Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Detect onScrollEndDrag and execute final animation. #16

Open
benevbright opened this issue Sep 1, 2018 · 7 comments
Open

Detect onScrollEndDrag and execute final animation. #16

benevbright opened this issue Sep 1, 2018 · 7 comments
Labels
enhancement New feature or request

Comments

@benevbright
Copy link
Owner

It does not detect the end of scroll and make final action.
At the result, when we scroll to make it half collapsed, it stays there.
So we detect onScrollEndDrag of ScrollView and execute final animation.

reference:
https://medium.com/appandflow/react-native-collapsible-navbar-e51a049b560a

@benevbright benevbright added enhancement New feature or request help wanted Extra attention is needed labels Sep 1, 2018
@benevbright benevbright changed the title Feature: Detect onScrollEndDrag and execute final animation. Detect onScrollEndDrag and execute final animation. Sep 23, 2018
@benevbright
Copy link
Owner Author

I'm more than happy to discuss it here.

@paolospag
Copy link

Hi @benevbright ,
I'm trying to do that with the latest version of react-navigation-collapsible (3.0.3).

Using withCollapsibleForTabChild HOC, I do that:

...
componentDidMount = () => {
...
    this.props.collapsible.navigation.setParams({isHeaderCollapsed: false});
...
}
...
_onScrollEndDrag = (e) => {
    const { contentOffset } = e.nativeEvent;
    const { isHeaderCollapsed } = this.props.collapsible.navigation.getParam('isHeaderCollapsed', false);
    const { animatedY } = this.props.collapsible;
    if (contentOffset.y >= 30 && !isHeaderCollapsed) {
      Animated.timing(animatedY, {
        toValue: 165,
        duration: 200,
        useNativeDriver: true
      }).start()
    } else if (contentOffset.y < 30) {
      Animated.timing(animatedY, {
        toValue: 0,
        duration: 200,
        useNativeDriver: true
      }).start()
    }
  }
...
render() {
    const { data } = this.state;
    const { animatedY, onScroll } = this.props.collapsible;
    return (
      <AnimatedFlatList 
        bounces={false}
        data={data || []}
        keyExtractor={item => item.id}
        renderItem={this._renderFlatListItem}
        contentContainerStyle={styles.listContainer}
        showsVerticalScrollIndicator={false}
        onScrollEndDrag={this._onScrollEndDrag} // <-- add this line
        onScroll={onScroll} 
        _mustAddThis={animatedY}
      />
    )
  }
...

I point out that 165 is extra header height.

With these changes everything seems to work correctly: on drag end, the header is collapsed immediately, but I'm not able to continue scrolling with collapsed header because the animatedY keeps updating due to the onScroll event (and accordingly other values such as translateY, translateOpacity, translateProgress).

This isn't a working solution, but it could be a good starting point.

What do you think about it?

@benevbright
Copy link
Owner Author

Oh, Nice! and I'm so sorry for the late response... 😭
You're correct. This can't be done because of the reason you mentioned.

I have different approach in my mind, which is setting a Timer loop that is adding the height like animatedY = Animated.add(animatedY, 1) until they reached to place where it should be. I know this sounds really weird, but I think it would be the only solution I guess..

@paolospag
Copy link

paolospag commented Mar 8, 2019

Hi @benevbright,
don't worry for the late response...

I think only you can find the solution to this problem, I will be grateful.

@benevbright
Copy link
Owner Author

Thanks. But your example is really useful.
I will use it. It's defitetly good starting point.

@andyr6381
Copy link

I ended up towards this library as I was using the medium example mentioned and it's far from perfect. (UX experience is jittery and small incremental scrolls just hides the nav bar once you reach the threshold)

What I'm trying to accomplish is if the user scrolls down any amount, run the timing animation, hide the NavBar and clamp. If the user scrolls up the show the nav bar parallel with the distance the user scrolls and clamp if it reaches the max height.. #struggling

@poonamdhomane
Copy link

for me if scroll it in landscape mode its working but for portrait mode it is not scrolling ...even the list larger than screen

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants