I'm building an app, where I have a realizable header called <SearchBar />
which has prop isCollaped
(value can be true or false) which opens and closes the container, and a <ScrollView />
(Screenshot below, sorry for not having text in English).Screenshots of an app:
I want to collapse the <SearchBar />
when starting to scroll the <ScrollView />
so I am setting the value of isCollaped
to true, and it works, but because of <ScrollView />
calling onScroll
every 200ms, and Scrolling animation not stopping after releasing a finger, when I try to open the <SearchBar />
again by pressing on it, and if the scroll animation is still active, I'm getting a really buggy animation that collapses the <SearchBar />
again.
This part of the code resizes the SearchBar when pressing on it:
collapseSearchBar = () => { this.setState({ searchBarCollapsed: !this.state.searchBarCollapsed, });};
This is the <SearchBar/>
:
<SearchBar isCollapsed={this.state.searchBarCollapsed} onCollapse={this.collapseSearchBar} onSearch={this.search}/>
This is the code for <ScrollView />
:
<ListView ref='mainScrollView' dataSource={this.state.dataSource} renderRow={(rowData) => { return this._renderRow(rowData, this.props.navigation); }} onScroll={() => { if (!this.state.searchBarCollapsed) { this.setState({ searchBarCollapsed: true }); } }}/>
My question is: How can I make a <ScrollView />
call onScroll
just once, when user swipes it, and not all the time (every 200ms, for about 3 seconds after the animation starts), while the animation is active.