作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下是我创建的 react native 模态,仍然找不到如何调暗背景并在弹出模态周围透明。我没有使用任何外部库,并试图在没有库的情况下找到解决方案。是否可以使用就这样吗?
render() {
let modal = this.state.modalType=='skill'? <SkillModal /> : <TrialModal />;
return (
<View style={styles.container}>
<Modal
animationType='slide'
onRequestClose={() => console.log('no warning')}
presentationStyle="FormSheet"
transparent
visible={this.state.showModal}
>
<View>
<View style={styles.modalView} >
<TouchableOpacity
onPress={this.closeModalFunc}
>
<Text style={styles.closeText}>X</Text>
</TouchableOpacity>
<View>
{modal}
</View>
</View>
</View>
</Modal>
</View>
);
}
import {StyleSheet} from 'react-native';
import colors from '../../../theme/colors';
import metrics from '../../../theme/metrics';
import {container} from '../../../theme/base';
const styles = StyleSheet.create({
container: {
backgroundColor: colors.background.gray,
},
modalView: {
backgroundColor: colors.background.white,
margin: 40,
},
closeText: {
backgroundColor: colors.background.purpleishBlue,
color: colors.background.white,
borderRadius: metrics.avatar.small,
width: 32,
padding: 6,
alignSelf: 'flex-end',
textAlign: 'center',
borderWidth: 1,
borderColor: colors.background.white,
},
});
export default styles;
最佳答案
我通过创建自己的组件 MyPopup 来解决这个问题,如下所示
class MyPopup extends React.PureComponent {
render() {
return (
<Modal
animationType="fade"
transparent={true}
visible={this.props.visible}
>
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'rgba(0,0,0,0.5)'}}>
{this.props.children}
</View>
</Modal>
)
}}
然后我就这样使用它
<MyPopup visible={this.state.modalVisible}>
<View style={{
width: '90%',
height: 50,
borderColor: '#ccc',
borderWidth: 1,
borderStyle: 'solid',
backgroundColor: 'white',
elevation: 20,
padding: 10,
borderRadius: 4,
}}>
<Text>Hello, This is my model with dim background color</Text>
</View>
关于reactjs - 如何在 react native 模式中调暗背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48058532/
我的代码遇到了很大的困难。我正在开发一个显示歌词和和弦的应用程序。我使用两个重叠的textview分隔了和弦和歌词。 我在这个项目中遇到的问题是音高改变功能。我尽我所能向我解释得更好: 和弦总数为12
我有一个游戏并使用 Tune 作为分析库。使用最新的 Unity (5.3.4f1) 并通过 Unity 获取 apk(无 eclipse/android studio)。 我的游戏在 Play 商店
我是一名优秀的程序员,十分优秀!