Невозможно отобразить заголовок и кнопку гамбургера в панели навигации в React Native - PullRequest
0 голосов
/ 11 мая 2019

Невозможно отобразить заголовок и кнопку гамбургера в ящике навигации в React Native.

Проблемы

  • Заголовок не отображается для элементов ящика
  • Значок гамбургера не отображается с действием

Screenshot of app

Реализация настроенного ящика с использованием реагировать на навигацию и использование экспо

Навигация происходит с одного экрана на другой, но заголовок не отображается для параметров, которые есть на экране ящика (DrawerScreen.js)

Исходный кодСсылка

App.js

import AppContainer from "./src/routes";

export default class App extends React.Component {
  render() {
    return (
      <ThemeProvider theme={theme}>
        <View style={{ flex: 1, backgroundColor: ColorConfig.COLOR_WHITE }}>
          <AppContainer />
        </View>
      </ThemeProvider>
    );
  }
}

DrawerScreen.js

class DrawerScreen extends Component {
   navigateToScreen = (route) => () => {
      const navigateAction = NavigationActions.navigate({
        routeName: route
      });

      this.props.navigation.dispatch(navigateAction);
      this.props.navigation.dispatch(DrawerActions.closeDrawer());
  }

  render () {
      return (
      <View>
        <ScrollView>
          <View>
            <Text style={{ margin: 15, fontSize: 20, color: theme.colors.secondary, fontWeight: "bold" }}>
            Hi User,
            </Text>
            <View style={styles.menuItem}>
              <Text onPress={this.navigateToScreen("Home")}>
                Home
              </Text>
            </View>
            <View style={styles.menuItem}>
              <Text onPress={this.navigateToScreen("Profile")}>
              Profile
              </Text>
            </View>
            <View style={styles.menuItem}>
              <Text onPress={this.navigateToScreen("Payment")}>
                Payment
              </Text>
            </View>
            <View style={styles.menuItem}>
              <Text onPress={this.navigateToScreen("AboutUs")}>
                AboutUs
              </Text>
            </View>
          </View>
        </ScrollView>
      </View>
    );
   }
}

DrawerScreen.propTypes = {
    navigation: PropTypes.object
};

export default DrawerScreen;

index.js

const navigationOptions = {
    defaultNavigationOptions: {
        headerStyle: {
            backgroundColor: theme.colors.primary,
        },
        headerTintColor: "#fff",
    }
};

const MenuImage = ({navigation}) => {
  if(!navigation.state.isDrawerOpen){
      return <Image source={require("../../assets/menu-button.png")}/>
  }else{
      return <Image source={require("../../assets/left-arrow.png")}/>
  }
}

const AuthStack = createStackNavigator({
    Login: {
        screen: LoginScreen,
        navigationOptions: { title: "Login" }
    },
    ForgotPassword: {
        screen: ForgotPasswordScreen,
        navigationOptions: { title: "Forgot Password" }
    }
}, {
    ...navigationOptions
});

const DrawerStack = createDrawerNavigator({
    Home: {
    screen: HomeScreen,
    navigationOptions: { title: "Home" }
    },
    Profile: {
    screen: ProfileScreen,
    navigationOptions: { title: "Profile" }
    },
    Payment: {
    screen: PaymentScreen,
    navigationOptions: { title: "Payment" }
    }
}, {
    initialRouteName: "Home",
    contentComponent: DrawerScreen,
});

const DrawerNavigation = createStackNavigator({
  DrawerStack: {
    screen: DrawerStack,
  },
  AboutUs: {
    screen: AboutUsScreen,
    navigationOptions: { title: "About Us" }
  }
},{
  navigationOptions: ({ navigation }) => ({
    title: 'ReactNavigation',
    headerLeft: 
      <TouchableOpacity  onPress={() => {navigation.dispatch(DrawerActions.toggleDrawer())} }>
        <MenuImage navigation={navigation}/>
      </TouchableOpacity>,
    }),
  ...navigationOptions
});

const MainNavigator = createAppContainer(createSwitchNavigator(
    {
        SplashScreen: SplashScreen,
    Auth: AuthStack,
    App: DrawerNavigation,
    },
    {
        initialRouteName: "SplashScreen",
    }
));

export default createAppContainer(MainNavigator);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...