Skip to content

Commit 45f4b36

Browse files
docs: update readme with the new app AppState event listener method
1 parent 47ee4d3 commit 45f4b36

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,13 @@ public class MainNotificationService extends FirebaseMessagingService {
227227
/**
228228
* Handle PushNotification
229229
*/
230-
AppState.addEventListener(
230+
const appStateListener = AppState.addEventListener(
231231
'change',
232232
(nextAppState) =>
233233
nextAppState === 'active' && Intercom.handlePushMessage()
234234
);
235-
return () => AppState.removeEventListener('change', () => true);
235+
return () => AppState.removeEventListener('change', () => true); // <- for RN < 0.65
236+
return () => appStateListener.remove() // <- for RN >= 0.65
236237
}
237238
, [])
238239
```
@@ -621,16 +622,14 @@ Handles the opening of an Intercom push message. This will retrieve the URI from
621622
/**
622623
* Handle PushNotification Open
623624
*/
624-
AppState.addEventListener(
625+
const appStateListener = AppState.addEventListener(
625626
'change',
626627
(nextAppState) =>
627628
nextAppState === 'active' && Intercom.handlePushMessage()
628629
);
629630

630-
return () => {
631-
AppState.removeEventListener('change', () => {
632-
});
633-
};
631+
return () => AppState.removeEventListener('change', () => {}); // <- for RN < 0.65
632+
return () => appStateListener.remove(); // <- for RN >= 0.65
634633
}, []);
635634
```
636635

0 commit comments

Comments
 (0)