以下是我创建的 react native Modal,但仍然找不到如何使背景变暗和在弹出模态周围透明。我没有使用任何外部库并试图找到没有库的解决方案。是否可以通过这种方式进行处理?
我的模态组件
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;