Skip to content

Instantly share code, notes, and snippets.

@bogoslavskiy
Created July 8, 2018 18:49
Show Gist options
  • Save bogoslavskiy/b4d0ce326bd3c44653a1bcafd750f41f to your computer and use it in GitHub Desktop.
Save bogoslavskiy/b4d0ce326bd3c44653a1bcafd750f41f to your computer and use it in GitHub Desktop.
export default class SearchBarProvider extends React.Component {
constructor(props) {
super(props);
this.searchBarAnimation = new SearchBarAnimation({
scrollToOffset: (configScroll) => {
let tab = configScroll.tab ? configScroll.tab : this.props.currentTab;
let scrollToOffset = this._handlersScroll[tab];
scrollToOffset && scrollToOffset(configScroll.offset, configScroll.animated);
}
});
this.state = {
currentTab: null,
canJumpToTab: true,
contextProvider: {
animation: this.searchBarAnimation.animationProps,
addHandlerScroll: this._addHandlerScroll,
}
};
}
componentWillUnmount() {
this.searchBarAnimation.destroy();
}
_handlersScroll = {};
_addHandlerScroll = (tab, handler) => {
this._handlersScroll[tab] = handler;
};
render() {
return (
<SearchBarContext.Provider value={this.state.contextProvider}>
{this.props.children(this.searchBarAnimation)}
</SearchBarContext.Provider>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment