简体   繁体   English

如何在React Native的标题中放置搜索栏?

[英]How to place Search Bar inside header in React Native?

I am trying to create this header for my app in React Native. 我正在尝试在React Native中为我的应用创建此标头 There is the title of the screen, a button to go back to the previous screen, and a search bar below them taking up the entire width of the screen. 屏幕标题,返回上一屏幕的按钮以及位于其下方的搜索栏占据了整个屏幕的宽度。 All three of these elements should be part of the header. 所有这三个元素应为标头的一部分。

This is what I started with. 就是我的开始。 As you can see, the Search Bar is outside the header and is scrollable (which it shouldn't be). 如您所见,搜索栏位于标题外部,并且可以滚动(不应滚动)。

After trying several different techniques, I'm nowhere close to my intended design. 在尝试了几种不同的技术之后,我离预期的设计还很遥远。 This is what I have till now :( 就是我到目前为止所拥有的:(

The code below is from my latest attempt: 以下代码是我最近的尝试:

Code for header: 标头代码:

static navigationOptions = ({ navigation }) => ({
        // headerLeft: <CloseModalButton navigation={navigation} testID='new-message-view-close' />,
        headerStyle: { backgroundColor: '#F9F9F9' },
        header: (
            <View>
                <Text fontSize={17}>{I18n.t('New_Message')}</Text>
                <SearchBox onChangeText={text => this.onSearchChangeText(text)} testID='new-message-view-search' />
            </View>
        ),
        title: I18n.t('New_Message')
    })

Styling for the searchBox component: searchBox组件的样式:

searchBox: {
        alignItems: 'center',
        backgroundColor: '#E6E8E9',
        borderRadius: 10,
        color: '#8E8E93',
        flexDirection: 'row',
        fontSize: 17,
        height: 43,
        margin: 8,
        marginVertical: 10,
        paddingHorizontal: 10
    },

How can I go from what I have now to my intended design? 如何从现有的设计过渡到预期的设计? I am particularly struggling with getting the Search Bar to align correctly with the other 2 elements. 我特别想让搜索栏与其他2个元素正确对齐。 Any and all help is appreciated. 任何和所有帮助表示赞赏。

Dropping a expo snack for the idea. 为这个想法放一个世博会小吃。 Expo snack link 世博小吃链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM