[英]React native, style not applied to component
I am using the platform api to apply a style for ios or android. However, no styles are appearing for containerAndroid
, or containerIos
, any ideas?我正在使用平台 api 为 ios 或 android 应用样式。但是,没有 styles 出现在containerAndroid
或containerIos
上,有什么想法吗?
import { View, Pressable, Platform } from 'react-native';
import getStyleObj from './styles';
const style = useMemo(() => getStyleObj({ backgroundColor, secondSnapshot }),
[backgroundColor, secondSnapshot]);
// apply style depending on platform
<Animated.View
style={[
style.container,
actionSheetStyle,
Platform.OS === 'android'
? style.containerAndroid
: style.containerIos,
]}
>
<Icon
name="minus"
size={50}
color={colors.GREYONE}
style={style.toggleIcon}
/>
{renderHeader}
style.js:样式.js:
const { StyleSheet } = require('react-native');
const getStyleObj = ({ backgroundColor, secondSnapshot }) => {
return StyleSheet.create({
container: {
position: 'absolute',
backgroundColor: backgroundColor || 'white',
width: '100%',
height: secondSnapshot,
bottom: 0,
},
containerIos: {
borderTopEndRadius: 15,
borderTopStartRadius: 15,
shadowColor: '#000',
shadowOffset: { width: 1, height: -6 },
shadowOpacity: 0.1,
shadowRadius: 2,
},
containerAndroid: {
borderTopColor: '#c4c4c4',
borderTopWidth: 0.3,
},
toggleIcon: {
alignSelf: 'center',
},
});
};
export default getStyleObj;
You can try the below things for your goal.您可以尝试以下方法来实现您的目标。
import { Platform, StyleSheet } from 'react-native';
<Animated.View
style={[
style.container,
actionSheetStyle,
style.platformContainer
]}
>
const styles = StyleSheet.create({
platformContainer: {
...Platform.select({
ios: {
borderTopEndRadius: 15,
borderTopStartRadius: 15,
shadowColor: '#000',
shadowOffset: { width: 1, height: -6 },
shadowOpacity: 0.1,
shadowRadius: 2,
},
android: {
borderTopColor: '#c4c4c4',
borderTopWidth: 0.3,
},
default: {
// other platforms, web for example
backgroundColor: 'blue'
}
})
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.