【问题标题】:React Native shadow to the top to give "shelf" like effect将 Native 阴影反应到顶部以提供类似“架子”的效果
【发布时间】:2020-10-06 05:37:19
【问题描述】:

我正在尝试使用 react native shadow 重新创建下面的图像。 如您所见,有了阴影,图像对象似乎位于白色架子的顶部。

这是我的尝试。但我的努力不够短,因为顶部阴影更像是黑点,而不是像上面的渐变。有什么建议吗?谢谢!


const CollectionScreen = () => {
    return (
        <View>
            <View style={{ backgroundColor: 'black', width: 100, height: 100, position: 'absolute', top: 100, left: 100}}/>
            <View style = {styles.shelf}/>
        </View>
    );
}

const styles = StyleSheet.create({
    shelf: {
        width: 1242, 
        height: 25, 
        borderRadius: 5, 
        backgroundColor: 'white', 
        position: 'absolute', 
        top: 200,
        shadowColor: "#000",
        shadowOffset: {
            width: 3,
            height: -5,
        },
        shadowOpacity: 0.25,
        shadowRadius: 10,
        marginTop: 3 
    }
})

【问题讨论】:

    标签: ios react-native shadow


    【解决方案1】:

    这是我的尝试。我添加了一个浅灰色框来表示书架的顶部,并在底部的“书”下方添加了一条带阴影的线,以复制仅落在书架上的阴影。

    export default function App() {
      return (
        <View>
          <View style={styles.shelf} />
          <View style={styles.shelfTop} />
          <View
          style={{
              backgroundColor: 'black',
              width: 100,
              height: 5,
              position: 'absolute',
              top: 190,
              left: 100,
              shadowColor: '#000',
              shadowOffset: {
                width: 3,
                height: 5,
              },
              shadowOpacity: 0.50,
              shadowRadius: 5,
            }}
          />
          <View
            style={{
              backgroundColor: 'black',
              width: 100,
              height: 100,
              position: 'absolute',
              top: 95,
              left: 100,
            }}
          />
        </View>
      );
    }
    
    const styles = StyleSheet.create({
      shelfTop: {
        width: 1242,
        height: 25,
        position: 'absolute',
        top: 180,
        backgroundColor: '#F5F5F5',
      },
      shelf: {
        width: 1242,
        height: 25,
        borderRadius: 5,
        backgroundColor: 'white',
        position: 'absolute',
        top: 200,
        shadowColor: '#000',
        shadowOffset: {
          width: 3,
          height: 5,
        },
        shadowOpacity: 0.25,
        shadowRadius: 20,
        marginTop: 3,
      },
    });
    

    【讨论】:

    • 除了shelfTop中的错字“位置”之外,它就像一个魅力。公认。谢谢。
    猜你喜欢
    • 2011-07-19
    • 2021-10-30
    • 2015-02-28
    • 1970-01-01
    • 2021-09-27
    • 2022-01-15
    • 2022-07-06
    • 1970-01-01
    • 2018-12-27
    相关资源
    最近更新 更多