Để trả lời câu hỏi của bạn về phương thức minh bạch, bạn có thể sử dụng màu nền rgba, ví dụ: rgba (0, 0, 0, 0.5) và chuyển alpha đến đối số cuối cùng của màu: rgba (r , g, b, alpha).
Theo như điều hướng có liên quan, bạn có thể sử dụng đối số Navigator.SceneConfigs.FloatFromBottom cho trình điều hướng để tạo phương thức, đặt Bộ điều hướng phương thức trong cảnh của một Điều hướng khác. Có một chuỗi tốt với các ví dụ cho rằng here. Một cái gì đó như:
this.props.navigator.push({
title: 'title',
sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
component: component,
navigationBar: <NavigationBar
title="Initial View"/>,
passProps: {}
})
Tôi đã tạo một dự án mẫu có nền trong suốt here và đặt mã bên dưới. Tôi hi vọng cái này giúp được!
https://rnplay.org/apps/pHqjhQ
'use strict';
var React = require('react-native');
var {
Modal,
StyleSheet,
SwitchIOS,
Text,
TouchableHighlight,
View,
AppRegistry,
} = React;
exports.displayName = (undefined: ?string);
exports.framework = 'React';
exports.title = '<Modal>';
exports.description = 'Component for presenting modal views.';
var Button = React.createClass({
getInitialState() {
return {
active: false,
};
},
_onHighlight() {
this.setState({active: true});
},
_onUnhighlight() {
this.setState({active: false});
},
render() {
var colorStyle = {
color: this.state.active ? '#fff' : '#000',
};
return (
<TouchableHighlight
onHideUnderlay={this._onUnhighlight}
onPress={this.props.onPress}
onShowUnderlay={this._onHighlight}
style={[styles.button, this.props.style]}
underlayColor="#a9d9d4">
<Text style={[styles.buttonText, colorStyle]}>{this.props.children}</Text>
</TouchableHighlight>
);
}
});
var ModalExample = React.createClass({
getInitialState() {
return {
animated: true,
modalVisible: false,
transparent: true,
};
},
_setModalVisible(visible) {
this.setState({modalVisible: visible});
},
render() {
var modalBackgroundStyle = {
backgroundColor: this.state.transparent ? 'rgba(0, 0, 0, 0.5)' : '#f5fcff',
};
return (
<View>
<Modal
animated={this.state.animated}
transparent={this.state.transparent}
visible={this.state.modalVisible}>
<View style={[styles.container, modalBackgroundStyle]}>
<View style={[styles.innerContainer]}>
<Button
onPress={this._setModalVisible.bind(this, false)}
style={styles.modalButton}>
Close
</Button>
</View>
</View>
</Modal>
<View style={{ marginTop:60 }}>
<Button onPress={this._setModalVisible.bind(this, true)}>
SHOW MODAL
</Button>
</View>
</View>
);
},
});
AppRegistry.registerComponent('ModalExample',() => ModalExample);
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 20,
},
innerContainer: {
borderRadius: 10,
alignItems: 'center',
},
button: {
borderRadius: 5,
flex: 1,
height: 44,
alignSelf: 'stretch',
justifyContent: 'center',
overflow: 'hidden',
},
buttonText: {
fontSize: 18,
margin: 5,
textAlign: 'center',
},
modalButton: {
marginTop: 10,
},
});
Tôi có cùng vấn đề. Cách được khuyến nghị không thực sự có thể cho nhiều trường hợp sử dụng. – Udi