【发布时间】:2021-11-22 00:45:02
【问题描述】:
我是 react native 的新手,如何在 react native 中动态更改 Zindex?或者如何使用其他动态方式隐藏/显示?
import { styles } from './App_styles';
export default function App() {
return (
<View style={styles.body}>
<Pressable onPress={()=>{styles.popup.zIndex=0}}>
<View style={styles.popup}>
</View>
</Pressable>
<View style={styles.main_content}>
</View>
</View>
);
}
App_styles:
export const styles = StyleSheet.create({
body:{
backgroundColor: 'gray',
height:'100%',
},
popup: {
position:'absolute',
backgroundColor: 'rgba(0,0,0, 0.5)',
height:'100%',
width:'100%',
zIndex:1,
alignSelf:'center',
marginTop:'30%',
},
main_content:{
backgroundColor: 'red',
width:'100%',
height:'100%'
},
});
我不确定如何使用 js 在 react native 中动态更改属性
【问题讨论】:
-
请先学习基础知识; React 和 React Native 是一样的:reactjs.org/docs/state-and-lifecycle.html
-
这能回答你的问题吗? Can I make dynamic styles in React Native?