【发布时间】:2021-01-29 08:20:10
【问题描述】:
我的数学真的很差,我正在尝试计算滚动视图的顶部,因为我希望它位于顶部视图的顶部,以便为滚动视图腾出更多位置。
我知道我可以使用 Animate.View 来完成此操作,但由于组件 (RecyclerListView) 我无法做到这一点。所以我的想法是,当我向下滚动时,我将组件 ItemList 向上移动直到位于 -150 并且当我向上滚动时,我将移动直到值 scrollY 达到 0。
Stack(here) 上已经有一个帖子显示了我想要的内容。
这是我的代码。
<View> this is the View i want to cover/fold <View>
<ItemList style={{top:scrollY}}
onScroll={(nativeEvent, offsetX, offsetY)=>{
// when scroll down, scrollY should not exeede 0
// when i scroll up, scrollY should not be more -150
var maxScroll = 0;
var minScroll = -150;
// How should i calculate and set setScrollY()
}}
columnPerRaw={columnPerRar}
itemHeight={150}
onIni={(s: any) => {
setScroll(s);
}}
onItemPress={(item, index) => itemClick(item as item)}
items={data ?? []}
renderItem={renderItem}
onEndReached={() => {
if (globalContext.value.panination && !isLoading)
setEffectTrigger(Math.random());
}}
keyName="name"
/>
更新
我已经像@Nnay 所说的那样做了,但它并不顺利
var maxScroll = 0; // when i scroll up, scrollY should not be more then 0
var minScroll = -150; // when scroll down, scrollY should not exeede -150
var top = lastPos - offsetY;
if (top >minScroll && top <=maxScroll)
setScrollY(top);
lastPos = offsetY;
我已经做到了
【问题讨论】:
标签: javascript reactjs react-native