javascript - 滚动到特定偏移 y 时显示搜索栏
问题描述
我在 React Native 中使用平面列表。我想在用户向下滚动并到达时显示搜索栏而不是图标offset.y >= 70
,然后将其切换回来offset.y < 0
。我尝试onScroll
在我的平面列表中设置一个调用我的函数:
<FlatList
onScroll={showSearchBar}
scrollEnabled={false}
data={products}
numColumns={2}
keyExtractor={(item) => item.id.toString()}
renderItem={___}
onEndReachedThreshold={0.09}
onEndReached={() => {
getNewData();
}}
/>
const showSearchBar = (e) => {
if (Math.floor(e.nativeEvent.contentOffset.y) >= 70)
{
setShowSearch(true);
}
else
{
setShowSearch(false);
}
}
<Stack.Screen
........................
headerRight: () => {
if (showSearch) {
<View>
<Text>
search bar
</Text>
</View>
} else {
<TouchableOpacity onPress={() => navigation.navigate("about")}>
<AntDesign
name="questioncircleo"
size={30}
color="white"
style={{
marginRight: 15,
justifyContent: "center",
}}
/>
</TouchableOpacity>;
}
},
title: "",
})}
name="home"
component={Home}
/>
…但它不能正常工作。我试过了while
do
,switch
case
但它总是在滚动停止时显示栏搜索......否则它一直显示图标。
解决方案
推荐阅读
- python - TypeError 使用 timedelta,不能求和时间
- django - 在序列化程序实例上没有字段的情况下将字段添加到 Django REST
- jquery - 在更短的时间内渲染 jquery 数据表中的 mongo 集合数据
- python - Python 和 SQL Server - 如何在具有变量的多个列中进行选择?
- ios - withUnsafeMutableBytes' 已弃用 xcode 警告
- c# - 实体框架返回延迟加载查询并以另一种方法应用过滤器
- javascript - CSS 渲染后的自定义元素中是否有回调?
- c - 反转后如何正确打印子字符串
- regex - 正则表达式:匹配两个字符串之间的所有字符
- firebase - 按文档 ID 对集合 Firestore 中的文档进行排序