Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thekevinscott/b028de2ade49127b560c43e929056731 to your computer and use it in GitHub Desktop.
Save thekevinscott/b028de2ade49127b560c43e929056731 to your computer and use it in GitHub Desktop.
class WrapperComponent extends Component {
constructor(props) {
super(props);
this.state = {
handledMounted: false,
appState: null,
};
this.refHandler = this.refHandler.bind(this);
this.handleAppStateChange = this.handleAppStateChange.bind(this);
this.componentWillAppear = this.componentWillAppear.bind(this);
}
componentWillMount() {
this.componentWillAppear();
AppState.addEventListener('change', this.handleAppStateChange);
}
componentWillAppear() {
if (this.instance) {
if (!this.instance.componentWillAppear) {
console.warn('You called connectFocus with a component that failed to implement componentWillAppear', this.instance);
} else {
this.instance.componentWillAppear();
}
}
}
componentWillUnmount() {
AppState.removeEventListener('change', this.handleAppStateChange);
}
handleAppStateChange(newAppState) {
if (this.state.appState !== newAppState && newAppState === 'active' && this.isComponentActive(this.props.activeComponent)) {
this.componentWillAppear();
}
this.setState({
appState: newAppState,
});
}
. . .
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment