React-native-reanimated-bottom-sheet: snapTo snapping to the wrong SnapPoint

Created on 1 Feb 2020  路  14Comments  路  Source: osdnk/react-native-reanimated-bottom-sheet

I have a simple sheet component with 3 buttons:

export const SimpleSheet: React.FC = (): JSX.Element => {
  const bs = useRef<BottomSheet>(null)

  const renderContent = () => (
    <View style={styles.content}>
      <Button title="Top" onPress={() => { bs?.current?.snapTo(2) }} />
      <Button title="Center" onPress={() => { bs?.current?.snapTo(1) }} />
      <Button title="Bottom" onPress={() => { bs?.current?.snapTo(0) }} />
    </View>
  )

  return (
    <BottomSheet
      ref={bs}
      snapPoints={[125, '50%', '95%']}
      initialSnap={1}
      renderContent={renderContent}
    />
  )
}
  1. I press the Top button
    -> snap to top

  2. I press the Bottom button
    -> nothing happens

  3. I press the Center button
    -> snap to bottom

It seems as the component is remembering the last snap point it is supposed to snap to and performs the action after the next snapTo.

happend on current npm version 1.0.0-alpha.18 on iOS

Thanks in advance

Most helpful comment

downgrade version to '1.0.0-alpha.14' works for me !

All 14 comments

A dirty solution would be to perform snapTo twice:

export const SimpleSheet: React.FC = (): JSX.Element => {
  const bs = useRef<BottomSheet>(null)

  const snapTo = (snapPoint: number): void => {
    bs?.current?.snapTo(snapPoint)
    bs?.current?.snapTo(snapPoint)
  }

  const renderContent = () => (
    <View style={styles.content}>
      <Button title="Top" onPress={() => snapTo(2) } />
      <Button title="Center" onPress={() => snapTo(1)} />
      <Button title="Bottom" onPress={() => snapTo(0)} />
    </View>
  )

  return (
    <BottomSheet
      ref={bs}
      snapPoints={[125, '50%', '95%']}
      initialSnap={1}
      renderContent={renderContent}
    />
  )
}

It works, but it just doesn't seem right.

Having the same issue with my app, the "hack" works, but would love a more proper solution.

+1, same problem

+1 same issue here within a functional component

Having the same issue after update from '1.0.0-alpha.14' to '1.0.0-alpha.18'.

+1 same issue with 1.0.0-alpha.19

+1 Same issue here. Android with 1.0.0-alpha.19

+1

+1

downgrade version to '1.0.0-alpha.14' works for me !

+1

downgrading to version to '1.0.0-alpha.14' doesn't work for me.

Possibly fixed by https://github.com/osdnk/react-native-reanimated-bottom-sheet/pull/206 which was included in the recent release 1.0.0-alpha.20.

bs = React.createRef(null);

ref={this.bs}
snapPoints={[330, 0]}
borderRadius={10}
/>
i use with this keyword fixed

call ref like this : this.bs.current.snapTo(1);

Was this page helpful?
0 / 5 - 0 ratings