Chr*_* H. 7 react-native react-navigation react-native-modal
我有一个带有底部标签导航的应用程序(以防它很重要),有时用户可以打开一个模式(react-native-modal)。模态中有按钮,我想在模态内实现导航,以便当用户按下其中一个按钮时,它们会被导航到模态内的另一个屏幕(并且可以向后导航)。任何帮助表示赞赏,提前致谢!我想要的例子:
小智 1
我有一个这样的问题。但我没有用路线做到这一点,因为我在路线中,我想在屏幕内打开另一个组件。所以我使用纯组件来做到这一点。我做了一个控制可见性变量,当用户单击按钮时显示另一个“屏幕”,并在用户关闭它时隐藏。
这是一个例子:
//Parent component
class Parent extends Component {
state = {
viewClhild: false
}
goToChild = (task) => {
this.setState({viewChild: true})
}
onShowClhildChange(viewChild) {
this.setState({ viewChild });
}
render() {
<View>
{
this.state.viewChild
? <ChildScreen onShowClhildChange={this.onShowClhildChange.bind(this)} />
: <Text>Show Parent</Text>
}
<Button
onPress={() => {this.goToChild()}}
>
<Text style={button.text}>Entrar</Text>
</Button>
</View>
}
}
//Child Component
class ChildScreen extends Component {
isChildVisible = (isVisible) => {
this.setState({ viewChild: isVisible })
if (this.props.onShowClhildChange) {
this.props.onShowClhildChange(isVisible);
}
}
constructor (props) {
super(props);
this.state = {
viewChild: this.props.viewChild
}
}
render() {
return (
<View>
<Button
onPress={() => this.isChildVisible(false)}
>
<Text>CLOSE CHILD SCREEN</Text>
</Button>
</View>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它可以帮助你!
| 归档时间: |
|
| 查看次数: |
4656 次 |
| 最近记录: |