Created
July 8, 2018 18:49
-
-
Save bogoslavskiy/b4d0ce326bd3c44653a1bcafd750f41f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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