【问题标题】:How to Make Carousel View of Screens without Navigation in React Native如何在 React Native 中制作没有导航的屏幕轮播视图
【发布时间】:2021-07-05 07:17:44
【问题描述】:

我想实现屏幕的动态轮播视图(类似于Swiper)。我正在考虑创建一个带有条件渲染的View,它将通过selectedId 显示与每个屏幕相对应的屏幕,但这会导致在每个屏幕上重新渲染,除非我对每个屏幕都有一个状态。

有没有更好的解决方案可以在不使用导航的情况下制作屏幕轮播视图并保存屏幕上的数据?

【问题讨论】:

  • 我想其中一种解决方案是制作一个FlatList,底部有一个有条件渲染的按钮,这将显示屏幕的延续(使用scrollEnabled={false},分页和scrollToIndex方法正确ref)。如果这种方法可行,我会发布答案。

标签: reactjs react-native navigation


【解决方案1】:

我使用react-native-progress-steps 来解决这个问题。我稍微修改了配置文件,并为它编写了一个虚拟数据模板。

虚拟数据:

const reviewData = [
    {
        id: "1",
        serviceID: 0,
    },
    {
        id: "2",
        serviceID: 1,
    },
    {
        id: "3",
        serviceID: 2,
    },
];

渲染(忽略颜色):

<View style={styles.container}>
            <ProgressSteps
                activeStepIconColor={defaultColors.white}
                completedProgressBarColor={settings.colors.primary}
                progressBarColor={defaultColors.light}
                activeStepIconBorderColor={settings.colors.primary}
                completedStepIconColor={settings.colors.primary}
                disabledStepIconColor={defaultColors.light}
                activeStepNumColor={defaultColors.dark}
                disabledStepNumColor={defaultColors.mediumLight}
            >
                {reviewData.map((item, index) => (
                    <ProgressStep
                        nextBtnStyle={styles.nextButtonStyle}
                        previousBtnStyle={
                            index === 0
                                ? styles.disabledButton
                                : styles.prevButtonStyle
                        }
                        nextBtnTextStyle={styles.nextButtonTextStyle}
                        previousBtnTextStyle={styles.prevButtonTextStyle}
                        previousBtnText={`Назад`}
                        nextBtnText={`Дальше`}
                        finishBtnText={`Завершить`}
                        previousBtnDisabled={index === 0 ? true : false}
                    >
                        <View style={{ alignItems: "left" }}>
                            <AppText>
                                {item.serviceID},{index}
                            </AppText>
                        </View>
                    </ProgressStep>
                ))}
            </ProgressSteps>
        </View>

我对解决方案感到满意,但如果您有其他解决方案,请告诉我 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多