react-native - 未定义的'_this2.props.navigation.navigate'
问题描述
我有问题,我想从 Modal 中的登录导航到注册。这个问题是怎么解决的?
我如何才能在模态中导航?
import React, { Component } from 'react';
import { Alert, StyleSheet, Text, TouchableOpacity, View, Dimensions, TextInput } from 'react-native';
import Modal from 'react-native-modalbox';
import Lock from '../../../assets/icon/lock.svg';
import User from '../../../assets/icon/user.svg';
var screen = Dimensions.get('window');
class Login extends Component {
constructor(props) {
super(props);
}
showLogin = () => {
this.refs.myLogin.open();
}
closeLogin = () => {
this.refs.myLogin.close();
}
render() {
return (
<Modal
ref={"myLogin"}
style={{
borderRadius: 10,
width: screen.width - 80,
shadowRadius: 10,
height: 300,
}}
position='center'
backdrop={true}
/>
)
}
}
和这个按钮
<TouchableOpacity onPress={() => this.props.navigation.navigate('Register')}>
<Text style={{ color: '#024379', fontWeight: 'bold' }}>Daftar Disini</Text>
</TouchableOpacity>
解决方案
使用withNavigation
HOC 能够访问组件中的导航道具。
参考请看这个
推荐阅读
- go - 你能创建一个只包含实例接收到的属性的 Go 结构吗?
- javascript - Shirt.size 未按预期更新
- ruby-on-rails - ActiveStorage 和 s3 - 默认情况下将所有图像设置为公开
- qemu - 通过 libvirt 或 qmp 访问多个 Qemu-kvm 实例的 Guest
- ruby-on-rails - 如何根据 Ruby on Rails 迁移中另一行的选择值更改_column_default?
- flask - Flask SQLAlchemy query.all() 仅返回所有 id
- rust - 将默认参数传递给 cargo run
- dynamic - 通过添加具有“动态名称”的新字段来更新 Firestore 文档的语法 (React-Redux)
- javascript - 如何让机器人只响应句子中存在的一个“事件”,而不是两个
- reactjs - 反应原生导航 - 在添加/更新/删除项目时更新屏幕中的列表