【问题标题】:React Native Router Flux: How to style NavDrawer's button and navigation bar?React Native Router Flux:如何设置 NavDrawer 的按钮和导航栏的样式?
【发布时间】:2016-10-07 05:36:39
【问题描述】:

在 React Native Router Flux 中,我有一个功能性的 react-native-drawer,称为 NavDrawer。它目前在导航栏左侧有默认的汉堡菜单图标,并希望将其更改为另一个自定义图标。所以我尝试了,leftTitle='Menu',但它没有改变。

所以我想知道如何自定义react-native-drawer 的默认菜单图标?

我还通过navigationBarStyle 更改了导航栏的高度,因此按钮当前位于靠近导航栏底部而不是中间的位置。所以在navigationBarStyle 中,我尝试了flex: 1, flexDirection: 'row', alignItems: 'center',但没有改变任何东西。

那么如何在导航栏中水平居中对齐元素?

代码如下:

        <Scene key='drawer' component={NavDrawer} open={false}>
          <Scene key="main" navigationBarStyle={styles.navigationBar} onRight={() => Actions.profile()} rightTitle='Profile'>
                        ...
          </Scene>
        <Scene/>

谢谢

【问题讨论】:

    标签: javascript ios reactjs react-native react-native-router-flux


    【解决方案1】:

    所以我想知道如何自定义 react-native-drawer 的默认菜单图标?

    我使用react-native-vector-icons,它允许您从几个不同的集合中选择图标,包括谷歌的Material Icons。这是我的代码的样子:

    首先,我使用renderLeftButton Scene 属性来渲染我的自定义按钮。

    <Scene key='navigationDrawerContentWrapper' navigationBarStyle={SceneStyle.navigationBar} titleStyle={SceneStyle.title}>
       <Scene key='mainScreen' component={MainScreen} title='Main Screen' renderLeftButton={NavigationItems.menuButton} sceneStyle={SceneStyle.scene} initial={true}/>
    </Scene>
    

    NavigationItems.js 看起来像这样:

    const menuButton = () => {
        return (
            <TouchableOpacity onPress={openDrawer} style={Dimensions.iconSmall.touchableObject}>
                <Icon name='menu'
                    size={24}
                    color={#ffffff}/>
            </TouchableOpacity>
        )
    }
    
    const openDrawer = () => {
        Actions.refresh({ key: 'drawer', open: true })
    }
    

    那么如何在导航栏中水平居中对齐元素?

    我认为您的意思是垂直对齐。尝试this 解决方案,该解决方案建议使用具有以下样式的弹性框:

      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center'
      }
    

    【讨论】:

    • 感谢您的回复。至于第一个示例,您介意显示您提供的 NavigationItems.js 示例的完整 .js 以进行澄清吗?至于对齐,是的,对不起,我的意思是垂直居中,我试了一下navigaitonBarStyle,但按钮没有移动。那是我应该设计的地方吗?再次感谢您
    • 刚刚签到看看你是否看到了我之前的评论。请告诉我。
    • 您好,很抱歉耽搁了。 NavigationItems.js 基本上包含这两个函数。您不妨将它们移动到定义场景的同一文件中。您是否设法使用react-native-vector-icons 或其他模块自定义默认图标?至于对齐方式,是的,我希望它在设置为navigationBarStyle 时可以工作。这种样式应该在图标的父组件中定义,我猜是导航栏。
    • 是的,我尝试了该图标,但没有成功。一个完整的例子真的很有帮助。至于对齐,我尝试了一下,但元素根本没有移动。
    猜你喜欢
    • 2018-01-22
    • 1970-01-01
    • 2023-04-05
    • 2023-04-04
    • 2017-03-14
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多