react-native - 灯箱不会触发动作
问题描述
目前使用 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>
解决方案
了解 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 - 转到家庭场景
推荐阅读
- powershell - 使用 PowerShell 对文件夹路径进行排序
- apache-nifi - Nifi Broken Pipe ExecuteStreamCommand
- php - Passing form data inside html table to controller in laravel
- angular - 在构建生产角度应用程序时,需要动态更改环境值(在构建之前它们是未知的)
- pandas - 无法将 Panda 系列转换为 DateTime
- unity3d - 事件触发器在从 google cardboard 转换为 oculus go/gear vr 的 vr 上不起作用
- entity-framework - 如何使用 Entity Framework LINQ to 使用包含和连接的自引用表检索数据?
- swift - Views not performing segue
- mockito - Mockito 是否支持在 then(Answer) 语句中抛出异常,然后是 thenReturn 语句?
- reactjs - 如何在反应原生中实现包含文本的水滴形状,如下图所示