0
我想在場景之間切換,並測試<{Some imported Scene} />
完美的作品,但下面的代碼沒有。 我非常新的反應本地的,我得到的錯誤是在線路30 index.android.js
意外的標記,它是甾體抗炎藥this.(scene[route.name] || scene['LoginView']);
反應本機導航器意外令牌
index.android.js
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
Navigator,
TouchableHighlight
} from 'react-native';
import LoginView from './Scence-Android/LoginView';
import SettingView from './Scence-Android/SettingView';
class TrackrModule extends Component {
render() {
return (
<View>
<Navigator
initialRoute={{ name: 'LoginView' }}
renderScene={ (route, navigator) => {
var scene = {
"LoginView":() => {
return (<LoginView navigator={navigator} title="Login" />)
},
"SettingView":() => {
return (<SettingView navigator={navigator} title="Setting" />)
}
}
this.(scene[route.name] || scene['LoginView']);
}}
/>
</View>
);
}
}
行
LoginView
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
Navigator,
TouchableHighlight
} from 'react-native';
export default class LoginView extends Component {
constructor(props){
super(props);
this.state = {
username: "",
password: ""
};
}
btnLogin_pressed(){
this.props.navigator.push({
name:"SettingView"
});
}
render(){
return (
<View style={styles.container}>
<View style={styles.loginContainer}>
<TextInput>
placeholder="Username"
style={styles.textInput}
onChange={(event) => this.setState({username: event.nativeEvent.text})}
value={this.state.username}
</TextInput>
<TextInput>
placeholder="Password"
secureTextEntry = { true }
style={styles.textInput}
onChange={(event) => this.setState({password: event.nativeEvent.text})}
value={this.state.password}/>
</TextInput>
<TouchableHighlight onPress={this.btnLogin_pressed.bind(this)}>
<Text>Login</Text>
</TouchableHighlight>
</View>
</View>
)
}
}
也許'回報(場景[route.name || 'LoginView'])'? – stereodenis
我認爲場景是一個以路線名稱作爲關鍵字和組件作爲值的對象。所以'return(scene [route.name] || scene ['LoginView']);'應該是正確的。 @stereodenis –
謝謝@AakashSigdel和stereodenis,那是一個醉酒的編碼:) – XPLOT1ON