【问题标题】:Undefined '_this2.props.navigation.navigate'未定义的'_this2.props.navigation.navigate'
【发布时间】:2019-11-02 10:07:18
【问题描述】:

我有问题,我想从 Modal 登录导航到注册。这个问题是怎么解决的?

如何才能在模态中导航?

enter image description here

enter image description here

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>

【问题讨论】:

标签: react-native react-navigation


【解决方案1】:

使用withNavigation HOC 可以访问组件中的导航属性。

参考见this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 2019-09-22
    相关资源
    最近更新 更多