Skip to content

Commit

Permalink
handling appstate Event subscription correctly (#5091)
Browse files Browse the repository at this point in the history
* handling appstate Event subscription correctly due to RemoveEventListener removal in RN 0.71

* cleanup, to prevent unnecessary diff noise
  • Loading branch information
mwieja authored Oct 4, 2023
1 parent 5e6e784 commit 1a62bdc
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ enableScreens();
const containerStyle = { flex: 1 };

class OldApp extends Component {
state = { appState: AppState.currentState, initialRoute: null };
state = {
appState: AppState.currentState,
initialRoute: null,
eventSubscription: null,
};

/**
* There's a race condition in Branch's RN SDK. From a cold start, Branch
Expand Down Expand Up @@ -143,7 +147,11 @@ class OldApp extends Component {
InteractionManager.runAfterInteractions(() => {
rainbowTokenList.update();
});
AppState?.addEventListener('change', this?.handleAppStateChange);
const eventSub = AppState?.addEventListener(
'change',
this?.handleAppStateChange
);
this.setState({ eventSubscription: eventSub });
rainbowTokenList.on('update', this.handleTokenListUpdate);
appEvents.on('transactionConfirmed', this.handleTransactionConfirmed);

Expand Down Expand Up @@ -183,9 +191,9 @@ class OldApp extends Component {
}

componentWillUnmount() {
AppState?.removeEventListener('change', this?.handleAppStateChange);
rainbowTokenList?.off?.('update', this.handleTokenListUpdate);
this.branchListener?.();
this.state.eventSubscription.remove();
rainbowTokenList.off('update', this.handleTokenListUpdate);
this.branchListener();
}

identifyFlow = async () => {
Expand Down

0 comments on commit 1a62bdc

Please sign in to comment.