gpt4 book ai didi

ios - 找不到变量 : navigate - ReactNative navigation

转载 作者:可可西里 更新时间:2023-11-01 04:49:55 24 4
gpt4 key购买 nike

这几天我一直在努力解决这个问题。我想插入导航堆栈并导航到另一个 View 。我在这里提到了这份官方文件。 https://reactnavigation.org .但我没有成功。请任何人告诉我我哪里做错了。

即使这个标题也没有出现。

static navigationOptions = {
title: 'Welcome',
};

这是我的 Login.js 代码。

import React, { Component } from 'react';

import { Text, View, StyleSheet, TextInput, TouchableOpacity, KeyboardAvoidingView, Image} from 'react-native';

import { StackNavigator } from 'react-navigation';

import {CirclesLoader, PulseLoader, TextLoader, DotsLoader, LinesLoader} from 'react-native-indicator';

var Spinner = require('react-native-spinkit');

import OrderList from './OrderList';

export default class Login extends Component {
constructor(props){
super(props);
this.state = {
username: '',
password: '',
showLoader: false,
autoCorrect: false,
}

this._login = this._login.bind(this);
}

/** Login Web Service **/
_login(){
this.setState({showLoader: true})
const { username, password, showLoader } = this.state;
console.log(username);
let formdata = new FormData();
formdata.append("username", username)
formdata.append("password", password)
formdata.append("device_type", 'I')
fetch('http://www.URL.com.au/ws/login', {method: 'POST', body:formdata, headers: {'Accept':'application/json', 'Content-Type':'application/json',}})
.then(function(response) {
if(response.status == 200) return response.json();
else throw new Error('Something went wrong on api server!');

this.setState({showLoader: false})
}.bind(this))
.then(function(response) {
console.log(response);

/** NAVIGATE TO ANOTHER VIEW - but getting cant find variable : navigate **/

navigate('Home');
this.setState({showLoader: false})
}.bind(this))
.catch(function(error) {
console.error(error);

this.setState({showLoader: false})
}.bind(this));
}

/** Even setting up navigation titile doesnt showup **/
static navigationOptions = {
title: 'Welcome',
};


render() {
return (
<KeyboardAvoidingView behavior="padding" style={styles.container}>
<View style={styles.spinnerContainer}>
{this.state.showLoader && <LinesLoader />}
{/*<TextLoader text="Please wait" />*/}
</View>
<View style={styles.formContainer}>
<TextInput style={styles.input} placeholder="Username" keyboardType="email-address" autoCapitalize="none" autoCorrect={this.state.autoCorrect} returnKeyType="next"
onSubmitEditing={() => this.passwordInput.focus()}
onChangeText={(username) => this.setState({username})}/>

<TextInput style={styles.input} placeholder="Password" secureTextEntry returnKeyType="go"
ref={(input) => this.passwordInput = input}
onChangeText={(password) => this.setState({password})}/>

<TouchableOpacity style={styles.buttonContainer} onPress={this._login}>
<Text style={styles.buttonText}>LOGIN</Text>
</TouchableOpacity>

</View>

);
}
}


const ReactNativeDemo = StackNavigator({
Login: {screen: Login},
Home: {screen: OrderList}
});

最佳答案

在与其他响应式代码进行了大量研究和测试后,它才奏效。

以下代码需要在 index.ios.js 文件上贴标。不在 Login.js 文件中。(我用作根文件的文件)

const ReactNativeDemo = StackNavigator({
Login: {screen: Login},
Home: {screen: OrderList}
});

同时导入文件路径和导航

import Login from './src/components/main/Login';
import OrderList from './src/components/main/OrderList';
import { StackNavigator } from 'react-navigation';

关于ios - 找不到变量 : navigate - ReactNative navigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43361828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com