diff --git a/android/src/main/java/com/github/yamill/orientation/OrientationModule.java b/android/src/main/java/com/github/yamill/orientation/OrientationModule.java index 1065a0f8..9c1f2c62 100644 --- a/android/src/main/java/com/github/yamill/orientation/OrientationModule.java +++ b/android/src/main/java/com/github/yamill/orientation/OrientationModule.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; -public class OrientationModule extends ReactContextBaseJavaModule implements LifecycleEventListener{ +public class OrientationModule extends ReactContextBaseJavaModule implements LifecycleEventListener { final BroadcastReceiver receiver; public OrientationModule(ReactApplicationContext reactContext) { @@ -44,8 +44,8 @@ public void onReceive(Context context, Intent intent) { params.putString("orientation", orientationValue); if (ctx.hasActiveCatalystInstance()) { ctx - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) - .emit("orientationDidChange", params); + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit("orientationDidChange", params); } } }; @@ -116,7 +116,9 @@ public void unlockAllOrientations() { } @Override - public @Nullable Map getConstants() { + public + @Nullable + Map getConstants() { HashMap constants = new HashMap(); int orientationInt = getReactApplicationContext().getResources().getConfiguration().orientation; @@ -145,32 +147,25 @@ private String getOrientationString(int orientation) { @Override public void onHostResume() { final Activity activity = getCurrentActivity(); - - assert activity != null; + if (activity == null) { + FLog.e(ReactConstants.TAG, "no activity to register receiver"); + return; + } activity.registerReceiver(receiver, new IntentFilter("onConfigurationChanged")); } + @Override public void onHostPause() { final Activity activity = getCurrentActivity(); if (activity == null) return; - try - { + try { activity.unregisterReceiver(receiver); - } - catch (java.lang.IllegalArgumentException e) { + } catch (java.lang.IllegalArgumentException e) { FLog.e(ReactConstants.TAG, "receiver already unregistered", e); } } @Override public void onHostDestroy() { - final Activity activity = getCurrentActivity(); - if (activity == null) return; - try - { - activity.unregisterReceiver(receiver); - } - catch (java.lang.IllegalArgumentException e) { - FLog.e(ReactConstants.TAG, "receiver already unregistered", e); - }} } +} diff --git a/iOS/RCTOrientation/Orientation.h b/iOS/RCTOrientation/Orientation.h index 05bfe65e..c01ed000 100644 --- a/iOS/RCTOrientation/Orientation.h +++ b/iOS/RCTOrientation/Orientation.h @@ -4,7 +4,13 @@ #import #import +#if __has_include() +#import +#elif __has_include("RCTBridgeModule.h") #import "RCTBridgeModule.h" +#elif __has_include("React/RCTBridgeModule.h") +#import "React/RCTBridgeModule.h" // Required when used as a Pod in a Swift project +#endif @interface Orientation : NSObject + (void)setOrientation: (UIInterfaceOrientationMask)orientation; diff --git a/iOS/RCTOrientation/Orientation.m b/iOS/RCTOrientation/Orientation.m index f8ec60db..93b89117 100644 --- a/iOS/RCTOrientation/Orientation.m +++ b/iOS/RCTOrientation/Orientation.m @@ -3,7 +3,14 @@ // #import "Orientation.h" + +#if __has_include() +#import +#elif __has_include("RCTEventDispatcher.h") #import "RCTEventDispatcher.h" +#elif __has_include("React/RCTEventDispatcher.h") +#import "React/RCTEventDispatcher.h" // Required when used as a Pod in a Swift project +#endif @implementation Orientation @synthesize bridge = _bridge;