热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在react-native中对齐导航屏幕内容-alignnavscreencontentinreact-native

Iamverynewtoreact-native.Iamtryingtocreateadrawerusingreact-navigation.IcoulduseDr

I am very new to react-native. I am trying to create a drawer using react-navigation. I could use DrawerNavigator but could not show the header/navbar on all the screens. That is why i create a NavScreen component with profile icon, title and back icon. However they are not aligned properly. I need profile icon to be shown on the left side, title on the center and back button on the right side. How can i do this?

我很反应原生。我正在尝试使用react-navigation创建抽屉。我可以使用DrawerNavigator,但无法在所有屏幕上显示标题/导航栏。这就是为什么我创建一个带有配置文件图标,标题和后退图标的NavScreen组件。但是它们没有正确对齐。我需要在左侧显示配置文件图标,在中间显示标题,在右侧显示后退按钮。我怎样才能做到这一点?

Here is my code

这是我的代码

const styles = StyleSheet.create({
  container: {
    marginTop: Platform.OS === 'ios' ? 20 : 10,
  },
});
const NavScreen = ({ navigation, banner }) => (
  
    {banner}
     navigation.navigate('DrawerOpen')}
    />
     navigation.goBack(null)}
    />
  
);

export default NavScreen;


class App extends React.Component {
  static navigatiOnOptions= ({ navigation }) => ({
    title: `${navigation.state.routeName}`,
    drawerTitle: `${navigation.state.routeName}`,
    drawerLabel: 'Home',
    drawerIcon: ({ whiteColor }) => (
      
    ),
  })

  render() {
    const { navigation } = this.props;
    return (
      
        
        Main Screen
      
    );
  }
}

export default App;

I need similar to the below image

我需要类似下面的图像

enter image description here

1 个解决方案

#1


0  

First, try to build a StackNavigation, at headerRight, and headerLeft you define your custom buttons (the above), now you can very easy customize the align/padding whatever you need with your icons/buttons.

首先,尝试在headerRight上构建StackNavigation,并在headerLeft中定义自定义按钮(上图),现在您可以使用图标/按钮轻松自定义对齐/填充。

const stackNavigatorCOnfiguration= {
  // set first Screen
  initialRouteName: 'Home',
  mode: Platform.OS === 'ios' ? 'card' : 'card',
  navigationOptions: ({navigation}) => ({
    headerRight: ,
    headerLeft: ,
    headerBackTitle: null
  })
}

const YourProfileButton = ({ navigation }) => (
  
     navigation.goBack(null)}
    />
  
)

const DrawerButton = ({ navigation }) => (
  
     navigation.navigate('DrawerOpen')}
    />
  
)

推荐阅读
author-avatar
9小酒
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有