react-native-orientation-director 2.4.0 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -107,7 +107,7 @@ To properly handle interface orientation changes in iOS, you need to update your
107
107
 
108
108
  ##### Objective-C
109
109
 
110
- In your AppDelegate.h file, import "OrientationDirector.h" and implement supportedInterfaceOrientationsForWindow method as follows:
110
+ In your AppDelegate.mm file, import "OrientationDirector.h" and implement supportedInterfaceOrientationsForWindow method as follows:
111
111
 
112
112
  ```objc
113
113
  #import <OrientationDirector.h>
@@ -135,6 +135,8 @@ override func application(_ application: UIApplication, supportedInterfaceOrient
135
135
  }
136
136
  ```
137
137
 
138
+ Note: if you are targeting react-native > 79.x, you can omit the `override` keyword.
139
+
138
140
  If you need help, you can check the example project.
139
141
 
140
142
  ## Usage
@@ -19,6 +19,13 @@ import UIKit
19
19
  private var lastInterfaceOrientation = Orientation.UNKNOWN
20
20
  private var lastDeviceOrientation = Orientation.UNKNOWN
21
21
  private var isLocked = false
22
+
23
+ /// # Only on iOS < 16
24
+ /// This variable is needed to prevent a loop where
25
+ /// we lock the interface to a specific orientation
26
+ /// and the sensor picks it up, therefore triggering
27
+ /// the orientation did change event.
28
+ private var isLocking = false
22
29
 
23
30
  @objc public var supportedInterfaceOrientations: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
24
31
 
@@ -56,6 +63,7 @@ import UIKit
56
63
  }
57
64
 
58
65
  @objc public func lockTo(jsValue: NSNumber) {
66
+ self.isLocking = true;
59
67
  let jsOrientation = utils.convertToOrientationFrom(jsValue: jsValue)
60
68
  let mask = utils.convertToMaskFrom(jsOrientation: jsOrientation)
61
69
  self.requestInterfaceUpdateTo(mask: mask)
@@ -65,17 +73,20 @@ import UIKit
65
73
  let orientationCanBeUpdatedDirectly = jsOrientation != Orientation.LANDSCAPE
66
74
  if orientationCanBeUpdatedDirectly {
67
75
  updateLastInterfaceOrientationTo(value: jsOrientation)
76
+ self.isLocking = false;
68
77
  return
69
78
  }
70
79
 
71
80
  let lastInterfaceOrientationIsAlreadyInLandscape = lastInterfaceOrientation == Orientation.LANDSCAPE_RIGHT || lastInterfaceOrientation == Orientation.LANDSCAPE_LEFT
72
81
  if lastInterfaceOrientationIsAlreadyInLandscape {
73
82
  updateLastInterfaceOrientationTo(value: lastInterfaceOrientation)
83
+ self.isLocking = false;
74
84
  return
75
85
  }
76
86
 
77
87
  let systemDefaultLandscapeOrientation = Orientation.LANDSCAPE_RIGHT
78
88
  updateLastInterfaceOrientationTo(value: systemDefaultLandscapeOrientation)
89
+ self.isLocking = false;
79
90
  }
80
91
 
81
92
  @objc public func unlock() {
@@ -155,14 +166,19 @@ import UIKit
155
166
  print("\(OrientationDirectorImpl.TAG) - requestGeometryUpdate error", error)
156
167
  }
157
168
  } else {
158
- UIDevice.current.setValue(mask.rawValue, forKey: "orientation")
169
+ let interfaceOrientation = self.utils.convertToInterfaceOrientationFrom(mask: mask)
170
+ UIDevice.current.setValue(interfaceOrientation.rawValue, forKey: "orientation")
159
171
  UIViewController.attemptRotationToDeviceOrientation()
160
172
  }
161
173
  }
162
174
 
163
175
  private func onOrientationChanged(uiDeviceOrientation: UIDeviceOrientation) {
164
176
  let deviceOrientation = utils.convertToOrientationFrom(deviceOrientation: uiDeviceOrientation)
165
- self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
177
+
178
+ if (!self.isLocking) {
179
+ self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
180
+ }
181
+
166
182
  lastDeviceOrientation = deviceOrientation
167
183
  adaptInterfaceTo(deviceOrientation: deviceOrientation)
168
184
  }
@@ -78,6 +78,21 @@ class Utils {
78
78
  }
79
79
  }
80
80
 
81
+ public func convertToInterfaceOrientationFrom(mask: UIInterfaceOrientationMask) -> UIInterfaceOrientation {
82
+ switch mask {
83
+ case .portrait:
84
+ return .portrait
85
+ case .landscapeRight:
86
+ return .landscapeRight
87
+ case .portraitUpsideDown:
88
+ return .portraitUpsideDown
89
+ case .landscapeLeft:
90
+ return .landscapeLeft
91
+ default:
92
+ return .unknown
93
+ }
94
+ }
95
+
81
96
  public func getInterfaceOrientation() -> UIInterfaceOrientation {
82
97
  guard let windowScene = self.getCurrentWindow()?.windowScene else {
83
98
  return UIInterfaceOrientation.unknown
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('OrientationDirector');
5
+ //# sourceMappingURL=NativeOrientationDirector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AA0BlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,18 +1,10 @@
1
1
  {
2
2
  "name": "react-native-orientation-director",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "A Modern React Native library that allows you to access orientation",
5
5
  "main": "./lib/module/index.js",
6
- "module": "lib/module/index",
7
- "types": "lib/typescript/src/index.d.ts",
8
- "source": "./src/index.tsx",
9
- "exports": {
10
- ".": {
11
- "types": "./lib/typescript/src/index.d.ts",
12
- "default": "./lib/module/index.js"
13
- },
14
- "./package.json": "./package.json"
15
- },
6
+ "module": "./lib/module/index.js",
7
+ "types": "./lib/typescript/src/index.d.ts",
16
8
  "files": [
17
9
  "src",
18
10
  "lib",
@@ -23,6 +15,7 @@
23
15
  "plugin/tsconfig.json",
24
16
  "app.plugin.js",
25
17
  "*.podspec",
18
+ "react-native.config.js",
26
19
  "!ios/build",
27
20
  "!android/build",
28
21
  "!android/gradle",
@@ -63,32 +56,33 @@
63
56
  "registry": "https://registry.npmjs.org/"
64
57
  },
65
58
  "devDependencies": {
66
- "@commitlint/config-conventional": "^17.0.2",
59
+ "@commitlint/config-conventional": "^19.6.0",
60
+ "@eslint/compat": "^1.2.7",
61
+ "@eslint/eslintrc": "^3.3.0",
62
+ "@eslint/js": "^9.22.0",
67
63
  "@evilmartians/lefthook": "^1.5.0",
68
- "@react-native/eslint-config": "0.78.2",
69
- "@release-it/conventional-changelog": "^5.0.0",
64
+ "@react-native-community/cli": "15.0.0-alpha.2",
65
+ "@react-native/babel-preset": "0.79.2",
66
+ "@react-native/eslint-config": "^0.78.0",
67
+ "@release-it/conventional-changelog": "^9.0.2",
70
68
  "@types/jest": "^29.5.5",
71
69
  "@types/react": "^19.0.0",
72
- "commitlint": "^17.0.2",
70
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
71
+ "commitlint": "^19.6.1",
73
72
  "del-cli": "^5.1.0",
74
- "eslint": "^8.51.0",
75
- "eslint-config-prettier": "^9.0.0",
76
- "eslint-plugin-prettier": "^5.0.1",
77
- "expo": "^52.0.35",
73
+ "eslint": "^9.22.0",
74
+ "eslint-config-prettier": "^10.1.1",
75
+ "eslint-plugin-jest": "^27.9.0",
76
+ "eslint-plugin-prettier": "^5.2.3",
78
77
  "jest": "^29.7.0",
79
78
  "prettier": "^3.0.3",
80
79
  "react": "19.0.0",
81
- "react-native": "0.78.2",
82
- "react-native-builder-bob": "^0.40.0",
83
- "release-it": "^15.0.0",
80
+ "react-native": "0.79.2",
81
+ "react-native-builder-bob": "^0.40.10",
82
+ "release-it": "^17.10.0",
84
83
  "turbo": "^1.10.7",
85
84
  "typescript": "^5.2.2"
86
85
  },
87
- "resolutions": {
88
- "@types/react": "^19.0.0",
89
- "@typescript-eslint/eslint-plugin": "^7.1.1",
90
- "@typescript-eslint/parser": "^7.1.1"
91
- },
92
86
  "peerDependencies": {
93
87
  "expo": ">=47.0.0",
94
88
  "react": "*",
@@ -99,6 +93,10 @@
99
93
  "optional": true
100
94
  }
101
95
  },
96
+ "resolutions": {
97
+ "eslint-plugin-jest": "^27.9.0",
98
+ "@typescript-eslint/eslint-plugin": "^7.18.0"
99
+ },
102
100
  "workspaces": [
103
101
  "example",
104
102
  "plugin"
@@ -146,33 +144,6 @@
146
144
  }
147
145
  }
148
146
  },
