react-nativa仿照美团。第二页附近的一级界面

附近

添加tab标签页的依赖
yarn add react-native-scrollable-tab-view

具体可以去giehub官网了解详情

<View style={styles.container}>
                    <Header/>
                    <View style={{height: 1,backgroundColor:'#000000'}}/>
                    <ScrollableTabView style={styles.ScrollableTabView}
                                       tabBarBackgroundColor={'#ffb92e'}
                                       tabBarActiveTextColor={'#000000'}
                                       tabBarUnderlineStyle={styles.tabBarUnderline}
                                       tabBarTextStyle={styles.tabBarTextStyle}
                                       tabBarInactiveTextColor={'#FFFFFF'}
                                       initialPage={0}
                                       locked={false}
                                       renderTabBar={() => <ScrollableTabBar/>}>
                        <View tabLabel={data[0].title} style={styles.container}><TopNavigationItem tabListData={data[0].tab}/></View>
                        <View tabLabel={data[1].title} style={styles.container}><TopNavigationItem tabListData={data[1].tab}/></View>
                        <View tabLabel={data[2].title} style={styles.container}><TopNavigationItem tabListData={data[2].tab}/></View>
                        <View tabLabel={data[3].title} style={styles.container}><TopNavigationItem tabListData={data[3].tab}/></View>
                    </ScrollableTabView>
                </View>

在开始的时候虽然添加上了tab标签但是下边始终是空白页面,不显示内容(如图),在最外层加了flex:1就好了。还有一些属性及默认值很好理解。
在这里插入图片描述

每一个页面,这里我只用了一个页面传入不同的参数,加载了4次构成的
//头部数据
        let {tabListData} = this.props;
        let tabTexts = [];
        for (let i = 0; i < tabListData.length; i++) {
            tabTexts.push(
                //点击改变当前text的背景色
                //知道点击的是第几个就在状态中存索引,重新绘制添加text到数组,当状态等等于索引的时候添加另一个text
                i == this.state.bState ?
                    <TouchableNativeFeedback
                        key={i}
                        onPress={() => this._onPressButton(i)}>
                        <Text style={[styles.text, {backgroundColor: '#000000', color: '#FFFFFF',}]}
                              key={i}>{tabListData[i]}</Text>
                    </TouchableNativeFeedback> :
                    <TouchableNativeFeedback key={i}
                                             onPress={() => this._onPressButton(i)}>
                        <Text style={styles.text} key={i}>{tabListData[i]}</Text>
                    </TouchableNativeFeedback>
            )
        }
        if (this.state.isShowActivityIndicator) {
            return (
                <ActivityIndicator animating={this.state.isShowActivityIndicator}
                                   size={'large'}
                                   style={styles.container}
                />
            );
        } else {
            return (
                <View style={styles.view}>

                    <FlatList
                        keyExtractor={(item, index) => (item.id)}
                        data={this.state.food}
                        renderItem={({item, index}) => this.renderItem(item, index)}
                        ItemSeparatorComponent={ItemDivideComponent}
                        ListHeaderComponent={<View style={[styles.view,{marginBottom: 5,marginTop: 5}]}>{tabTexts}</View>}
                        refreshControl={<RefreshControl
                            refreshing={this.state.refreshing}
                            onRefresh={this._onRefresh}
                        />}
                    />
                </View>
            )
        }

这里的头部布局是我自己用text组件拼成的,setState刷新状态产生的选中效果。而在状态中记录了点击第几个,在刷新时判断这个加载哪一个text就好了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值