diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..03d9549
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..9bd16c0
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/react-native-orientation-locker.iml b/.idea/react-native-orientation-locker.iml
new file mode 100644
index 0000000..24643cc
--- /dev/null
+++ b/.idea/react-native-orientation-locker.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 0ad3680..885a0ec 100644
--- a/README.md
+++ b/README.md
@@ -233,28 +233,33 @@ Whenever you want to use it within React Native code now you can:
import Orientation from 'react-native-orientation-locker';
- _onOrientationDidChange = (orientation) => {
+_onOrientationDidChange = (orientation) => {
if (orientation == 'LANDSCAPE-LEFT') {
- //do something with landscape left layout
+ //do something with landscape left layout
} else {
- //do something with portrait layout
+ //do something with portrait layout
}
- };
+};
- componentWillMount() {
+componentWillMount()
+{
//The getOrientation method is async. It happens sometimes that
//you need the orientation at the moment the js starts running on device.
//getInitialOrientation returns directly because its a constant set at the
//beginning of the js code.
var initial = Orientation.getInitialOrientation();
if (initial === 'PORTRAIT') {
- //do stuff
+ //do stuff
} else {
- //do other stuff
+ //do other stuff
}
- },
+}
+,
- componentDidMount() {
+componentDidMount()
+{
+ // init sdk Only need android other platforms can ignore
+ Orientation.init();
Orientation.getAutoRotateState((rotationLock) => this.setState({rotationLock}));
//this allows to check if the system autolock is enabled or not.
@@ -276,11 +281,14 @@ import Orientation from 'react-native-orientation-locker';
*/
Orientation.addOrientationListener(this._onOrientationDidChange);
- },
+}
+,
- componentWillUnmount: function() {
+componentWillUnmount: function () {
Orientation.removeOrientationListener(this._onOrientationDidChange);
- }
+ // init sdk Only need android other platforms can ignore
+ Orientation.removeInit();
+}
```
### Reactive component ``
diff --git a/android/src/main/java/org/wonday/orientation/OrientationModule.java b/android/src/main/java/org/wonday/orientation/OrientationModule.java
index 35041fd..ecb07c0 100644
--- a/android/src/main/java/org/wonday/orientation/OrientationModule.java
+++ b/android/src/main/java/org/wonday/orientation/OrientationModule.java
@@ -16,6 +16,7 @@
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.hardware.SensorManager;
+import android.util.Log;
import android.view.Display;
import android.view.OrientationEventListener;
import android.view.Surface;
@@ -40,10 +41,9 @@
public class OrientationModule extends ReactContextBaseJavaModule implements OrientationListeners {
final BroadcastReceiver mReceiver;
- final OrientationEventListener mOrientationListener;
+ private OrientationEventListener mOrientationListener;
final ReactApplicationContext ctx;
private boolean isLocked = false;
- private boolean isConfigurationChangeReceiverRegistered = false;
private String lastOrientationValue = "";
private String lastDeviceOrientationValue = "";
@@ -51,67 +51,6 @@ public OrientationModule(ReactApplicationContext reactContext) {
super(reactContext);
ctx = reactContext;
- mOrientationListener = new OrientationEventListener(reactContext, SensorManager.SENSOR_DELAY_UI) {
-
- @Override
- public void onOrientationChanged(int orientation) {
-
- FLog.d(ReactConstants.TAG,"DeviceOrientation changed to " + orientation);
-
- String deviceOrientationValue = lastDeviceOrientationValue;
-
-
- if (orientation == -1) {
- deviceOrientationValue = "UNKNOWN";
- } else if (orientation > 355 || orientation < 5) {
- deviceOrientationValue = "PORTRAIT";
- } else if (orientation > 85 && orientation < 95) {
- deviceOrientationValue = "LANDSCAPE-RIGHT";
- } else if (orientation > 175 && orientation < 185) {
- deviceOrientationValue = "PORTRAIT-UPSIDEDOWN";
- } else if (orientation > 265 && orientation < 275) {
- deviceOrientationValue = "LANDSCAPE-LEFT";
- }
-
- if (!lastDeviceOrientationValue.equals(deviceOrientationValue)) {
-
- lastDeviceOrientationValue = deviceOrientationValue;
-
- WritableMap params = Arguments.createMap();
- params.putString("deviceOrientation", deviceOrientationValue);
- if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("deviceOrientationDidChange", params);
- }
- }
-
- String orientationValue = getCurrentOrientation();
- if (!lastOrientationValue.equals(orientationValue)) {
- lastOrientationValue = orientationValue;
-
- FLog.d(ReactConstants.TAG,"Orientation changed to " + orientationValue);
-
- WritableMap params = Arguments.createMap();
- params.putString("orientation", orientationValue);
- if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
- }
- }
-
- return;
- }
- };
-
- if (mOrientationListener.canDetectOrientation()) {
- FLog.d(ReactConstants.TAG, "orientation detect enabled.");
- mOrientationListener.enable();
- } else {
- FLog.d(ReactConstants.TAG, "orientation detect disabled.");
- mOrientationListener.disable();
- }
mReceiver = new BroadcastReceiver() {
@Override
@@ -120,14 +59,12 @@ public void onReceive(Context context, Intent intent) {
String orientationValue = getCurrentOrientation();
lastOrientationValue = orientationValue;
- FLog.d(ReactConstants.TAG,"Orientation changed to " + orientationValue);
+ FLog.d(ReactConstants.TAG, "Orientation changed to " + orientationValue);
WritableMap params = Arguments.createMap();
params.putString("orientation", orientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
}
@@ -168,6 +105,71 @@ public void getDeviceOrientation(Callback callback) {
callback.invoke(lastDeviceOrientationValue);
}
+ @ReactMethod
+ public void init() {
+ Log.e("OrientationModule", "init()");
+ mOrientationListener = new OrientationEventListener(ctx, SensorManager.SENSOR_DELAY_UI) {
+
+ @Override
+ public void onOrientationChanged(int orientation) {
+
+ FLog.d(ReactConstants.TAG, "DeviceOrientation changed to " + orientation);
+
+ String deviceOrientationValue = lastDeviceOrientationValue;
+
+
+ if (orientation == -1) {
+ deviceOrientationValue = "UNKNOWN";
+ } else if (orientation > 355 || orientation < 5) {
+ deviceOrientationValue = "PORTRAIT";
+ } else if (orientation > 85 && orientation < 95) {
+ deviceOrientationValue = "LANDSCAPE-RIGHT";
+ } else if (orientation > 175 && orientation < 185) {
+ deviceOrientationValue = "PORTRAIT-UPSIDEDOWN";
+ } else if (orientation > 265 && orientation < 275) {
+ deviceOrientationValue = "LANDSCAPE-LEFT";
+ }
+
+ if (!lastDeviceOrientationValue.equals(deviceOrientationValue)) {
+
+ lastDeviceOrientationValue = deviceOrientationValue;
+
+ WritableMap params = Arguments.createMap();
+ params.putString("deviceOrientation", deviceOrientationValue);
+ if (ctx.hasActiveCatalystInstance()) {
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("deviceOrientationDidChange", params);
+ }
+ }
+
+ String orientationValue = getCurrentOrientation();
+ if (!lastOrientationValue.equals(orientationValue)) {
+ lastOrientationValue = orientationValue;
+
+ FLog.d(ReactConstants.TAG, "Orientation changed to " + orientationValue);
+
+ WritableMap params = Arguments.createMap();
+ params.putString("orientation", orientationValue);
+ if (ctx.hasActiveCatalystInstance()) {
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
+ }
+ }
+
+ }
+ };
+
+ mOrientationListener.enable();
+ }
+
+ @ReactMethod
+ public void removeInit() {
+ Log.e("OrientationModule", "removeInit()");
+ // 停止监听并释放资源
+ if (mOrientationListener != null) {
+ mOrientationListener.disable();
+ mOrientationListener = null; // 释放资源
+ }
+ }
+
@ReactMethod
public void lockToPortrait() {
final Activity activity = getCurrentActivity();
@@ -180,18 +182,14 @@ public void lockToPortrait() {
WritableMap params = Arguments.createMap();
params.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
// send a locked event
WritableMap lockParams = Arguments.createMap();
lockParams.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("lockDidChange", lockParams);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("lockDidChange", lockParams);
}
}
@@ -207,18 +205,14 @@ public void lockToPortraitUpsideDown() {
WritableMap params = Arguments.createMap();
params.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
// send a locked event
WritableMap lockParams = Arguments.createMap();
lockParams.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("lockDidChange", lockParams);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("lockDidChange", lockParams);
}
}
@@ -234,18 +228,14 @@ public void lockToLandscape() {
WritableMap params = Arguments.createMap();
params.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
// send a locked event
WritableMap lockParams = Arguments.createMap();
lockParams.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("lockDidChange", lockParams);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("lockDidChange", lockParams);
}
}
@@ -261,18 +251,14 @@ public void lockToLandscapeLeft() {
WritableMap params = Arguments.createMap();
params.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
// send a locked event
WritableMap lockParams = Arguments.createMap();
lockParams.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("lockDidChange", lockParams);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("lockDidChange", lockParams);
}
}
@@ -288,18 +274,14 @@ public void lockToLandscapeRight() {
WritableMap params = Arguments.createMap();
params.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
// send a locked event
WritableMap lockParams = Arguments.createMap();
lockParams.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("lockDidChange", lockParams);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("lockDidChange", lockParams);
}
}
@@ -316,28 +298,22 @@ public void unlockAllOrientations() {
WritableMap params = Arguments.createMap();
params.putString("orientation", lastOrientationValue);
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("orientationDidChange", params);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("orientationDidChange", params);
}
// send a unlocked event
WritableMap lockParams = Arguments.createMap();
lockParams.putString("orientation", "UNKNOWN");
if (ctx.hasActiveCatalystInstance()) {
- ctx
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
- .emit("lockDidChange", lockParams);
+ ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("lockDidChange", lockParams);
}
}
@ReactMethod
public void getAutoRotateState(Callback callback) {
- final ContentResolver resolver = ctx.getContentResolver();
- boolean rotateLock = android.provider.Settings.System.getInt(
- resolver,
- android.provider.Settings.System.ACCELEROMETER_ROTATION, 0) == 1;
- callback.invoke(rotateLock);
+ final ContentResolver resolver = ctx.getContentResolver();
+ boolean rotateLock = android.provider.Settings.System.getInt(resolver, android.provider.Settings.System.ACCELEROMETER_ROTATION, 0) == 1;
+ callback.invoke(rotateLock);
}
@Override
@@ -353,51 +329,49 @@ public void getAutoRotateState(Callback callback) {
@Override
public void start() {
FLog.i(ReactConstants.TAG, "orientation detect enabled.");
- mOrientationListener.enable();
+ if (mOrientationListener != null) {
+ mOrientationListener.enable();
+
+ }
ctx.registerReceiver(mReceiver, new IntentFilter("onConfigurationChanged"));
- isConfigurationChangeReceiverRegistered = true;
}
@Override
public void stop() {
FLog.d(ReactConstants.TAG, "orientation detect disabled.");
- mOrientationListener.disable();
+ if (mOrientationListener != null) {
+ mOrientationListener.disable();
+ }
try {
- if (isConfigurationChangeReceiverRegistered) {
- ctx.unregisterReceiver(mReceiver);
- isConfigurationChangeReceiverRegistered = false;
- }
- } catch (Exception e) {
- FLog.w(ReactConstants.TAG, "Receiver already unregistered", e);
+ ctx.unregisterReceiver(mReceiver);
+ } catch (java.lang.IllegalArgumentException e) {
+ FLog.w(ReactConstants.TAG, "Receiver already unregistered", e);
}
}
@Override
public void release() {
FLog.d(ReactConstants.TAG, "orientation detect disabled.");
- mOrientationListener.disable();
+ if (mOrientationListener != null) {
+ mOrientationListener.disable();
+ }
final Activity activity = getCurrentActivity();
if (activity == null) return;
- try
- {
- if (isConfigurationChangeReceiverRegistered) {
- activity.unregisterReceiver(mReceiver);
- isConfigurationChangeReceiverRegistered = false;
- }
- }
- catch (Exception e) {
+ try {
+ activity.unregisterReceiver(mReceiver);
+ } catch (java.lang.IllegalArgumentException e) {
FLog.w(ReactConstants.TAG, "Receiver already unregistered", e);
}
}
@ReactMethod
public void addListener(String eventName) {
- // Keep: Required for RN built in Event Emitter Calls.
+ // Keep: Required for RN built in Event Emitter Calls.
}
@ReactMethod
public void removeListeners(Integer count) {
- // Keep: Required for RN built in Event Emitter Calls.
+ // Keep: Required for RN built in Event Emitter Calls.
}
}
diff --git a/example/App.js b/example/App.js
index 5c5383b..6f4683a 100644
--- a/example/App.js
+++ b/example/App.js
@@ -10,158 +10,164 @@
import React, {Component, useEffect, useState} from 'react';
import {
- Platform,
- Pressable,
- ScrollView,
- StyleSheet,
- Text,
- TouchableOpacity,
- View,
+ Platform,
+ Pressable,
+ ScrollView,
+ StyleSheet,
+ Text,
+ TouchableOpacity,
+ View,
} from 'react-native';
import Orientation, {
- useOrientationChange,
- useDeviceOrientationChange,
- useLockListener,
+ useOrientationChange,
+ useDeviceOrientationChange,
+ useLockListener,
} from 'react-native-orientation-locker';
export default function App() {
- const [isLocked, setLocked] = useState();
- const [orientation, setOrientation] = useState();
- const [deviceOrientation, setDeviceOrientation] = useState();
- const [lock, setLock] = useState();
+ const [isLocked, setLocked] = useState();
+ const [orientation, setOrientation] = useState();
+ const [deviceOrientation, setDeviceOrientation] = useState();
+ const [lock, setLock] = useState();
- // eslint-disable-next-line react-hooks/exhaustive-deps
- useEffect(() => {
- checkLocked();
- });
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ useEffect(() => {
+ //Initializing screen monitoring (Fixes android HuaWei,XiaoMi, privacy contract issues)
+ Orientation.init()
+ checkLocked();
+ return()=>{
+ //remove
+ Orientation.removeInit()
+ }
+ });
- useOrientationChange((o) => {
- setOrientation(o);
- });
+ useOrientationChange((o) => {
+ setOrientation(o);
+ });
- useDeviceOrientationChange((o) => {
- setDeviceOrientation(o);
- });
+ useDeviceOrientationChange((o) => {
+ setDeviceOrientation(o);
+ });
- useLockListener((o) => {
- setLocked(o);
- });
+ useLockListener((o) => {
+ setLocked(o);
+ });
- function checkLocked() {
- const locked = Orientation.isLocked();
- if (locked !== isLocked) {
- setLocked(locked);
+ function checkLocked() {
+ const locked = Orientation.isLocked();
+ if (locked !== isLocked) {
+ setLocked(locked);
+ }
}
- }
- return (
-
- ☆OrientationLocker example☆
-
- isLocked
- {isLocked ? 'TRUE' : 'FALSE'}
-
-
- addOrientationListener
- {orientation}
-
-
- addDeviceOrientationListener
- {deviceOrientation}
-
-
- {
- Orientation.lockToPortrait();
- checkLocked();
- }}
- style={styles.button}>
- Lock me to PORTRAIT
-
- {
- Orientation.lockToPortraitUpsideDown();
- checkLocked();
- }}
- style={styles.button}>
- Lock me to PORTRAIT UPSIDE DOWN
-
- {
- Orientation.lockToLandscape();
- checkLocked();
- }}
- style={styles.button}>
- Lock me to LANDSCAPE
-
- {
- Orientation.lockToLandscapeLeft();
- checkLocked();
- }}
- style={styles.button}>
- Lock me to LANDSCAPE LEFT
-
- {
- Orientation.lockToLandscapeRight();
- checkLocked();
- }}
- style={styles.button}>
- Lock me to LANDSCAPE RIGHT
-
+ return (
+
+ ☆OrientationLocker example☆
+
+ isLocked
+ {isLocked ? 'TRUE' : 'FALSE'}
+
+
+ addOrientationListener
+ {orientation}
+
+
+ addDeviceOrientationListener
+ {deviceOrientation}
+
+
+ {
+ Orientation.lockToPortrait();
+ checkLocked();
+ }}
+ style={styles.button}>
+ Lock me to PORTRAIT
+
+ {
+ Orientation.lockToPortraitUpsideDown();
+ checkLocked();
+ }}
+ style={styles.button}>
+ Lock me to PORTRAIT UPSIDE DOWN
+
+ {
+ Orientation.lockToLandscape();
+ checkLocked();
+ }}
+ style={styles.button}>
+ Lock me to LANDSCAPE
+
+ {
+ Orientation.lockToLandscapeLeft();
+ checkLocked();
+ }}
+ style={styles.button}>
+ Lock me to LANDSCAPE LEFT
+
+ {
+ Orientation.lockToLandscapeRight();
+ checkLocked();
+ }}
+ style={styles.button}>
+ Lock me to LANDSCAPE RIGHT
+
- {
- Orientation.unlockAllOrientations();
- checkLocked();
- }}
- style={styles.button}>
- Unlock all orientations
-
-
-
- );
+ {
+ Orientation.unlockAllOrientations();
+ checkLocked();
+ }}
+ style={styles.button}>
+ Unlock all orientations
+
+
+
+ );
}
const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#F5FCFF',
- },
- welcome: {
- fontSize: 20,
- textAlign: 'center',
- margin: 10,
- marginTop: 50,
- },
- row: {
- flexDirection: 'row',
- marginTop: 10,
- paddingHorizontal: 15,
- alignItems: 'center',
- },
- value: {
- backgroundColor: 'green',
- color: 'black',
- paddingHorizontal: 10,
- paddingVertical: 5,
- },
- button: {
- backgroundColor: 'orange',
- padding: 10,
- borderRadius: 10,
- marginTop: 10,
- },
+ container: {
+ flex: 1,
+ backgroundColor: '#F5FCFF',
+ },
+ welcome: {
+ fontSize: 20,
+ textAlign: 'center',
+ margin: 10,
+ marginTop: 50,
+ },
+ row: {
+ flexDirection: 'row',
+ marginTop: 10,
+ paddingHorizontal: 15,
+ alignItems: 'center',
+ },
+ value: {
+ backgroundColor: 'green',
+ color: 'black',
+ paddingHorizontal: 10,
+ paddingVertical: 5,
+ },
+ button: {
+ backgroundColor: 'orange',
+ padding: 10,
+ borderRadius: 10,
+ marginTop: 10,
+ },
});
diff --git a/index.d.ts b/index.d.ts
index 9fdb641..93a2da1 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -32,14 +32,12 @@ export interface OrientationLockerProps {
onDeviceChange?: (deviceOrientation: OrientationType) => void;
}
-type IOSConfigurationOptions = {
- disableFaceUpDown: boolean;
-}
-
export const OrientationLocker: React.ComponentType;
declare class Orientation {
- static configure(options: IOSConfigurationOptions): void;
+
+ static init(): void;
+ static removeInit(): void;
static addOrientationListener(callback: (orientation: OrientationType) => void): void;
@@ -73,6 +71,7 @@ declare class Orientation {
static unlockAllOrientations(): void;
+
static getOrientation(callback: (orientation: OrientationType) => void): void;
static getDeviceOrientation(callback: (orientation: OrientationType) => void): void;
@@ -82,11 +81,11 @@ declare class Orientation {
export default Orientation;
-declare function useOrientationChange(listener: (orientation: OrientationType) => void): void;
+declare function useOrientationChange(listener: (orientation: OrientationType) => void);
-declare function useDeviceOrientationChange(listener: (orientation: OrientationType) => void): void;
+declare function useDeviceOrientationChange(listener: (orientation: OrientationType) => void);
-declare function useLockListener(listener: (orientation: OrientationType) => void): void;
+declare function useLockListener(listener: (orientation: OrientationType) => void);
export {
useOrientationChange,
diff --git a/src/orientation.android.js b/src/orientation.android.js
index 18720f4..e435f91 100644
--- a/src/orientation.android.js
+++ b/src/orientation.android.js
@@ -31,16 +31,19 @@ function getKey(listener) {
}
export default class Orientation {
- static configure = (_options) => {
- // ios only
- };
-
static getOrientation = (cb) => {
OrientationNative.getOrientation((orientation) => {
cb(orientation);
});
};
+ static init =()=>{
+ OrientationNative.init()
+ }
+ static removeInit=()=>{
+ OrientationNative.removeInit()
+ }
+
static getDeviceOrientation = (cb) => {
OrientationNative.getDeviceOrientation((deviceOrientation) => {
cb(deviceOrientation);
diff --git a/src/orientation.ios.js b/src/orientation.ios.js
index 06da486..e4b8d27 100644
--- a/src/orientation.ios.js
+++ b/src/orientation.ios.js
@@ -40,7 +40,12 @@ export default class Orientation {
cb(orientation);
});
};
+ static init =()=>{
+ }
+ static removeInit =()=>{
+
+ }
static getDeviceOrientation = cb => {
OrientationNative.getDeviceOrientation(deviceOrientation => {
cb(deviceOrientation);
diff --git a/src/orientation.js b/src/orientation.js
index 6b0224e..bce4880 100644
--- a/src/orientation.js
+++ b/src/orientation.js
@@ -9,8 +9,6 @@
"use strict";
export default class Orientation {
- static configure = options => {}
-
static getOrientation = cb => {
cb("UNKNOWN");
};
@@ -24,6 +22,8 @@ export default class Orientation {
};
static lockToPortrait = () => {};
+ static init = () => {};
+ static removeInit = () => {};
static lockToPortraitUpsideDown = () => {};