2017-08-05 3 views
1

Ich bin neu in React Native und ich suchte auf Google, aber ich konnte nur alte Version von React Native finden.reagieren native passing Wert

Eigentlich bin ich nicht sicher, wie Zustandswert auf andere js Dateien passieren Ich Authpage machen, die tappage.js umleiten, wenn der Zustandswert ‚isValid‘ wird ‚true‘

Ich bin Planung zu Ändern Sie die Seite so auf App.js, wenn es andere bessere Möglichkeiten gibt, lassen Sie es mich wissen.

Vielen Dank das ist mein Code. AuthManager.js

export default class AuthPage extends Component { 
    constructor(props) { 
    super(props); 
    this.state = { 
     user     : null, 
     firebaseUser   : null, 
     fcmToken    : null, 
     accessToken    : null, 
     authType    : null, 
     hasInitialNotification : null, 
     isValid     : false 
    }; 
    this.unsubscribe = null; 

    } 

...some codes.. 


render() { 
    // if (!this.state.firebaseUser) { 
     return (
     <Provider store={store}> 
     <View style = {styles.main}> 


     <View style ={styles.logotemp}> 
     <Image style ={styles.logo} 
     source={require('../../resources/logo/logo.png')} 
     /> 

     </View> 

     <View style = {styles.inputid}> 


     <FormInput 
     ref={(el)=> {this.email = el;}} 
     textInputRef='email' 
     placeholder = "Email" 
     onChangeText={(email) => this.setState({email})} 
     value = {this.state.email} 
     /> 

     <FormInput 
     ref={(el)=> {this.password = el;}} 
     textInputRef='password' 
     onChangeText={(password) => this.setState({password})} 
     value = {this.state.password} 
     placeholder = "Password" 
     secureTextEntry = {true} 
     /> 
     <TouchableOpacity onPress={this._emailSignIn.bind(this)}> 
     <Image 
     style = {styles.loginbut} 
     source={require('../../resources/socialicon/signin.png')} 
     /> 
     </TouchableOpacity> 

     </View> 

     <View style = {styles.socialicons}> 
     <TouchableOpacity onPress={this._facebookSignIn.bind(this)} > 
     <Image 
     style={styles.fbicons} 
     source={require('../../resources/socialicon/facebook.png')} 
     /> 
     </TouchableOpacity> 
     <Image 
     style={styles.divider} 
     source = {require('../../resources/socialicon/divider.png')} 
     /> 

     <TouchableOpacity onPress={this._googleSignIn.bind(this)} > 
     <Image 
     style={styles.ggicons} 
     source={require('../../resources/socialicon/google.png')} 
     /> 
     </TouchableOpacity> 

     </View>  
     </View> 

     </Provider> 
    ); 
    // } 

    if (this.state.firebaseUser) { 
     return(
     <Provider store = {store}> 
     {store.isValid = this.state.isValid} 
     </Provider> 
    ); 
    } 
    } 

export default class MainPage extends Component { 
    constructor(props) { 
    super(props); 
    } 

    componentDidMount() { 

    } 



    render() { 
    alert(store.isValid); 
    if(!this.props.isValid){ 
     return(<View style={{flex:1}}> 

     <AuthPage></AuthPage> 

     </View> 


    ); 
    } 

    if(isValid){ 
    return(
     <View style={{flex:1}}> 

     <TabPage></TabPage> 

     </View> 
    ); 
    } 




    } 
} 

danke !!

Antwort

1

Das Idiom in React ist, dass nur das aktuelle Element seinen Zustand kennen kann. Ich würde empfehlen, Redux für die globale Datenübertragung zwischen Komponenten zu verwenden, oder, wenn Sie keine Daten synchronisiert benötigen, können Sie AsyncStorage verwenden.