在屏幕中央实现选项卡 [英] implement tabs in the center of the screen

查看:37
本文介绍了在屏幕中央实现选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是本机反应的新手.我已经在 drawernavigator 中实现了 stacknavigator.使用这个库"反应导航": "^1.0.0-beta.11",

I am new to react native. i have implemented stacknavigator inside drawernavigator. Using this library "react-navigation": "^1.0.0-beta.11",

现在我想在屏幕中央实现选项卡.下图是我屏幕的一部分

Now i want to implement tabs within the screen at the center. Following image is part of my screen

我不知道如何使用任何库或手动放置视图来执行此操作.

i dont have any idea how can i do this with any library or manually putting views.

感谢任何帮助.谢谢

推荐答案

嗯,我已经使用 react-native-swiper

基本上,您必须将您想要的所有视图包装在 Swiper 中,根据需要渲染和设置标题的样式.

Basically you have to wrap all views you want to have inside a Swiper, render and style the header as you want.

这是我制作的一个工作示例:

Here there is a working example I've made:

render() {
    return (
        <View style={styles.body}>
            <Swiper
              height={500}
              showsPagination={true}
              loop={false}
              renderPagination={this._renderPagination}
              ref={component => this._swiper = component}>
                <View style={styles.page}>
                    <FlatList data={..} renderItem={item => ...} keyExtractor={(item, index) => index} />
                </View>
                <View style={styles.page}>
                    <FlatList data={...} renderItem={item => ...} keyExtractor={(item, index) => index} />
                </View>
                <View style={styles.page}>
                    <FlatList data={...} renderItem={item => ...} keyExtractor={(item, index) => index} />
                </View>
                <View style={styles.page}>
                    <FlatList data={...} renderItem={item => ...} keyExtractor={(item, index) => index} />
                </View>
            </Swiper>
        </View>
    );
}

_renderPagination(index, total, context) {
    return (
        <View style={styles.pagination}>
            {this._renderPaginationHeaders(index, total, context)}
        </View>
    )
}

_renderPaginationHeaders(index, total, context) {
    let ret = [];
    for (let i = 0; i < total; i++) {
        ret.push(
            <TouchableOpacity key={i} style={{ flex: 1, flexDirection: 'column' }} onPress={() => this._onPageChange(i)}>
                <Text style={[styles.title, { flex: 1, textAlign: 'center', textAlignVertical: 'center' }]}>
                    {this._getSectionText(i)}
                </Text>
                <View style={{ height: 5, backgroundColor: index === i ? 'magenta' : 'transparent' }}></View>
            </TouchableOpacity>
        );
    }

return ret;
}

_onPageChange(targetIndex) {
    const currentIndex = this._swiper.state.index;
    const offset = targetIndex - currentIndex;
    this._swiper.scrollBy(offset);
}

const styles = StyleSheet.create({
  body: {
    flex: 1,
    alignItems: 'center',
    alignSelf: 'center',
    backgroundColor: '#f1f1f1',
  },
  pagination: {
    flexDirection: 'row',
    width: Dimensions.get('window').width,
    height: Header.currentHeight * 0.7,
    backgroundColor: '#2E2E2E',
    paddingLeft: 2,
    paddingRight: 2,
    alignItems: 'center',
    position: 'absolute',
    top: 0,
  },
  page: {
    flex: 1,
    marginTop: (Header.currentHeight * 0.7) + 3
  },
  title: {
    color: 'white'
  },
});

这篇关于在屏幕中央实现选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