@tenthdart/react-native-nitro-orientation-locker 0.0.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/NitroOrientationLocker.podspec +30 -0
  3. package/README.md +98 -0
  4. package/android/CMakeLists.txt +13 -0
  5. package/android/build.gradle +138 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/src/main/AndroidManifest.xml +1 -0
  8. package/android/src/main/java/com/margelo/nitro/orientationlocker/HybridOrientationLocker.kt +99 -0
  9. package/ios/HybridOrientationLocker.swift +118 -0
  10. package/ios/OrientationGate.swift +22 -0
  11. package/lib/commonjs/OrientationLocker.nitro.js +6 -0
  12. package/lib/commonjs/OrientationLocker.nitro.js.map +1 -0
  13. package/lib/commonjs/OrientationLockerProvider.js +25 -0
  14. package/lib/commonjs/OrientationLockerProvider.js.map +1 -0
  15. package/lib/commonjs/index.js +33 -0
  16. package/lib/commonjs/index.js.map +1 -0
  17. package/lib/commonjs/package.json +1 -0
  18. package/lib/module/OrientationLocker.nitro.js +4 -0
  19. package/lib/module/OrientationLocker.nitro.js.map +1 -0
  20. package/lib/module/OrientationLockerProvider.js +20 -0
  21. package/lib/module/OrientationLockerProvider.js.map +1 -0
  22. package/lib/module/index.js +23 -0
  23. package/lib/module/index.js.map +1 -0
  24. package/lib/typescript/OrientationLocker.nitro.d.ts +36 -0
  25. package/lib/typescript/OrientationLocker.nitro.d.ts.map +1 -0
  26. package/lib/typescript/OrientationLockerProvider.d.ts +12 -0
  27. package/lib/typescript/OrientationLockerProvider.d.ts.map +1 -0
  28. package/lib/typescript/index.d.ts +11 -0
  29. package/lib/typescript/index.d.ts.map +1 -0
  30. package/nitro.json +24 -0
  31. package/nitrogen/generated/.gitattributes +1 -0
  32. package/nitrogen/generated/android/NitroOrientationLocker+autolinking.cmake +81 -0
  33. package/nitrogen/generated/android/NitroOrientationLocker+autolinking.gradle +27 -0
  34. package/nitrogen/generated/android/NitroOrientationLockerOnLoad.cpp +54 -0
  35. package/nitrogen/generated/android/NitroOrientationLockerOnLoad.hpp +34 -0
  36. package/nitrogen/generated/android/c++/JHybridOrientationLockerSpec.cpp +71 -0
  37. package/nitrogen/generated/android/c++/JHybridOrientationLockerSpec.hpp +66 -0
  38. package/nitrogen/generated/android/c++/JOrientation.hpp +70 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/HybridOrientationLockerSpec.kt +68 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/NitroOrientationLockerOnLoad.kt +35 -0
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/Orientation.kt +27 -0
  42. package/nitrogen/generated/ios/NitroOrientationLocker+autolinking.rb +62 -0
  43. package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.cpp +33 -0
  44. package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.hpp +51 -0
  45. package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Umbrella.hpp +46 -0
  46. package/nitrogen/generated/ios/NitroOrientationLockerAutolinking.mm +33 -0
  47. package/nitrogen/generated/ios/NitroOrientationLockerAutolinking.swift +26 -0
  48. package/nitrogen/generated/ios/c++/HybridOrientationLockerSpecSwift.cpp +11 -0
  49. package/nitrogen/generated/ios/c++/HybridOrientationLockerSpecSwift.hpp +99 -0
  50. package/nitrogen/generated/ios/swift/HybridOrientationLockerSpec.swift +58 -0
  51. package/nitrogen/generated/ios/swift/HybridOrientationLockerSpec_cxx.swift +171 -0
  52. package/nitrogen/generated/ios/swift/Orientation.swift +56 -0
  53. package/nitrogen/generated/shared/c++/HybridOrientationLockerSpec.cpp +25 -0
  54. package/nitrogen/generated/shared/c++/HybridOrientationLockerSpec.hpp +66 -0
  55. package/nitrogen/generated/shared/c++/Orientation.hpp +92 -0
  56. package/package.json +103 -0
  57. package/react-native.config.js +8 -0
  58. package/src/OrientationLocker.nitro.ts +45 -0
  59. package/src/OrientationLockerProvider.tsx +26 -0
  60. package/src/index.ts +30 -0
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// HybridOrientationLockerSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridOrientationLockerSpec.hpp"
9
+
10
+ namespace margelo::nitro::orientationlocker {
11
+
12
+ void HybridOrientationLockerSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("isTablet", &HybridOrientationLockerSpec::getIsTablet);
18
+ prototype.registerHybridGetter("currentOrientation", &HybridOrientationLockerSpec::getCurrentOrientation);
19
+ prototype.registerHybridMethod("acquireLock", &HybridOrientationLockerSpec::acquireLock);
20
+ prototype.registerHybridMethod("releaseLock", &HybridOrientationLockerSpec::releaseLock);
21
+ prototype.registerHybridMethod("setLockTabletsToLandscape", &HybridOrientationLockerSpec::setLockTabletsToLandscape);
22
+ });
23
+ }
24
+
25
+ } // namespace margelo::nitro::orientationlocker
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// HybridOrientationLockerSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `Orientation` to properly resolve imports.
17
+ namespace margelo::nitro::orientationlocker { enum class Orientation; }
18
+
19
+ #include "Orientation.hpp"
20
+
21
+ namespace margelo::nitro::orientationlocker {
22
+
23
+ using namespace margelo::nitro;
24
+
25
+ /**
26
+ * An abstract base class for `OrientationLocker`
27
+ * Inherit this class to create instances of `HybridOrientationLockerSpec` in C++.
28
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
29
+ * @example
30
+ * ```cpp
31
+ * class HybridOrientationLocker: public HybridOrientationLockerSpec {
32
+ * public:
33
+ * HybridOrientationLocker(...): HybridObject(TAG) { ... }
34
+ * // ...
35
+ * };
36
+ * ```
37
+ */
38
+ class HybridOrientationLockerSpec: public virtual HybridObject {
39
+ public:
40
+ // Constructor
41
+ explicit HybridOrientationLockerSpec(): HybridObject(TAG) { }
42
+
43
+ // Destructor
44
+ ~HybridOrientationLockerSpec() override = default;
45
+
46
+ public:
47
+ // Properties
48
+ virtual bool getIsTablet() = 0;
49
+ virtual Orientation getCurrentOrientation() = 0;
50
+
51
+ public:
52
+ // Methods
53
+ virtual void acquireLock(Orientation orientation) = 0;
54
+ virtual void releaseLock() = 0;
55
+ virtual void setLockTabletsToLandscape(bool enabled) = 0;
56
+
57
+ protected:
58
+ // Hybrid Setup
59
+ void loadHybridMethods() override;
60
+
61
+ protected:
62
+ // Tag for logging
63
+ static constexpr auto TAG = "OrientationLocker";
64
+ };
65
+
66
+ } // namespace margelo::nitro::orientationlocker
@@ -0,0 +1,92 @@
1
+ ///
2
+ /// Orientation.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::orientationlocker {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (Orientation).
30
+ */
31
+ enum class Orientation {
32
+ PORTRAIT SWIFT_NAME(portrait) = 0,
33
+ PORTRAIT_UPSIDE_DOWN SWIFT_NAME(portraitUpsideDown) = 1,
34
+ LANDSCAPE_LEFT SWIFT_NAME(landscapeLeft) = 2,
35
+ LANDSCAPE_RIGHT SWIFT_NAME(landscapeRight) = 3,
36
+ LANDSCAPE SWIFT_NAME(landscape) = 4,
37
+ ALL SWIFT_NAME(all) = 5,
38
+ } CLOSED_ENUM;
39
+
40
+ } // namespace margelo::nitro::orientationlocker
41
+
42
+ namespace margelo::nitro {
43
+
44
+ // C++ Orientation <> JS Orientation (union)
45
+ template <>
46
+ struct JSIConverter<margelo::nitro::orientationlocker::Orientation> final {
47
+ static inline margelo::nitro::orientationlocker::Orientation fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
48
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
49
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
50
+ case hashString("portrait"): return margelo::nitro::orientationlocker::Orientation::PORTRAIT;
51
+ case hashString("portrait-upside-down"): return margelo::nitro::orientationlocker::Orientation::PORTRAIT_UPSIDE_DOWN;
52
+ case hashString("landscape-left"): return margelo::nitro::orientationlocker::Orientation::LANDSCAPE_LEFT;
53
+ case hashString("landscape-right"): return margelo::nitro::orientationlocker::Orientation::LANDSCAPE_RIGHT;
54
+ case hashString("landscape"): return margelo::nitro::orientationlocker::Orientation::LANDSCAPE;
55
+ case hashString("all"): return margelo::nitro::orientationlocker::Orientation::ALL;
56
+ default: [[unlikely]]
57
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum Orientation - invalid value!");
58
+ }
59
+ }
60
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::orientationlocker::Orientation arg) {
61
+ switch (arg) {
62
+ case margelo::nitro::orientationlocker::Orientation::PORTRAIT: return JSIConverter<std::string>::toJSI(runtime, "portrait");
63
+ case margelo::nitro::orientationlocker::Orientation::PORTRAIT_UPSIDE_DOWN: return JSIConverter<std::string>::toJSI(runtime, "portrait-upside-down");
64
+ case margelo::nitro::orientationlocker::Orientation::LANDSCAPE_LEFT: return JSIConverter<std::string>::toJSI(runtime, "landscape-left");
65
+ case margelo::nitro::orientationlocker::Orientation::LANDSCAPE_RIGHT: return JSIConverter<std::string>::toJSI(runtime, "landscape-right");
66
+ case margelo::nitro::orientationlocker::Orientation::LANDSCAPE: return JSIConverter<std::string>::toJSI(runtime, "landscape");
67
+ case margelo::nitro::orientationlocker::Orientation::ALL: return JSIConverter<std::string>::toJSI(runtime, "all");
68
+ default: [[unlikely]]
69
+ throw std::invalid_argument("Cannot convert Orientation to JS - invalid value: "
70
+ + std::to_string(static_cast<int>(arg)) + "!");
71
+ }
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isString()) {
75
+ return false;
76
+ }
77
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
78
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
79
+ case hashString("portrait"):
80
+ case hashString("portrait-upside-down"):
81
+ case hashString("landscape-left"):
82
+ case hashString("landscape-right"):
83
+ case hashString("landscape"):
84
+ case hashString("all"):
85
+ return true;
86
+ default:
87
+ return false;
88
+ }
89
+ }
90
+ };
91
+
92
+ } // namespace margelo::nitro
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "@tenthdart/react-native-nitro-orientation-locker",
3
+ "version": "0.0.1",
4
+ "description": "High-performance Nitro module for locking screen orientation on React Native (New Architecture only).",
5
+ "main": "./lib/commonjs/index.js",
6
+ "module": "./lib/module/index.js",
7
+ "types": "./lib/typescript/index.d.ts",
8
+ "react-native": "./src/index.ts",
9
+ "source": "./src/index.ts",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "nitrogen/generated",
17
+ "NitroOrientationLocker.podspec",
18
+ "react-native.config.js",
19
+ "nitro.json",
20
+ "README.md",
21
+ "LICENSE",
22
+ "!**/.DS_Store",
23
+ "!**/__tests__",
24
+ "!**/__fixtures__",
25
+ "!**/__mocks__",
26
+ "!ios/build",
27
+ "!android/build",
28
+ "!android/.gradle",
29
+ "!android/.cxx",
30
+ "!**/*.tsbuildinfo"
31
+ ],
32
+ "scripts": {
33
+ "typecheck": "tsc --noEmit",
34
+ "specs": "nitrogen",
35
+ "clean": "rimraf lib nitrogen/generated",
36
+ "build": "bob build",
37
+ "prepare": "bob build",
38
+ "prepublishOnly": "bob build"
39
+ },
40
+ "keywords": [
41
+ "react-native",
42
+ "nitro",
43
+ "nitro-modules",
44
+ "orientation",
45
+ "orientation-locker",
46
+ "landscape",
47
+ "portrait",
48
+ "tablet",
49
+ "ios",
50
+ "android",
51
+ "visionos"
52
+ ],
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/tenthdart/react-native-nitro-orientation-locker.git"
56
+ },
57
+ "homepage": "https://github.com/tenthdart/react-native-nitro-orientation-locker#readme",
58
+ "bugs": {
59
+ "url": "https://github.com/tenthdart/react-native-nitro-orientation-locker/issues"
60
+ },
61
+ "author": {
62
+ "name": "Tenthdart",
63
+ "email": "ar.372920118@gmail.com",
64
+ "url": "https://github.com/tenthdart"
65
+ },
66
+ "license": "MIT",
67
+ "engines": {
68
+ "node": ">= 18.0.0"
69
+ },
70
+ "publishConfig": {
71
+ "registry": "https://registry.npmjs.org/",
72
+ "access": "public"
73
+ },
74
+ "peerDependencies": {
75
+ "react": "*",
76
+ "react-native": ">=0.76.0",
77
+ "react-native-nitro-modules": ">=0.22.0"
78
+ },
79
+ "devDependencies": {
80
+ "@types/react": "^19.0.0",
81
+ "nitrogen": "^0.35.0",
82
+ "react": "19.1.0",
83
+ "react-native": "0.81.0",
84
+ "react-native-builder-bob": "^0.40.0",
85
+ "react-native-nitro-modules": "^0.35.0",
86
+ "rimraf": "^6.0.1",
87
+ "typescript": "^5.6.0"
88
+ },
89
+ "react-native-builder-bob": {
90
+ "source": "src",
91
+ "output": "lib",
92
+ "targets": [
93
+ "commonjs",
94
+ "module",
95
+ [
96
+ "typescript",
97
+ {
98
+ "project": "tsconfig.build.json"
99
+ }
100
+ ]
101
+ ]
102
+ }
103
+ }
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ ios: {},
5
+ android: {},
6
+ },
7
+ },
8
+ };
@@ -0,0 +1,45 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+ export type Orientation =
4
+ | 'portrait'
5
+ | 'portrait-upside-down'
6
+ | 'landscape-left'
7
+ | 'landscape-right'
8
+ | 'landscape'
9
+ | 'all';
10
+
11
+ export interface OrientationLocker
12
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
13
+ /**
14
+ * True when the device's smallest width is >= 600dp (Android)
15
+ * or the user-interface idiom is .pad (iOS / visionOS).
16
+ */
17
+ readonly isTablet: boolean;
18
+
19
+ /**
20
+ * The current effective orientation of the interface.
21
+ */
22
+ readonly currentOrientation: Orientation;
23
+
24
+ /**
25
+ * Force a given orientation. Subsequent calls override the previous lock.
26
+ * On iOS 16+, this uses `requestGeometryUpdate`. On Android, it sets the
27
+ * Activity's requested orientation. The lock persists until `releaseLock`
28
+ * is called.
29
+ */
30
+ acquireLock(orientation: Orientation): void;
31
+
32
+ /**
33
+ * Release any active lock and return to the app's default supported
34
+ * orientations.
35
+ */
36
+ releaseLock(): void;
37
+
38
+ /**
39
+ * Enable or disable automatic landscape lock for tablets / large-width
40
+ * screens. When enabled and the device is a tablet, this acquires a
41
+ * landscape lock immediately. When disabled, any tablet-driven lock is
42
+ * released (manual locks set via `acquireLock` are untouched).
43
+ */
44
+ setLockTabletsToLandscape(enabled: boolean): void;
45
+ }
@@ -0,0 +1,26 @@
1
+ import React, { useEffect } from 'react';
2
+ import { OrientationLocker } from './index';
3
+
4
+ export interface OrientationLockerProviderProps {
5
+ /**
6
+ * When true, devices with `isTablet === true` (iPad / visionOS / Android
7
+ * `smallestScreenWidthDp >= 600`) are locked to landscape automatically
8
+ * while the provider is mounted. Phones are unaffected.
9
+ */
10
+ lockTabletsToLandscape?: boolean;
11
+ children?: React.ReactNode;
12
+ }
13
+
14
+ export function OrientationLockerProvider({
15
+ lockTabletsToLandscape = false,
16
+ children,
17
+ }: OrientationLockerProviderProps): React.ReactElement {
18
+ useEffect(() => {
19
+ OrientationLocker.setLockTabletsToLandscape(lockTabletsToLandscape);
20
+ return () => {
21
+ OrientationLocker.setLockTabletsToLandscape(false);
22
+ };
23
+ }, [lockTabletsToLandscape]);
24
+
25
+ return <>{children}</>;
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type {
3
+ OrientationLocker as OrientationLockerSpec,
4
+ Orientation,
5
+ } from './OrientationLocker.nitro';
6
+
7
+ export type { Orientation } from './OrientationLocker.nitro';
8
+
9
+ const OrientationLockerHybrid =
10
+ NitroModules.createHybridObject<OrientationLockerSpec>('OrientationLocker');
11
+
12
+ export const OrientationLocker = {
13
+ get isTablet(): boolean {
14
+ return OrientationLockerHybrid.isTablet;
15
+ },
16
+ get currentOrientation(): Orientation {
17
+ return OrientationLockerHybrid.currentOrientation;
18
+ },
19
+ acquireLock(orientation: Orientation): void {
20
+ OrientationLockerHybrid.acquireLock(orientation);
21
+ },
22
+ releaseLock(): void {
23
+ OrientationLockerHybrid.releaseLock();
24
+ },
25
+ setLockTabletsToLandscape(enabled: boolean): void {
26
+ OrientationLockerHybrid.setLockTabletsToLandscape(enabled);
27
+ },
28
+ };
29
+
30
+ export { OrientationLockerProvider } from './OrientationLockerProvider';