StackNavigator菜单在左侧未对齐

时间:2019-03-08 02:53:45

标签: react-native react-navigation native-base

我正在尝试在我的Expo应用程序中实现react stack navigator。该应用程序运行正常,只是抽屉菜单图标并未如预期那样显示在左侧。谁能告诉我我搞砸了吗?

这是应用程序的屏幕截图 enter image description here

这是我的App.js

import React from 'react';
import { StyleSheet, Text, View, SafeAreaView, ScrollView, Dimensions, Image } from 'react-native';

import {createDrawerNavigator,DrawerItems} from 'react-navigation'

import SplashScreen from './src/components/splash';
import LibraryScreen from './src/screens/LibraryScreen';
import ReminderScreen from './src/screens/ReminderScreen';
import ReportScreen from './src/screens/ReportScreen';
import SettingsScreen from './src/screens/SettingsScreen';
import TrainingScreen from './src/screens/TrainingScreen';

export default class App extends React.Component {
  render() {
    return (
      <AppDrawerNavigator/>
    );
  }
}

const CustomDrawerComponent = (props) =>(
  <SafeAreaView style={{ flex:1 }}>
    <View style={{ height:150, backgroundColor: 'white',alignItems:'center', justifyContent:'center' }}>
      <Image source={require('./assets/icon.png')} style={{ height:120, width: 120, borderRadius:60 }} />
    </View>
    <ScrollView>
      <DrawerItems {...props} />
    </ScrollView>
  </SafeAreaView>
)

const AppDrawerNavigator = createDrawerNavigator({
  Training:TrainingScreen,
  Library:LibraryScreen,
  Report:ReportScreen,
  Reminder:ReminderScreen,
  Settings:SettingsScreen
},{
  contentComponent:CustomDrawerComponent
})

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

这是Training.js

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

import {header,Left,Right,Icon, Header} from 'native-base'

class TrainingScreen extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Header>
          <Left>
            <Icon name="menu" onPress={()=>this.props.navigation.openDrawer()}/>
          </Left>
        </Header>
        <View style={{flex:1, alignItems:'center', justifyContent:'center'}}>
          <Text>Training Screen</Text>
        </View>
      </View>
    );
  }
}
export default TrainingScreen;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
  },
});

2 个答案:

答案 0 :(得分:1)

您可能需要在NativeBase Left中包含所有BodyRightHeader

<Header>
  <Left>
    <Icon name="menu" onPress={()=>this.props.navigation.openDrawer()}/>
  </Left>
  <Body/>
  <Right/>
</Header>

答案 1 :(得分:1)

只需在代码中添加以下样式即可。在您的代码中添加此样式<< strong>左样式= {{justifyContent:“ flex-start”,flex:1}} >

Training.js

form_start(formOne)
form_rest(formOne)
    <button type="submit">one</button>
form_end(formOne)


form_start(formOne)
form_rest(formOne)
    <button type="submit">one</button>
form_end(formOne)