简体   繁体   English

如何在反应原生 Expo 中仅在底部视图上添加阴影

[英]How to add shadow only on the bottom View in react native Expo

I need to add a shadow only on the bottom of a component for and android device (expo reac native)我只需要在 android 设备的组件底部添加阴影(expo reac native)

I get it always on the 4 sides.我总是在 4 个方面得到它。

list: {
        display: "flex",
        position: "relative",
        borderRadius: 5,
        margin: 10,

        backgroundColor: "#fff",
        shadowColor: "#000",
        shadowOffset: {
            width: 0,
            height: 2,
        },
        shadowOpacity: 0.25,
        shadowRadius: 3.84,

        elevation: 3,
    },

I am trying something like this in my styles but only seems to work: elevation and shadowColor, the rest of the shadow styles do not seem to do anything in my android emulator (maybe in ios it does) I am trying something like this in my styles but only seems to work: elevation and shadowColor, the rest of the shadow styles do not seem to do anything in my android emulator (maybe in ios it does)

you are correct, for android the only property available is elevation rest all properties are ios only.你是对的,对于 android,唯一可用的属性是elevation rest,所有属性都是 ios。 you can check here RN- shadow- props你可以在这里查看RN-shadow-props

For ios it will be very easy to add shadow at bottom by just passing对于 ios,只需通过即可在底部添加阴影非常容易

shadowOffset:{
height:-20 // whatever you wanna have
}

But for android, you need to have external packages for it to work like rn-shadow-2但是对于 android,您需要有外部封装才能使其像rn-shadow-2一样工作

Hope it helps.希望能帮助到你。 feel free for doubts随时怀疑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM