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

<MotiPressable> box shadow not working on Android #149

Closed
agrawal-rohit opened this issue Jan 9, 2022 · 7 comments · Fixed by #152
Closed

<MotiPressable> box shadow not working on Android #149

agrawal-rohit opened this issue Jan 9, 2022 · 7 comments · Fixed by #152

Comments

@agrawal-rohit
Copy link
Contributor

Issue

Shadows do not appear when using the <MotiPressable /> component on Android (iOS works fine). However, when I use the original Pressable component from react-native, shows work fine.

Configuration

  • Expo: 44.0.4
  • Moti: 0.17.1

Screenshots

MotiPressable

IOS

Android

React Native Pressable

IOS

Android

Code

<MotiPressable
  style={{
    padding: 20,
    overflow: "visible",
    backgroundColor: "white",
    shadowColor: "#1A2138",
    shadowOffset: {
      width: 0,
      height: 28,
    },
    shadowOpacity: 0.16,
    shadowRadius: 28,
    elevation: 28,
  }}
>
  <Text>Hello</Text>
</MotiPressable>
@nandorojo
Copy link
Owner

try containerStyle?

@agrawal-rohit
Copy link
Contributor Author

Tried using containerStyle, didn't work.

<MotiPressable
  containerStyle={{
    backgroundColor: "white",
    shadowColor: "#1A2138",
    shadowOffset: {
      width: 0,
      height: 28,
    },
    shadowOpacity: 0.16,
    shadowRadius: 28,
    elevation: 28,
    padding: 20,
  }}
>
  <Text>Hello</Text>
</MotiPressable>

@nandorojo
Copy link
Owner

is it a reanimated issue? did you wrap your app in the root gesture handler view?

@agrawal-rohit
Copy link
Contributor Author

agrawal-rohit commented Jan 9, 2022

Not sure about it being a reanimated issue, though I'm wrapping all the contents in App using the root gesture handler view like this:

<GestureHandlerRootView style={{ flex: 1 }}>
    {/*  Rest of the components */}
</GestureHandlerRootView>

@nandorojo
Copy link
Owner

not sure, maybe try wrapping moti pressable with a normal view and put the shadow there. or make sure it works on an Animated.View too

@agrawal-rohit
Copy link
Contributor Author

Here's what I've tried till now:

1. Shadow on <View /> (Working)

<View
  style={{
    backgroundColor: "white",
    shadowColor: "#1A2138",
    shadowOffset: {
      width: 0,
      height: 28,
    },
    shadowOpacity: 0.16,
    shadowRadius: 28,
    elevation: 28,
  }}
>
  <MotiPressable
    containerStyle={{
      backgroundColor: "white",
      padding: 20,
    }}
  >
    <Text>Hello</Text>
  </MotiPressable>
</View>

2. Shadow on <Animated.View /> (Working)

<Animated.View
  style={{
    backgroundColor: "white",
    shadowColor: "#1A2138",
    shadowOffset: {
      width: 0,
      height: 28,
    },
    shadowOpacity: 0.16,
    shadowRadius: 28,
    elevation: 28,
  }}
>
  <MotiPressable
    containerStyle={{
      backgroundColor: "white",
      padding: 20,
    }}
  >
    <Text>Hello</Text>
  </MotiPressable>
</Animated.View>

3. Shadow on <MotiView /> (Working)

<MotiView
  style={{
    backgroundColor: "white",
    shadowColor: "#1A2138",
    shadowOffset: {
      width: 0,
      height: 28,
    },
    shadowOpacity: 0.16,
    shadowRadius: 28,
    elevation: 28,
  }}
>
  <MotiPressable
    containerStyle={{
      backgroundColor: "white",
      padding: 20,
    }}
  >
    <Text>Hello</Text>
  </MotiPressable>
</MotiView>

@agrawal-rohit
Copy link
Contributor Author

agrawal-rohit commented Jan 10, 2022

I think I've got a fix for this, it seems to be happening because of the use of containerStyle on the AnimatedTouchable in the <MotiPressable /> component

Updated Code

const AnimatedTouchable = Animated.createAnimatedComponent(
  TouchableWithoutFeedback
);

const App = () => {
  return (
   <GestureHandlerRootView style={{ flex: 1 }}>
        <AnimatedTouchable
          style={{
            padding: 20,
            overflow: "visible",
            backgroundColor: "white",
            shadowColor: "#1A2138",
            shadowOffset: {
              width: 0,
              height: 28,
            },
            shadowOpacity: 0.16,
            shadowRadius: 28,
            elevation: 28,
          }}
        >
          <MotiView>
            <Text>Hello</Text>
          </MotiView>
        </AnimatedTouchable>
   </GestureHandlerRootView>
  );
};

Output

IOS

Android

Further Comments

I'm skeptical about having the current implementation ofMotiPressable from a styling perspective. Wouldn't it be easier if we wrote it as:

const MotiTouchable = motify(TouchableWithoutFeedback)();

const MotiPressable = (props) => {
   // ... methods and state management

  return (
      <MotiTouchable {...props}>
          {props.children}
     </MotiTouchable>
  )
}

Opened a PR for the same :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants