Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,24 @@ protected void refreshToken() {
}

protected void sendTokenToJS() {
final ReactInstanceManager instanceManager = ((ReactApplication) mAppContext).getReactNativeHost().getReactInstanceManager();
ReactContext reactContext = instanceManager.getCurrentReactContext();
ReactContext reactContext = null;

if (reactContext == null) {
// If the react context is not available, try to get the current context from the react host (RN0.76).
// Try New Architecture first (ReactHost) - available in RN 0.76+
try {
reactContext = ((ReactApplication) mAppContext).getReactHost().getCurrentReactContext();
} catch (NoSuchMethodError | RuntimeException e) {
// getReactHost() doesn't exist in older RN versions or throws in some cases
// Fall back to Old Architecture (ReactNativeHost)
}

if (reactContext == null) {
try {
final ReactInstanceManager instanceManager = ((ReactApplication) mAppContext).getReactNativeHost().getReactInstanceManager();
reactContext = instanceManager.getCurrentReactContext();
} catch (RuntimeException e) {
// getReactNativeHost() throws RuntimeException in New Architecture
// This is expected, we'll just continue with null reactContext
}
}
// Note: Cannot assume react-context exists cause this is an async dispatched service.
if (reactContext != null && reactContext.hasActiveReactInstance()) {
Expand Down
2 changes: 1 addition & 1 deletion react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
ios: {},
android: {
sourceDir: './lib/android/app',
packageInstance: 'new RNNotificationsPackage(reactNativeHost.getApplication())',
packageInstance: 'new RNNotificationsPackage(getApplication())',
}
},
},
Expand Down