【问题标题】:scrollTo has no animation on AndroidscrollTo 在 Android 上没有动画
【发布时间】:2020-12-14 09:41:29
【问题描述】:

由于某种原因,在 ScrollView 上调用 scrollTo({x: 50}) 和在 FlatList 上调用 scrollToOffset({offset: 50}) 仅在 Android 上没有动画。

const scrollViewRef = useRef<ScrollView>(null);
...
const handleOnPress = useCallback(
  (data) => {
    scrollViewRef.current.scrollToOffset({offset: getOffset(data)});
    ...
  },
  [getOffset]
);
...
<ScrollView
  ref={scrollViewRef}
  ...
>
  <MyItem onPress={handleOnPress}/>
<ScrollView/>

在使用 FlatList 并进行适当调整时会出现同样的问题。

【问题讨论】:

  • 默认情况下 animated 为 true 但请尝试手动设置。
  • 谢谢@LeriGogsadze,我确实试过了。请参阅我的答案以了解我的问题。
  • 你能给我一个小吃网址吗?

标签: android react-native react-native-android react-native-flatlist react-native-scrollview


【解决方案1】:

原来我有两次调用scrollTo 方法(代码中的其他地方),等效示例:

const handleOnPress = useCallback(
  (data) => {
    scrollViewRef.current.scrollToOffset({offset: getOffset(data)});
    scrollViewRef.current.scrollToOffset({offset: getOffset(data)});
    ...
  },
  [getOffset]
);

由于某种原因,这导致 Android 动画无法正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 2013-04-11
    相关资源
    最近更新 更多