149
- "eslintConfig": {
150
- "root": true,
151
- "extends": [
152
- "@react-native",
153
- "prettier"
154
- ],
155
- "plugins": [
156
- "prettier"
157
- ],
158
- "rules": {
159
- "react/react-in-jsx-scope": "off",
160
- "prettier/prettier": [
161
- "error",
162
- {
163
- "quoteProps": "consistent",
164
- "singleQuote": true,
165
- "tabWidth": 2,
166
- "trailingComma": "es5",
167
- "useTabs": false
168
- }
169
- ]
170
- }
171
- },
172
- "eslintIgnore": [
173
- "node_modules/",
174
- "lib/"
175
- ],
176
147
  "prettier": {
177
148
  "quoteProps": "consistent",
178
149
  "singleQuote": true,
@@ -190,7 +161,12 @@
190
161
  "esm": true
191
162
  }
192
163
  ],
193
- "typescript"
164
+ [
165
+ "typescript",
166
+ {
167
+ "project": "tsconfig.build.json"
168
+ }
169
+ ]
194
170
  ]
195
171
  },
196
172
  "codegenConfig": {
@@ -202,8 +178,8 @@
202
178
  }
203
179
  },
204
180
  "create-react-native-library": {
205
- "type": "turbo-module",
206
181
  "languages": "kotlin-objc",
207
- "version": "0.48.0"
182
+ "type": "turbo-module",
183
+ "version": "0.50.2"
208
184
  }
209
185
  }
