React Native:将参数传递给Drawer.Navigator

问题描述 投票:1回答:1

我能够传递道具,但是由于道具是只读的,如何在App.js和DrawerContent.js之间传递其他参数?请参见下面的代码段

使用“ @ react-navigation / drawer”:“ ^ 5.4.0”,

App.js:

 const Drawer = createDrawerNavigator();

 const DrawerRender = () => {
    return (
      <NavigationContainer>
        <Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
          <Drawer.Screen name="Feed" component={Feed} />
        </Drawer.Navigator>
      </NavigationContainer>
    );
  }

  export default class App extends React.Component {

       constructor(props) {
          super(props);
          this.state = { 
              fonts_loaded: false,
              isLoggedin: false,
              userData: null,
              isImageLoading: false
          }
       }

     ...

     render() {
        if(this.state.fonts_loaded){
            if(this.state.isLoggedin && this.state.userData !== null){
                return (
                    <DrawerRender />
                );
            }
            return (
                <View style={styles.container}>
                    ...
                </View>
            );
        }
        return (<View></View>)
    }
}

DrawerContent.js:

export function DrawerContent(props) {

    return(
        <View style={{flex:1}}>
            <DrawerContentScrollView {...props}>
                <View style={styles.drawerContent}>
                    <View style={styles.userInfoSection}>
                        <View style={{flexDirection:'row',marginTop: 15}}>
                            <Avatar.Image 
                                source={{
                                    uri: <GET_URI_FROM_App.js>
                                }}
                                size={50}
                            />
                            <View style={{marginLeft:15, flexDirection:'column'}}>
                                <Title style={styles.title}><GET_USERNAME_FROM_App.js></Title>
    ...

如何将用户名和uri从App.js传递给DrawerContent.js?在上述代码段中被视为GET_URI_FROM_App.jsGET_USERNAME_FROM_App.js]

我能够传递道具,但是由于道具是只读的,如何在App.js和DrawerContent.js之间传递其他参数?请使用“ @ react-navigation / drawer”查看下面的代码片段:“ ^ 5.4.0”,...

react-native react-native-android react-navigation react-native-ios
1个回答
1
投票

您可以使用此:

© www.soinside.com 2019 - 2024. All rights reserved.