question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v4] Android shadows are barely noticeable

See original GitHub issue

Bug

On Android, shadows applied to the BottomSheetModal are virtually invisible, even with a very high value of elevation.

To make sure no other library or config was interfering, I started a fresh project under React Native 0.68 with only the minimal libraries and files. I then copy-pasted the usage example provided in your documentation, and applied some shadow styles to the modal component. I made sure they were visible by putting high opacity and elevation values, as well as a low radius. I tried with and without shadowColor, as well as with and without backgroundColor. The used code can be found at the end of this report.

As you can see on this screenshot, the iOS shadow is correctly visible, but the Android one is not. If I use an even lower elevation value, the shadow will completely disappear and the modal will blend into the app background.

Capture d’écran 2022-07-11 à 16 47 09

I also made sure this wasn’t an Android or React Native bug by applying shadows to other objects (like buttons and views), which worked fine.

I found the ticket #734, and especially this comment pretending to solve the issue, but as you can see in my MCVE it didn’t work for me.

Environment info

Library Version
@gorhom/bottom-sheet 4.4.2
react-native 0.68.2
react-native-reanimated 2.9.1
react-native-gesture-handler 2.5.0

Steps To Reproduce

  1. Fetch the usage example from the doc
  2. Apply shadows styling to the BottomSheetModal style prop.
  3. Run on Android and observe the (lack of) result

Describe what you expected to happen:

  1. I was expecting the shadow to be more visible on Android

Reproducible sample code

Minimal sample code

import React, {useCallback, useMemo, useRef} from 'react';
import {View, Text, StyleSheet, Button} from 'react-native';
import {BottomSheetModal, BottomSheetModalProvider} from '@gorhom/bottom-sheet';
import {GestureHandlerRootView} from 'react-native-gesture-handler';

const App = () => {
  // ref
  const bottomSheetModalRef = useRef<BottomSheetModal>(null);

  // variables
  const snapPoints = useMemo(() => ['25%', '50%'], []);

  // callbacks
  const handlePresentModalPress = useCallback(() => {
    bottomSheetModalRef.current?.present();
  }, [bottomSheetModalRef]);

  // renders
  return (
    <GestureHandlerRootView style={{flex: 1}}>
      <BottomSheetModalProvider>
        <View style={styles.container}>
          <Button onPress={handlePresentModalPress} title="Present Modal" />
          <BottomSheetModal
            ref={bottomSheetModalRef}
            index={1}
            style={styles.sheet}
            snapPoints={snapPoints}>
            <View style={styles.contentContainer}>
              <Text>Awesome 🎉</Text>
            </View>
          </BottomSheetModal>
        </View>
      </BottomSheetModalProvider>
    </GestureHandlerRootView>
  );
};

const styles = StyleSheet.create({
  sheet: {
    backgroundColor: 'white',
    borderRadius: 15,
    shadowOpacity: 0.37,
    shadowRadius: 5,
    shadowColor: 'blue',
    elevation: 5,
  },
  container: {
    flex: 1,
    padding: 24,
    justifyContent: 'center',
    backgroundColor: 'white',
  },
  contentContainer: {
    flex: 1,
    alignItems: 'center',
  },
});

export default App;

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:8
  • Comments:14

github_iconTop GitHub Comments

1reaction
afizboltzcommented, Jul 22, 2022

maybe you can add borderWidth: 0 in style. mine showing the shadow for android emulator

BottomSheetShadow

Screenshot 2022-07-22 at 4 53 00 PM
0reactions
gabriel-morescocommented, Nov 24, 2022

some workaround?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android "elevation" not showing a shadow - Stack Overflow
I've been playing around with shadows on Lollipop for a bit and this is what I've found: It appears that a parent ViewGroup...
Read more >
Shadows in Android : r/androiddev - Reddit
Documentation is pretty bad, on Stackoverflow there are Codesnippets how to make it work but many of them involve hacks.
Read more >
Shadows - Robolectric
Shadows are ideal for testing interaction with the Android framework as the framework doesn't support dependency injection and makes liberal use of static...
Read more >
Elevation & shadows - Material Design
Crisp shadows indicate the floating action button and the blue sheet are separate elements. However, their shadows are so similar that they imply...
Read more >
The Eminence in Shadow RPG - Apps on Google Play
Experience The Eminence in Shadow's epic story modes! Continue the story with new chapters, beat exciting new challenges and get the latest ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found