内联功能组件如何通过“导航”道具反应导航5?

时间:2020-09-14 19:14:54

标签: react-native expo react-navigation

我使用tsx与expo进行本机登录,问题是我使用内联函数组件来调用父函数,以确定用户是否在线或离线,但问题是缺少内联组件导航道具的问题是,内联组件缺少导航道具¿我如何调养导航道具?

export default class App extends React.Component<MyProps, MyState>{
    constructor(props:any){
        super(props)
        this.state ={
            onsession : 2
        }
    }

    UNSAFE_componentWillMount(){
        this.definecontainer()
    }

    definecontainer = async()=>{
      this.setState({onsession:1})
    }

    tryes = ()=>{
        console.log('sssss')
    }

    render(){
        return(
            <Container>
                {this.containers(this.state.onsession)}
            </Container>
        )
    }

    containers(sessiontype:number){
        if(sessiontype == 1){
            return(
                <View
                style={{flex:1 ,justifyContent: 'center', alignItems: 'center'}}>
                    <Spinner
                    color="blue"
                    />
                </View>
            )
        } else if(sessiontype == 2){
            return(
                <NavigationContainer>
                    <Auth.Navigator headerMode='none'                
                    initialRouteName="Login">
                        <Auth.Screen name="Login" component={() => <Login navigation={this.props.navigation} onsession={this.onsession}/>}/>
                    </Auth.Navigator>
                </NavigationContainer>
            )
        } else if( sessiontype == 3){
            return(
                <NavigationContainer>
                    <Myapp.Navigator headerMode='none'
                    initialRouteName="Profile">
                        <Myapp.Screen name='Profile'                                    component={Profile}/>
                        <Myapp.Screen name='Deliverysumary'                             component={Deliverysumary}/>
                    </Myapp.Navigator>
                </NavigationContainer>
            )
        }
    }
}

0 个答案:

没有答案