Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent backgrounds #16

Open
terrysahaidak opened this issue Jul 18, 2023 · 3 comments
Open

Transparent backgrounds #16

terrysahaidak opened this issue Jul 18, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@terrysahaidak
Copy link

Is your feature request related to a problem? Please describe.

In react native on Android when you use elevation and want to have a transparent-ish view, you will have visible shadow background:

https://snack.expo.dev/@terrysahaidak/humiliated-strawberries
image

This library implements really cool shadows but also suffers from this same problem - the shadow is visible underneath.

This is a known problem of React Native, though:
facebook/react-native#25093

Describe the solution you'd like

At this point, I don't know if this is actually possible.
According to the issue, it wasn't a problem until Android 9.

P.S.
Thanks for this awesome library, it's a gem!

@terrysahaidak terrysahaidak added the enhancement New feature or request label Jul 18, 2023
@WadhahEssam
Copy link

if this is solved, it would be probably the #1 library to go for shadows. will try to solve it

@simontreny
Copy link
Collaborator

simontreny commented Aug 17, 2023

Hi @terrysahaidak,

I think you can achieve what you want with renderToHardwareTextureAndroid. Unfortunately, it clips the view to its exact bounds, so the shadow won't render properly if applied directly on ShadowedView. You can fix that by adding some padding around the shadowed view by doing something like this:

<View style={{ opacity: 0.5, padding: 20, margin: -20 }} renderToHardwareTextureAndroid>
  <ShadowedView
    style={{
      width: 150,
      height: 200,
      borderRadius: 20,
      backgroundColor: '#dbfff2',
      ...shadowStyle({
        opacity: 0.4,
        radius: 12,
        offset: [5, 3],
      }),
    }}
  />
</View>

The 20px padding needs to be adjusted based on the radius/offset of the shadow. Let me know if it doesn't work as you would expect.

@Dav2015
Copy link

Dav2015 commented Jan 28, 2024

Hi @terrysahaidak,

I think you can achieve what you want with renderToHardwareTextureAndroid. Unfortunately, it clips the view to its exact bounds, so the shadow won't render properly if applied directly on ShadowedView. You can fix that by adding some padding around the shadowed view by doing something like this:

<View style={{ opacity: 0.5, padding: 20, margin: -20 }} renderToHardwareTextureAndroid>
  <ShadowedView
    style={{
      width: 150,
      height: 200,
      borderRadius: 20,
      backgroundColor: '#dbfff2',
      ...shadowStyle({
        opacity: 0.4,
        radius: 12,
        offset: [5, 3],
      }),
    }}
  />
</View>

The 20px padding needs to be adjusted based on the radius/offset of the shadow. Let me know if it doesn't work as you would expect.

Solved my issue with renderToHardwareTextureAndroid. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants