首页 > 解决方案 > React Native - 用户向下滚动足够多后,使视图出现并跟随屏幕,视图出现和消失太慢

问题描述

我有一个按钮,在用户在 ScrollView 中包含的长屏幕上向下滚动足够多后出现,我有一些代码并且它可以工作,但是视图需要一整秒才能出现和消失,这太慢了!有没有办法让它更快地出现和消失?

const [showBottomButton, setShowBottomButton] = useState(false)

.

const  handleScroll = (event) => {
        var curY = event.nativeEvent.contentOffset.y;
            if (curY>=500 && !showBottomButton){
                setShowBottomButton(true)
            }else if (curY<500 && showBottomButton){
                setShowBottomButton(false)
            }
    }

.

{showBottomButton ? <View style={{ position: 'absolute', left: 0, bottom: 0, right: 0, height: 70, alignItems: 'center', justifyContent: 'center', backgroundColor: 'white', borderTopWidth: 1, borderColor: '#eeeeee' }}>
                <TouchableOpacity onPress={BottomButtonOnpress}>
                    <View style={styles.BottomButton}
                        <Text style={styles.MediumText}>Button Text</Text>
                    </View></TouchableOpacity>
            </View> : null}

标签: androidreact-nativereact-hooksscrollview

解决方案


推荐阅读