加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 使用Navigator透明地反映Native Modal,而不使用

发布时间:2020-12-15 05:07:49 所属栏目:百科 来源:网络整理
导读:React Native文档说RN应该使用Navigator创建Modals( https://facebook.github.io/react-native/docs/modal.html#content). 如何在不使用Modal的情况下使用Navigator创建透明模式?我希望用户在后台查看当前页面.谢谢. 要回答关于透明模态的问题,可以使用rgba
React Native文档说RN应该使用Navigator创建Modals( https://facebook.github.io/react-native/docs/modal.html#content).

如何在不使用Modal的情况下使用Navigator创建透明模式?我希望用户在后台查看当前页面.谢谢.

要回答关于透明模态的问题,可以使用rgba背景颜色,例如rgba(0,0.5),并将alpha传递给颜色的最后一个参数:rgba(r,g,b),α).

就导航器而言,您可以使用导航器的Navigator.SceneConfigs.FloatFromBottom参数创建模态,将模态导航器放在另一个导航器的场景中.有一个很好的线程与here的例子.像:

this.props.navigator.push({
    title: 'title',sceneConfig: Navigator.SceneConfigs.FloatFromBottom,component: component,navigationBar: <NavigationBar
        title="Initial View"/>,passProps: {}
})

我创建了一个透明背景here的示例项目,并将代码放在下面.我希望这有帮助!

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.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',overflow: 'hidden',buttonText: {
    fontSize: 18,margin: 5,textAlign: 'center',modalButton: {
    marginTop: 10,});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读