【问题标题】:Got problem when switching between tabs using react-native-scrollable-tab-view使用 react-native-scrollable-tab-view 在选项卡之间切换时出现问题
【发布时间】:2020-11-04 08:46:46
【问题描述】:

我正在使用 ScrollableTabView,但在选项卡之间切换时出现问题。在我的应用程序中,我有 3 个选项卡视图:全部、流行、菜单。当我在全部选项卡中时,我可以在全部选项卡中看到菜单选项卡。

here is the problem

这是我的 HomeScreen.js:

import React from 'react';
import { StyleSheet, View, Text, ImageBackground, Dimensions } from 'react-native';
import ScrollableTabView, { DefaultTabBar } from 'react-native-scrollable-tab-view';
import All from '../src/components/All';
import Menu from '../src/components/Menu';
import Popular from '../src/components/Popular';

const HomeScreen = () => {
    return (
        <View style={styles.container}>
            <View style={styles.header}>
                <ImageBackground
                    source={require("../src/assets/header.png")}
                    style={styles.imageBackground}
                    resizeMode="contain"
                >
                    <Text style={styles.title}>HOME</Text>
                </ImageBackground>
            </View>
            <View style={styles.tabbar}>
                <ScrollableTabView
                    initialPage={0}
                    renderTabBar={() =>
                        <DefaultTabBar underlineStyle={{ backgroundColor: 'green' }} style={{ borderWidth: 0 }} />}
                    tabBarActiveTextColor="green"
                >
                    <All tabLabel="All" />
                    <Menu tabLabel="Menu" />
                    <Popular tabLabel="Popular" />

                </ScrollableTabView>
            </View>
        </View>
    );
}

const { width } = Dimensions.get('screen');

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    header: {
        marginTop: 10,
        position: 'absolute'
    },
    tabbar: {
        flex: 1,
        marginTop: width * 0.3,
        paddingHorizontal: 30,
    },
    imageBackground: {
        width: width * 0.4,
        height: width * 0.4,
        alignItems: 'center'
    },
    title: {
        color: 'white',
        marginTop: 20,
        fontWeight: 'bold',
        fontSize: 25
    }
});

export default HomeScreen;

谁能给我解释一下?

【问题讨论】:

    标签: react-native react-native-scrollable-tab-view


    【解决方案1】:

    检查你的styles.tabbar:

    tabbar: {
            flex: 1,
            marginTop: width * 0.3,
            paddingHorizontal: 30,
        },
    

    你应该从这里移除 paddingHorizo​​ntal

    【讨论】:

    • 我想在标签栏中添加一些 paddingHorizo​​ntal ,我该怎么做?
    • 您应该将其提供给 DefaultTabBar 组件的 style 属性,而不是包装所有选项卡的完整视图
    • 它不起作用,我已经尝试为容器视图设置 paddingHorizo​​ntal,它仍然不起作用
    • 你能把ScrollableTabView组件的父View去掉吗,不是主要的,我说的是有style propstyles.tabbar的那个
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    相关资源
    最近更新 更多