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.

Shadow not working on Android

See original GitHub issue

Bug

Trying to follow guide on adding shadow to BottomSheetModal, only iOS seems to work. IMG_B258DB887710-1 Screen Shot 2021-11-06 at 14 49 42

Environment info

Library Version
@gorhom/bottom-sheet 4.1.3
react-native 0.65.1
react-native-reanimated 2.2.3
react-native-gesture-handler 1.10.3

Steps To Reproduce

  1. Just use the code in this link: https://gorhom.github.io/react-native-bottom-sheet/modal/usage
  2. Add the style to BottomSheetModal
            shadowColor: 'pink',
            shadowOffset: {
              width: 0,
              height: 12,
            },
            shadowOpacity: 0.58,
            shadowRadius: 16.0,

            elevation: 24,
  1. See the result

Describe what you expected to happen:

  1. Android should show the shadow correctly

Reproducible sample code

Snack link

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

7reactions
rmathias86commented, Jun 9, 2022

I solved the issue by adding a background colour

style={{
        backgroundColor: 'white',  // <==== HERE
        borderRadius: 24,
        shadowColor: '#000000',
        shadowOffset: {
          width: 0,
          height: 8,
        },
        shadowOpacity: 0.1,
        shadowRadius: 24,
        elevation: 10,
      }}
6reactions
fiznoolcommented, Nov 11, 2021

The elevation property on Android is very inflexible, and so I opted for a custom handle component with a shadow applied using react-native-shadow-2.

// SheetHandle.tsx

import React, { FC } from 'react';
import { StyleSheet, View } from 'react-native';
import { Shadow } from 'react-native-shadow-2';

const RADIUS = 24;

const SheetHandle: FC = () => {
  return (
    <Shadow
      sides={['top']}
      corners={['topLeft', 'topRight']}
      radius={RADIUS}
      viewStyle={styles.shadowContainer}>
      <View style={styles.handleContainer}>
        <View style={styles.handle} />
      </View>
    </Shadow>
  );
};

const styles = StyleSheet.create({
  shadowContainer: {
    width: '100%',
  },
  handleContainer: {
    alignItems: 'center',
    justifyContent: 'center',
    paddingVertical: 12,
    borderTopLeftRadius: RADIUS,
    borderTopRightRadius: RADIUS,
  },
  handle: {
    width: 30,
    height: 4,
    backgroundColor: 'gray',
    borderRadius: 4,
  },
});

export default SheetHandle;

The SheetHandle component is then applied to the BottomSheet via the handleComponent prop:

// App.tsx

import React, { useCallback, useMemo, useRef } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';

import SheetHandle from './SheetHandle';

const App = () => {
  return (
    <View style={styles.container}>
      <BottomSheet
        index={1}
        snapPoints={['25%', '50%']}
        handleComponent={SheetHandle}
      >
        <View style={styles.contentContainer}>
          <Text>Awesome 🎉</Text>
        </View>
      </BottomSheet>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
    backgroundColor: 'white',
  },
  contentContainer: {
    flex: 1,
    alignItems: 'center',
  },
});

export default App;

The results:

iOS Android
ios android
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android "elevation" not showing a shadow
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 >
shadow not working on my android tablet :( | Community
Hello I am trying to connect to Shadow from a cheap android tablet but it does not work. It says that streaming services...
Read more >
Shadow on Android TV not working : r/ShadowPC
My TV is connected over an GBit-Ethernet-Cable to my network and 4K Streaming works flawless. So it's not the connection speed.
Read more >
Create Shadows and Clip Views
Customize View Shadows and Outlines ... The bounds of a view's background drawable determine the default shape of its shadow. Outlines represent ...
Read more >
React Native Shadow is Missing on iOS but is Okay on Android
Turns out on iOS, the shadow is part of the UI component that you define it at, which results in removing the shadow,...
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