octopitus / rn-sliding-up-panel

Draggable sliding up panel implemented in React Native https://octopitus.github.io/rn-sliding-up-panel/
MIT License
928 stars 157 forks source link

Initial value not respected #113

Closed samiede closed 5 years ago

samiede commented 5 years ago

Issue Description

I'm setting the initial panel position the following way, it works when using it the first time. After I've changed screen with componentWillUnmount being called, the panel remains in the position I left it in when leaving the screen, even though the constructor is called again and _animatedValue has the correct value.

Steps to Reproduce / Code Snippets / Screenshots

  constructor (props) {
    super(props)
    this.draggableRange = {
      bottom: 100,
      top: height - StatusBar.currentHeight - 60
    }
    this._animatedValue = new Animated.Value(windowHeight / 2)
  }

  <SlidingUpPanel
          showBackdrop={false}
          onBackButtonPress={() => true}
          animatedValue={this._animatedValue}
          draggableRange={this.draggableRange}
          snappingPoints={[100, height / 2, height]}>
          {(dragHandlers) => ( .... )

/>

Environment

octopitus commented 5 years ago

Investigating. For now a workaround is to reset the animation to default value when your component will unmount.

Put this to your component:

componentWillUnmount() {
  this._animatedValue.resetAnimation()
}
samiede commented 5 years ago

I fear that this has something to do with my own implementation because your workaround works exactly once and then doesn’t when going to the screen again

Am 03.05.2019 um 14:12 schrieb Luy Tran notifications@github.com:

Investigating. For now a workaround is to reset the animation https://facebook.github.io/react-native/docs/animatedvalue#resetanimation to default value when your component will unmount.

Put this to your component:

componentWillUnmount() { this._animatedValue.resetAnimation() } — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/octopitus/rn-sliding-up-panel/issues/113#issuecomment-489074724, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOFHOVPDD2DHIV3UCWO4BLPTQTZVANCNFSM4HKTLTTQ.

samiede commented 5 years ago

Update from my side:

I had an @autobind decorator in that screen that apparently caused the behavior. Removing that and binding all functions manually resolved the issue! Thanks!

faustoct1 commented 5 years ago

animatedValue is not working for me at all animatedValue={top} renders like bottom

arnaud-roland commented 5 years ago

I'm currently experiencing the same issue. My component is correctly initialized the first time but after it will unmount and did mount again (life cycle is the same as the first time), the position isn't correctly initialized the second time even if the state is the same.