@@ -1,28 +0,0 @@
1
- import type { TurboModule } from 'react-native';
2
- import { TurboModuleRegistry } from 'react-native';
3
-
4
- export interface Spec extends TurboModule {
5
- getInterfaceOrientation(): Promise<number>;
6
- getDeviceOrientation(): Promise<number>;
7
- lockTo(orientation: number): void;
8
- unlock(): void;
9
- isLocked(): boolean;
10
- resetSupportedInterfaceOrientations(): void;
11
-
12
- ////////////////////////////////////
13
- //
14
- // ANDROID ONLY
15
- //
16
-
17
- isAutoRotationEnabled(): boolean;
18
- enableOrientationSensors(): void;
19
- disableOrientationSensors(): void;
20
-
21
- //
22
- ////////////////////////////////////
23
-
24
- addListener: (eventType: string) => void;
25
- removeListeners: (count: number) => void;
26
- }
27
-
28
- export default TurboModuleRegistry.getEnforcing<Spec>('OrientationDirector');
@@ -1,2 +0,0 @@
1
- export default function App(): import("react/jsx-runtime").JSX.Element;
2
- //# sourceMappingURL=App.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../../../example/src/App.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,GAAG,4CAE1B"}
@@ -1,3 +0,0 @@
1
- declare function AppNavigationContainer(): import("react/jsx-runtime").JSX.Element;
2
- export default AppNavigationContainer;
3
- //# sourceMappingURL=AppNavigationContainer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AppNavigationContainer.d.ts","sourceRoot":"","sources":["../../../../example/src/AppNavigationContainer.tsx"],"names":[],"mappings":"AAOA,iBAAS,sBAAsB,4CA8B9B;AAED,eAAe,sBAAsB,CAAC"}
@@ -1,3 +0,0 @@
1
- declare function Explore(): import("react/jsx-runtime").JSX.Element;
2
- export default Explore;
3
- //# sourceMappingURL=Explore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Explore.d.ts","sourceRoot":"","sources":["../../../../../example/src/screens/Explore.tsx"],"names":[],"mappings":"AASA,iBAAS,OAAO,4CAwCf;AAED,eAAe,OAAO,CAAC"}
@@ -1,3 +0,0 @@
1
- declare function Home(): import("react/jsx-runtime").JSX.Element;
2
- export default Home;
3
- //# sourceMappingURL=Home.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../../../../example/src/screens/Home.tsx"],"names":[],"mappings":"AAOA,iBAAS,IAAI,4CAmHZ;AAED,eAAe,IAAI,CAAC"}
@@ -1,3 +0,0 @@
1
- declare function InnerExplore(): import("react/jsx-runtime").JSX.Element;
2
- export default InnerExplore;
3
- //# sourceMappingURL=InnerExplore.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InnerExplore.d.ts","sourceRoot":"","sources":["../../../../../example/src/screens/InnerExplore.tsx"],"names":[],"mappings":"AAMA,iBAAS,YAAY,4CAkBpB;AAED,eAAe,YAAY,CAAC"}
@@ -1,51 +0,0 @@
1
- export declare const homepageStyle: {
2
- container: {
3
- flexGrow: number;
4
- padding: number;
5
- };
6
- marginBottom: {
7
- marginBottom: number;
8
- };
9
- buttonsContainer: {
10
- flex: number;
11
- justifyContent: "center";
12
- };
13
- text: {
14
- color: string;
15
- };
16
- };
17
- export declare const exploreStyle: {
18
- container: {
19
- flexGrow: number;
20
- padding: number;
21
- };
22
- marginBottom: {
23
- marginBottom: number;
24
- };
25
- text: {
26
- color: string;
27
- };
28
- body: {
29
- flex: number;
30
- justifyContent: "center";
31
- alignItems: "center";
32
- };
33
- };
34
- export declare const innerExploreStyle: {
35
- container: {
36
- flexGrow: number;
37
- padding: number;
38
- };
39
- marginBottom: {
40
- marginBottom: number;
41
- };
42
- text: {
43
- color: string;
44
- };
45
- body: {
46
- flex: number;
47
- justifyContent: "center";
48
- alignItems: "center";
49
- };
50
- };
51
- //# sourceMappingURL=styles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../../example/src/screens/styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;CAexB,CAAC;AAEH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;CASvB,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;CAE5B,CAAC"}
@@ -1,17 +0,0 @@
1
- import type { TurboModule } from 'react-native';
2
- export interface Spec extends TurboModule {
3
- getInterfaceOrientation(): Promise<number>;
4
- getDeviceOrientation(): Promise<number>;
5
- lockTo(orientation: number): void;
6
- unlock(): void;
7
- isLocked(): boolean;
8
- resetSupportedInterfaceOrientations(): void;
9
- isAutoRotationEnabled(): boolean;
10
- enableOrientationSensors(): void;
11
- disableOrientationSensors(): void;
12
- addListener: (eventType: string) => void;
13
- removeListeners: (count: number) => void;
14
- }
15
- declare const _default: Spec;
16
- export default _default;
17
- //# sourceMappingURL=NativeOrientationDirector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NativeOrientationDirector.d.ts","sourceRoot":"","sources":["../../../module/NativeOrientationDirector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,MAAM,IAAI,IAAI,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC;IACpB,mCAAmC,IAAI,IAAI,CAAC;IAO5C,qBAAqB,IAAI,OAAO,CAAC;IACjC,wBAAwB,IAAI,IAAI,CAAC;IACjC,yBAAyB,IAAI,IAAI,CAAC;IAKlC,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;;AAED,wBAA6E"}