如何修复安卓版 React-Native 中提升的阴影问题



我试图在 react-native 中显示视图周围的阴影。

我试过这个

<View
      style={{
        flex: 0.3,
        margin: 4,
        ...Platform.select({
          ios: {
            shadowColor: '#000',
            shadowOffset: {width: 0, height: 4},
            shadowOpacity: 0.4,
          },
          android: {
            elevation: 2,
          },
        }),
      }}>

它在iOS上完美运行,但在Android上没有效果。有一个名为 react-native-shadow 的库,它在 iOS 和 Android 上都能完美运行,但如何在不使用任何第三方库的情况下修复 android 中的阴影问题。

现在我有这些属性,我已经为所需的动画提供了解决方法。 试试这个,lemme 在评论中知道,如果它对你的情况有帮助。 乐于帮忙。

   ...Platform.select({
            ios: {
                shadowColor: '#000',
                shadowOffset: { width: 0, height: 3 },
                shadowOpacity: 0.2,
            },
            android: {
                elevation: 0.4,
                // bottomElevation:4,
                borderBottomWidth: 0.2,
                borderTopWidth:0.2,
                borderColor:'#000'
            },
        }),

目前,我使用以下属性来处理IOS和Android平台上的阴影。

<View
  style={{
      height: 200,
      width: 350,
      borderRadius: 4,
      margin: 5,
      shadowColor: 'rgba(0,0,0,0.5)',
      shadowOffset: {width: 0, height: 5},
      shadowOpacity: 2,
      shadowRadius: 2,
      elevation: 4,
      backgroundColor: '#fff',
  }}>

最新更新