0

我将 DrawerNavigator 用于 React-Native,并在 Drawer 内使用以下 CustomDrawerContentComponent ...

const uiTheme = {
  palette: {
    primaryColor: COLOR.blue500,
  },
  toolbar: {
    container: {
      height: 80,
    },
  },
};

const propTypes = {
  navigation: PropTypes.shape({
    goBack: PropTypes.func.isRequired,
  }).isRequired,
};

const CustomDrawerContentComponent = props => (
  <Container>
    <Toolbar
      leftElement="arrow-back"
      onLeftElementPress={() => this.props.navigation.goBack()}
      centerElement="Menu"
    />
    <View>
      <Drawer.Header>
        <Drawer.Header.Account
          avatar={<Avatar text="K" />}
          footer={{
            dense: true,
            centerElement: {
              primaryText: 'Account',
              secondaryText: 'xxxx@yahoo.com',
            },
            rightElement: 'arrow-drop-down',
          }}
        />
      </Drawer.Header>
      <DrawerItems {...props} />
    </View>
  </Container>
);

const MainRoot = DrawerNavigator(
  {
    Login: {
      path: '/login',
      screen: Login,
    },
    Profile: {
      path: '/profile',
      screen: Profile,
    },
    Settings: {
      path: '/settings',
      screen: Settings,
    },
  },
  {
    initialRouteName: 'Settings',
    contentOptions: {
      activeTintColor: '#2089b0',
      activeBackgroundColor: 'transparent',
      inactiveTintColor: '#000000',
      inactiveBackgroundColor: 'transparent',
      labelStyle: {
        fontSize: 18,
        marginLeft: 0,
        fontFamily: 'sans-serif-thin',
      },
    },
    drawerWidth: SCREEN_WIDTH * 0.8,
    contentComponent: CustomDrawerContentComponent,
    drawerOpenRoute: 'DrawerOpen',
    drawerCloseRoute: 'DrawerClose',
    drawerToggleRoute: 'DrawerToggle',
  }
);

export default class AppContainer extends Component {
  render() {    
    return (
      <ThemeContext.Provider value={getTheme(uiTheme)}>
        <MainRoot />
      </ThemeContext.Provider>
    );
  }
}

Expo.registerRootComponent(AppContainer);

我想要做的是将工具栏的元素定位到底部......

侧边菜单

这是怎么做到的..?(对不起,React-Native 相对较新......)

此外,代码 onLeftElementPress={() => this.props.navigation.goBack()} 为 this.props.navigation 返回 null。

是否需要传递一些东西..?

谢谢。

4

1 回答 1

0

我正在使用 react-native-material-ui,所以 Toolbar 有 leftElementContainer 和 centerElementContainer 元素。因此可以使用以下方式对它们进行样式设置:

const uiTheme = {
  palette: {
    primaryColor: COLOR.blue500,
  },
  toolbar: {
    container: {
      height: 80,
    },
    leftElementContainer: {
      marginTop: 20,
    },
    centerElementContainer: {
      marginTop: 20,
    },
  },
};
于 2018-07-12T02:00:35.150 回答