scrollTo has no animation on Android

198 Views Asked by At

For some reason calling scrollTo({x: 50}) on ScrollView and scrollToOffset({offset: 50}) on FlatList has no animation on Android only.

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

The same problem happens when using FlatList with the proper adjustments.

1

There are 1 best solutions below

0
On

Turns out I had two calls to the scrollTo method (somewhere else in the code), equivalent example:

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

And for some reason this caused the Android animation not to work.