【问题标题】:Lightbox wont trigger actions灯箱不会触发动作
【发布时间】:2018-11-12 07:58:08
【问题描述】:

目前使用 rnrf 进行导航。灯箱上的按钮无法触发 onpress 动作以转到另一个场景。请帮帮我。这就是设置我的 rnrf 的方式

<Router>
<Lightbox key="lightbox">
    <Modal hideNavBar>
        <Scene drawer key='root' contentComponent={DrawerContent}>
            <Scene key='root'>
                <Scene hideNavBar key='Home' component={Screen.Home} />
                <Scene hideNavBar key='Details' component={Screen.Details} />
            </Scene>
        </Scene>
        <Scene hideNavBar key='Modals' component={Screen.Modals} />
    </Modal>
    <Scene key="LightBox" component={Component.LightBox} />
    <Scene key="MoreOptions" component={Component.MoreOptions} />
</Lightbox>    

这是灯箱上的按钮

<TouchableWithoutFeedback onPress={() => { Actions.Home(); }}>
            <View>
                <Text style={s.text}>Group</Text>
            </View>
 </TouchableWithoutFeedback>

请注意,如果这样设置,按钮可以工作,但无法通过 rnrf 传递道具

<Router>
<Lightbox key="lightbox">
    <Modal hideNavBar>
        <Scene drawer key='root' contentComponent={DrawerContent}>
                <Scene hideNavBar key='Home' component={Screen.Home} />
                <Scene hideNavBar key='Details' component={Screen.Details} />
        </Scene>
        <Scene hideNavBar key='Modals' component={Screen.Modals} />
    </Modal>
    <Scene key="LightBox" component={Component.LightBox} />
    <Scene key="MoreOptions" component={Component.MoreOptions} />
</Lightbox>    

【问题讨论】:

    标签: react-native react-native-router-flux


    【解决方案1】:

    了解 RNRF 遵循路由器树的层次结构对您很重要...

    在您的上下文中,您有:

    <Scene key="LightBox"...
    

    的子级并行
    <Modal...
    

    当您执行 Actions.Home() 时,这不会做任何事情,因为您不能并行“跳跃”。为了存档它,您需要执行类似...

    在调用LightBox的页面中:

     const callback = () =>{
        Actions.Home()
     }
     Actions.MyLightBox({callback})
    

    在您的灯箱中:

    <TouchableWithoutFeedback onPress={() => { 
         this.props.callback()
         Actions.pop() 
    }}>
            <View>
                <Text style={s.text}>Group</Text>
            </View>
    </TouchableWithoutFeedback>
    

    这将:

    1 - 关闭当前灯箱

    2 - 转到主场景

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多