@tenthdart/react-native-nitro-orientation-locker 0.1.0
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/LICENSE +21 -0
- package/NitroOrientationLocker.podspec +30 -0
- package/README.md +98 -0
- package/android/CMakeLists.txt +13 -0
- package/android/build.gradle +138 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/margelo/nitro/orientationlocker/HybridOrientationLocker.kt +99 -0
- package/ios/HybridOrientationLocker.swift +118 -0
- package/ios/OrientationGate.swift +22 -0
- package/lib/commonjs/OrientationLocker.nitro.js +6 -0
- package/lib/commonjs/OrientationLocker.nitro.js.map +1 -0
- package/lib/commonjs/OrientationLockerProvider.js +25 -0
- package/lib/commonjs/OrientationLockerProvider.js.map +1 -0
- package/lib/commonjs/index.js +33 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/OrientationLocker.nitro.js +4 -0
- package/lib/module/OrientationLocker.nitro.js.map +1 -0
- package/lib/module/OrientationLockerProvider.js +20 -0
- package/lib/module/OrientationLockerProvider.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/OrientationLocker.nitro.d.ts +36 -0
- package/lib/typescript/OrientationLocker.nitro.d.ts.map +1 -0
- package/lib/typescript/OrientationLockerProvider.d.ts +12 -0
- package/lib/typescript/OrientationLockerProvider.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +11 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroOrientationLocker+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroOrientationLocker+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroOrientationLockerOnLoad.cpp +54 -0
- package/nitrogen/generated/android/NitroOrientationLockerOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JHybridOrientationLockerSpec.cpp +71 -0
- package/nitrogen/generated/android/c++/JHybridOrientationLockerSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JOrientation.hpp +70 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/HybridOrientationLockerSpec.kt +68 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/NitroOrientationLockerOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/orientationlocker/Orientation.kt +27 -0
- package/nitrogen/generated/ios/NitroOrientationLocker+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.cpp +33 -0
- package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Bridge.hpp +51 -0
- package/nitrogen/generated/ios/NitroOrientationLocker-Swift-Cxx-Umbrella.hpp +46 -0
- package/nitrogen/generated/ios/NitroOrientationLockerAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroOrientationLockerAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridOrientationLockerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridOrientationLockerSpecSwift.hpp +99 -0
- package/nitrogen/generated/ios/swift/HybridOrientationLockerSpec.swift +58 -0
- package/nitrogen/generated/ios/swift/HybridOrientationLockerSpec_cxx.swift +171 -0
- package/nitrogen/generated/ios/swift/Orientation.swift +56 -0
- package/nitrogen/generated/shared/c++/HybridOrientationLockerSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridOrientationLockerSpec.hpp +66 -0
- package/nitrogen/generated/shared/c++/Orientation.hpp +92 -0
- package/package.json +103 -0
- package/react-native.config.js +8 -0
- package/src/OrientationLocker.nitro.ts +45 -0
- package/src/OrientationLockerProvider.tsx +26 -0
- package/src/index.ts +30 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
const OrientationLockerHybrid = NitroModules.createHybridObject('OrientationLocker');
|
|
5
|
+
export const OrientationLocker = {
|
|
6
|
+
get isTablet() {
|
|
7
|
+
return OrientationLockerHybrid.isTablet;
|
|
8
|
+
},
|
|
9
|
+
get currentOrientation() {
|
|
10
|
+
return OrientationLockerHybrid.currentOrientation;
|
|
11
|
+
},
|
|
12
|
+
acquireLock(orientation) {
|
|
13
|
+
OrientationLockerHybrid.acquireLock(orientation);
|
|
14
|
+
},
|
|
15
|
+
releaseLock() {
|
|
16
|
+
OrientationLockerHybrid.releaseLock();
|
|
17
|
+
},
|
|
18
|
+
setLockTabletsToLandscape(enabled) {
|
|
19
|
+
OrientationLockerHybrid.setLockTabletsToLandscape(enabled);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export { OrientationLockerProvider } from './OrientationLockerProvider';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","OrientationLockerHybrid","createHybridObject","OrientationLocker","isTablet","currentOrientation","acquireLock","orientation","releaseLock","setLockTabletsToLandscape","enabled","OrientationLockerProvider"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAQzD,MAAMC,uBAAuB,GAC3BD,YAAY,CAACE,kBAAkB,CAAwB,mBAAmB,CAAC;AAE7E,OAAO,MAAMC,iBAAiB,GAAG;EAC/B,IAAIC,QAAQA,CAAA,EAAY;IACtB,OAAOH,uBAAuB,CAACG,QAAQ;EACzC,CAAC;EACD,IAAIC,kBAAkBA,CAAA,EAAgB;IACpC,OAAOJ,uBAAuB,CAACI,kBAAkB;EACnD,CAAC;EACDC,WAAWA,CAACC,WAAwB,EAAQ;IAC1CN,uBAAuB,CAACK,WAAW,CAACC,WAAW,CAAC;EAClD,CAAC;EACDC,WAAWA,CAAA,EAAS;IAClBP,uBAAuB,CAACO,WAAW,CAAC,CAAC;EACvC,CAAC;EACDC,yBAAyBA,CAACC,OAAgB,EAAQ;IAChDT,uBAAuB,CAACQ,yBAAyB,CAACC,OAAO,CAAC;EAC5D;AACF,CAAC;AAED,SAASC,yBAAyB,QAAQ,6BAA6B","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export type Orientation = 'portrait' | 'portrait-upside-down' | 'landscape-left' | 'landscape-right' | 'landscape' | 'all';
|
|
3
|
+
export interface OrientationLocker extends HybridObject<{
|
|
4
|
+
ios: 'swift';
|
|
5
|
+
android: 'kotlin';
|
|
6
|
+
}> {
|
|
7
|
+
/**
|
|
8
|
+
* True when the device's smallest width is >= 600dp (Android)
|
|
9
|
+
* or the user-interface idiom is .pad (iOS / visionOS).
|
|
10
|
+
*/
|
|
11
|
+
readonly isTablet: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The current effective orientation of the interface.
|
|
14
|
+
*/
|
|
15
|
+
readonly currentOrientation: Orientation;
|
|
16
|
+
/**
|
|
17
|
+
* Force a given orientation. Subsequent calls override the previous lock.
|
|
18
|
+
* On iOS 16+, this uses `requestGeometryUpdate`. On Android, it sets the
|
|
19
|
+
* Activity's requested orientation. The lock persists until `releaseLock`
|
|
20
|
+
* is called.
|
|
21
|
+
*/
|
|
22
|
+
acquireLock(orientation: Orientation): void;
|
|
23
|
+
/**
|
|
24
|
+
* Release any active lock and return to the app's default supported
|
|
25
|
+
* orientations.
|
|
26
|
+
*/
|
|
27
|
+
releaseLock(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Enable or disable automatic landscape lock for tablets / large-width
|
|
30
|
+
* screens. When enabled and the device is a tablet, this acquires a
|
|
31
|
+
* landscape lock immediately. When disabled, any tablet-driven lock is
|
|
32
|
+
* released (manual locks set via `acquireLock` are untouched).
|
|
33
|
+
*/
|
|
34
|
+
setLockTabletsToLandscape(enabled: boolean): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=OrientationLocker.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrientationLocker.nitro.d.ts","sourceRoot":"","sources":["../../src/OrientationLocker.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,sBAAsB,GACtB,gBAAgB,GAChB,iBAAiB,GACjB,WAAW,GACX,KAAK,CAAC;AAEV,MAAM,WAAW,iBACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,kBAAkB,EAAE,WAAW,CAAC;IAEzC;;;;;OAKG;IACH,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5C;;;OAGG;IACH,WAAW,IAAI,IAAI,CAAC;IAEpB;;;;;OAKG;IACH,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACnD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface OrientationLockerProviderProps {
|
|
3
|
+
/**
|
|
4
|
+
* When true, devices with `isTablet === true` (iPad / visionOS / Android
|
|
5
|
+
* `smallestScreenWidthDp >= 600`) are locked to landscape automatically
|
|
6
|
+
* while the provider is mounted. Phones are unaffected.
|
|
7
|
+
*/
|
|
8
|
+
lockTabletsToLandscape?: boolean;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare function OrientationLockerProvider({ lockTabletsToLandscape, children, }: OrientationLockerProviderProps): React.ReactElement;
|
|
12
|
+
//# sourceMappingURL=OrientationLockerProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OrientationLockerProvider.d.ts","sourceRoot":"","sources":["../../src/OrientationLockerProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAGzC,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,yBAAyB,CAAC,EACxC,sBAA8B,EAC9B,QAAQ,GACT,EAAE,8BAA8B,GAAG,KAAK,CAAC,YAAY,CASrD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Orientation } from './OrientationLocker.nitro';
|
|
2
|
+
export type { Orientation } from './OrientationLocker.nitro';
|
|
3
|
+
export declare const OrientationLocker: {
|
|
4
|
+
readonly isTablet: boolean;
|
|
5
|
+
readonly currentOrientation: Orientation;
|
|
6
|
+
acquireLock(orientation: Orientation): void;
|
|
7
|
+
releaseLock(): void;
|
|
8
|
+
setLockTabletsToLandscape(enabled: boolean): void;
|
|
9
|
+
};
|
|
10
|
+
export { OrientationLockerProvider } from './OrientationLockerProvider';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAEnC,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAK7D,eAAO,MAAM,iBAAiB;uBACZ,OAAO;iCAGG,WAAW;6BAGZ,WAAW,GAAG,IAAI;mBAG5B,IAAI;uCAGgB,OAAO,GAAG,IAAI;CAGlD,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://nitro.margelo.com/nitro.schema.json",
|
|
3
|
+
"cxxNamespace": ["orientationlocker"],
|
|
4
|
+
"ios": {
|
|
5
|
+
"iosModuleName": "NitroOrientationLocker"
|
|
6
|
+
},
|
|
7
|
+
"android": {
|
|
8
|
+
"androidNamespace": ["orientationlocker"],
|
|
9
|
+
"androidCxxLibName": "NitroOrientationLocker"
|
|
10
|
+
},
|
|
11
|
+
"autolinking": {
|
|
12
|
+
"OrientationLocker": {
|
|
13
|
+
"ios": {
|
|
14
|
+
"language": "swift",
|
|
15
|
+
"implementationClassName": "HybridOrientationLocker"
|
|
16
|
+
},
|
|
17
|
+
"android": {
|
|
18
|
+
"language": "kotlin",
|
|
19
|
+
"implementationClassName": "HybridOrientationLocker"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"ignorePaths": ["node_modules", "lib"]
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
** linguist-generated=true
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#
|
|
2
|
+
# NitroOrientationLocker+autolinking.cmake
|
|
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
|
+
# This is a CMake file that adds all files generated by Nitrogen
|
|
9
|
+
# to the current CMake project.
|
|
10
|
+
#
|
|
11
|
+
# To use it, add this to your CMakeLists.txt:
|
|
12
|
+
# ```cmake
|
|
13
|
+
# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroOrientationLocker+autolinking.cmake)
|
|
14
|
+
# ```
|
|
15
|
+
|
|
16
|
+
# Define a flag to check if we are building properly
|
|
17
|
+
add_definitions(-DBUILDING_NITROORIENTATIONLOCKER_WITH_GENERATED_CMAKE_PROJECT)
|
|
18
|
+
|
|
19
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
20
|
+
add_definitions(-DRN_SERIALIZABLE_STATE)
|
|
21
|
+
|
|
22
|
+
# Add all headers that were generated by Nitrogen
|
|
23
|
+
include_directories(
|
|
24
|
+
"../nitrogen/generated/shared/c++"
|
|
25
|
+
"../nitrogen/generated/android/c++"
|
|
26
|
+
"../nitrogen/generated/android/"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Add all .cpp sources that were generated by Nitrogen
|
|
30
|
+
target_sources(
|
|
31
|
+
# CMake project name (Android C++ library name)
|
|
32
|
+
NitroOrientationLocker PRIVATE
|
|
33
|
+
# Autolinking Setup
|
|
34
|
+
../nitrogen/generated/android/NitroOrientationLockerOnLoad.cpp
|
|
35
|
+
# Shared Nitrogen C++ sources
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridOrientationLockerSpec.cpp
|
|
37
|
+
# Android-specific Nitrogen C++ sources
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridOrientationLockerSpec.cpp
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
42
|
+
# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
|
|
43
|
+
target_compile_definitions(
|
|
44
|
+
NitroOrientationLocker PRIVATE
|
|
45
|
+
-DFOLLY_NO_CONFIG=1
|
|
46
|
+
-DFOLLY_HAVE_CLOCK_GETTIME=1
|
|
47
|
+
-DFOLLY_USE_LIBCPP=1
|
|
48
|
+
-DFOLLY_CFG_NO_COROUTINES=1
|
|
49
|
+
-DFOLLY_MOBILE=1
|
|
50
|
+
-DFOLLY_HAVE_RECVMMSG=1
|
|
51
|
+
-DFOLLY_HAVE_PTHREAD=1
|
|
52
|
+
# Once we target android-23 above, we can comment
|
|
53
|
+
# the following line. NDK uses GNU style stderror_r() after API 23.
|
|
54
|
+
-DFOLLY_HAVE_XSI_STRERROR_R=1
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Add all libraries required by the generated specs
|
|
58
|
+
find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
|
|
59
|
+
find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
|
|
60
|
+
find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
|
|
61
|
+
|
|
62
|
+
# Link all libraries together
|
|
63
|
+
target_link_libraries(
|
|
64
|
+
NitroOrientationLocker
|
|
65
|
+
fbjni::fbjni # <-- Facebook C++ JNI helpers
|
|
66
|
+
ReactAndroid::jsi # <-- RN: JSI
|
|
67
|
+
react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Link react-native (different prefab between RN 0.75 and RN 0.76)
|
|
71
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
72
|
+
target_link_libraries(
|
|
73
|
+
NitroOrientationLocker
|
|
74
|
+
ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
|
|
75
|
+
)
|
|
76
|
+
else()
|
|
77
|
+
target_link_libraries(
|
|
78
|
+
NitroOrientationLocker
|
|
79
|
+
ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
|
|
80
|
+
)
|
|
81
|
+
endif()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroOrientationLocker+autolinking.gradle
|
|
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
|
+
/// This is a Gradle file that adds all files generated by Nitrogen
|
|
9
|
+
/// to the current Gradle project.
|
|
10
|
+
///
|
|
11
|
+
/// To use it, add this to your build.gradle:
|
|
12
|
+
/// ```gradle
|
|
13
|
+
/// apply from: '../nitrogen/generated/android/NitroOrientationLocker+autolinking.gradle'
|
|
14
|
+
/// ```
|
|
15
|
+
|
|
16
|
+
logger.warn("[NitroModules] 🔥 NitroOrientationLocker is boosted by nitro!")
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
sourceSets {
|
|
20
|
+
main {
|
|
21
|
+
java.srcDirs += [
|
|
22
|
+
// Nitrogen files
|
|
23
|
+
"${project.projectDir}/../nitrogen/generated/android/kotlin"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroOrientationLockerOnLoad.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
|
+
#ifndef BUILDING_NITROORIENTATIONLOCKER_WITH_GENERATED_CMAKE_PROJECT
|
|
9
|
+
#error NitroOrientationLockerOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#include "NitroOrientationLockerOnLoad.hpp"
|
|
13
|
+
|
|
14
|
+
#include <jni.h>
|
|
15
|
+
#include <fbjni/fbjni.h>
|
|
16
|
+
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
|
+
|
|
18
|
+
#include "JHybridOrientationLockerSpec.hpp"
|
|
19
|
+
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
|
+
|
|
21
|
+
namespace margelo::nitro::orientationlocker {
|
|
22
|
+
|
|
23
|
+
int initialize(JavaVM* vm) {
|
|
24
|
+
return facebook::jni::initialize(vm, []() {
|
|
25
|
+
::margelo::nitro::orientationlocker::registerAllNatives();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
struct JHybridOrientationLockerSpecImpl: public jni::JavaClass<JHybridOrientationLockerSpecImpl, JHybridOrientationLockerSpec::JavaPart> {
|
|
30
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/orientationlocker/HybridOrientationLocker;";
|
|
31
|
+
static std::shared_ptr<JHybridOrientationLockerSpec> create() {
|
|
32
|
+
static const auto constructorFn = javaClassStatic()->getConstructor<JHybridOrientationLockerSpecImpl::javaobject()>();
|
|
33
|
+
jni::local_ref<JHybridOrientationLockerSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
34
|
+
return javaPart->getJHybridOrientationLockerSpec();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
void registerAllNatives() {
|
|
39
|
+
using namespace margelo::nitro;
|
|
40
|
+
using namespace margelo::nitro::orientationlocker;
|
|
41
|
+
|
|
42
|
+
// Register native JNI methods
|
|
43
|
+
margelo::nitro::orientationlocker::JHybridOrientationLockerSpec::CxxPart::registerNatives();
|
|
44
|
+
|
|
45
|
+
// Register Nitro Hybrid Objects
|
|
46
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
47
|
+
"OrientationLocker",
|
|
48
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
49
|
+
return JHybridOrientationLockerSpecImpl::create();
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
} // namespace margelo::nitro::orientationlocker
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroOrientationLockerOnLoad.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
|
+
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
10
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro::orientationlocker {
|
|
13
|
+
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the native (C++) part of NitroOrientationLocker, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
21
|
+
* Example:
|
|
22
|
+
* ```cpp (cpp-adapter.cpp)
|
|
23
|
+
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroOrientationLocker HybridObjects
|
|
26
|
+
* margelo::nitro::orientationlocker::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
void registerAllNatives();
|
|
33
|
+
|
|
34
|
+
} // namespace margelo::nitro::orientationlocker
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridOrientationLockerSpec.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 "JHybridOrientationLockerSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `Orientation` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::orientationlocker { enum class Orientation; }
|
|
12
|
+
|
|
13
|
+
#include "Orientation.hpp"
|
|
14
|
+
#include "JOrientation.hpp"
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::orientationlocker {
|
|
17
|
+
|
|
18
|
+
std::shared_ptr<JHybridOrientationLockerSpec> JHybridOrientationLockerSpec::JavaPart::getJHybridOrientationLockerSpec() {
|
|
19
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
20
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridOrientationLockerSpec>(hybridObject);
|
|
21
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
22
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridOrientationLockerSpec!");
|
|
23
|
+
}
|
|
24
|
+
return castHybridObject;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
jni::local_ref<JHybridOrientationLockerSpec::CxxPart::jhybriddata> JHybridOrientationLockerSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
28
|
+
return makeCxxInstance(jThis);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
std::shared_ptr<JHybridObject> JHybridOrientationLockerSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
32
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridOrientationLockerSpec::JavaPart>(javaPart);
|
|
33
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
34
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridOrientationLockerSpec::JavaPart!");
|
|
35
|
+
}
|
|
36
|
+
return std::make_shared<JHybridOrientationLockerSpec>(castJavaPart);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void JHybridOrientationLockerSpec::CxxPart::registerNatives() {
|
|
40
|
+
registerHybrid({
|
|
41
|
+
makeNativeMethod("initHybrid", JHybridOrientationLockerSpec::CxxPart::initHybrid),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Properties
|
|
46
|
+
bool JHybridOrientationLockerSpec::getIsTablet() {
|
|
47
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isTablet");
|
|
48
|
+
auto __result = method(_javaPart);
|
|
49
|
+
return static_cast<bool>(__result);
|
|
50
|
+
}
|
|
51
|
+
Orientation JHybridOrientationLockerSpec::getCurrentOrientation() {
|
|
52
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JOrientation>()>("getCurrentOrientation");
|
|
53
|
+
auto __result = method(_javaPart);
|
|
54
|
+
return __result->toCpp();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Methods
|
|
58
|
+
void JHybridOrientationLockerSpec::acquireLock(Orientation orientation) {
|
|
59
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JOrientation> /* orientation */)>("acquireLock");
|
|
60
|
+
method(_javaPart, JOrientation::fromCpp(orientation));
|
|
61
|
+
}
|
|
62
|
+
void JHybridOrientationLockerSpec::releaseLock() {
|
|
63
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("releaseLock");
|
|
64
|
+
method(_javaPart);
|
|
65
|
+
}
|
|
66
|
+
void JHybridOrientationLockerSpec::setLockTabletsToLandscape(bool enabled) {
|
|
67
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<void(jboolean /* enabled */)>("setLockTabletsToLandscape");
|
|
68
|
+
method(_javaPart, enabled);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} // 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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridOrientationLockerSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::orientationlocker {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridOrientationLockerSpec: public virtual HybridOrientationLockerSpec, public virtual JHybridObject {
|
|
22
|
+
public:
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/orientationlocker/HybridOrientationLockerSpec;";
|
|
25
|
+
std::shared_ptr<JHybridOrientationLockerSpec> getJHybridOrientationLockerSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/orientationlocker/HybridOrientationLockerSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
explicit JHybridOrientationLockerSpec(const jni::local_ref<JHybridOrientationLockerSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridOrientationLockerSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
41
|
+
~JHybridOrientationLockerSpec() override {
|
|
42
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
43
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridOrientationLockerSpec::JavaPart>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
bool getIsTablet() override;
|
|
54
|
+
Orientation getCurrentOrientation() override;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Methods
|
|
58
|
+
void acquireLock(Orientation orientation) override;
|
|
59
|
+
void releaseLock() override;
|
|
60
|
+
void setLockTabletsToLandscape(bool enabled) override;
|
|
61
|
+
|
|
62
|
+
private:
|
|
63
|
+
jni::global_ref<JHybridOrientationLockerSpec::JavaPart> _javaPart;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
} // namespace margelo::nitro::orientationlocker
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JOrientation.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "Orientation.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::orientationlocker {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "Orientation" and the the Kotlin enum "Orientation".
|
|
19
|
+
*/
|
|
20
|
+
struct JOrientation final: public jni::JavaClass<JOrientation> {
|
|
21
|
+
public:
|
|
22
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/orientationlocker/Orientation;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum Orientation.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
Orientation toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("value");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<Orientation>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JOrientation> fromCpp(Orientation value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
switch (value) {
|
|
45
|
+
case Orientation::PORTRAIT:
|
|
46
|
+
static const auto fieldPORTRAIT = clazz->getStaticField<JOrientation>("PORTRAIT");
|
|
47
|
+
return clazz->getStaticFieldValue(fieldPORTRAIT);
|
|
48
|
+
case Orientation::PORTRAIT_UPSIDE_DOWN:
|
|
49
|
+
static const auto fieldPORTRAIT_UPSIDE_DOWN = clazz->getStaticField<JOrientation>("PORTRAIT_UPSIDE_DOWN");
|
|
50
|
+
return clazz->getStaticFieldValue(fieldPORTRAIT_UPSIDE_DOWN);
|
|
51
|
+
case Orientation::LANDSCAPE_LEFT:
|
|
52
|
+
static const auto fieldLANDSCAPE_LEFT = clazz->getStaticField<JOrientation>("LANDSCAPE_LEFT");
|
|
53
|
+
return clazz->getStaticFieldValue(fieldLANDSCAPE_LEFT);
|
|
54
|
+
case Orientation::LANDSCAPE_RIGHT:
|
|
55
|
+
static const auto fieldLANDSCAPE_RIGHT = clazz->getStaticField<JOrientation>("LANDSCAPE_RIGHT");
|
|
56
|
+
return clazz->getStaticFieldValue(fieldLANDSCAPE_RIGHT);
|
|
57
|
+
case Orientation::LANDSCAPE:
|
|
58
|
+
static const auto fieldLANDSCAPE = clazz->getStaticField<JOrientation>("LANDSCAPE");
|
|
59
|
+
return clazz->getStaticFieldValue(fieldLANDSCAPE);
|
|
60
|
+
case Orientation::ALL:
|
|
61
|
+
static const auto fieldALL = clazz->getStaticField<JOrientation>("ALL");
|
|
62
|
+
return clazz->getStaticFieldValue(fieldALL);
|
|
63
|
+
default:
|
|
64
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
65
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
} // namespace margelo::nitro::orientationlocker
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridOrientationLockerSpec.kt
|
|
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
|
+
package com.margelo.nitro.orientationlocker
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.HybridObject
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A Kotlin class representing the OrientationLocker HybridObject.
|
|
17
|
+
* Implement this abstract class to create Kotlin-based instances of OrientationLocker.
|
|
18
|
+
*/
|
|
19
|
+
@DoNotStrip
|
|
20
|
+
@Keep
|
|
21
|
+
@Suppress(
|
|
22
|
+
"KotlinJniMissingFunction", "unused",
|
|
23
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
24
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
25
|
+
)
|
|
26
|
+
abstract class HybridOrientationLockerSpec: HybridObject() {
|
|
27
|
+
// Properties
|
|
28
|
+
@get:DoNotStrip
|
|
29
|
+
@get:Keep
|
|
30
|
+
abstract val isTablet: Boolean
|
|
31
|
+
|
|
32
|
+
@get:DoNotStrip
|
|
33
|
+
@get:Keep
|
|
34
|
+
abstract val currentOrientation: Orientation
|
|
35
|
+
|
|
36
|
+
// Methods
|
|
37
|
+
@DoNotStrip
|
|
38
|
+
@Keep
|
|
39
|
+
abstract fun acquireLock(orientation: Orientation): Unit
|
|
40
|
+
|
|
41
|
+
@DoNotStrip
|
|
42
|
+
@Keep
|
|
43
|
+
abstract fun releaseLock(): Unit
|
|
44
|
+
|
|
45
|
+
@DoNotStrip
|
|
46
|
+
@Keep
|
|
47
|
+
abstract fun setLockTabletsToLandscape(enabled: Boolean): Unit
|
|
48
|
+
|
|
49
|
+
// Default implementation of `HybridObject.toString()`
|
|
50
|
+
override fun toString(): String {
|
|
51
|
+
return "[HybridObject OrientationLocker]"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// C++ backing class
|
|
55
|
+
@DoNotStrip
|
|
56
|
+
@Keep
|
|
57
|
+
protected open class CxxPart(javaPart: HybridOrientationLockerSpec): HybridObject.CxxPart(javaPart) {
|
|
58
|
+
// C++ JHybridOrientationLockerSpec::CxxPart::initHybrid(...)
|
|
59
|
+
external override fun initHybrid(): HybridData
|
|
60
|
+
}
|
|
61
|
+
override fun createCxxPart(): CxxPart {
|
|
62
|
+
return CxxPart(this)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
companion object {
|
|
66
|
+
protected const val TAG = "HybridOrientationLockerSpec"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroOrientationLockerOnLoad.kt
|
|
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
|
+
package com.margelo.nitro.orientationlocker
|
|
9
|
+
|
|
10
|
+
import android.util.Log
|
|
11
|
+
|
|
12
|
+
internal class NitroOrientationLockerOnLoad {
|
|
13
|
+
companion object {
|
|
14
|
+
private const val TAG = "NitroOrientationLockerOnLoad"
|
|
15
|
+
private var didLoad = false
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the native part of "NitroOrientationLocker".
|
|
18
|
+
* This method is idempotent and can be called more than once.
|
|
19
|
+
*/
|
|
20
|
+
@JvmStatic
|
|
21
|
+
fun initializeNative() {
|
|
22
|
+
if (didLoad) return
|
|
23
|
+
try {
|
|
24
|
+
Log.i(TAG, "Loading NitroOrientationLocker C++ library...")
|
|
25
|
+
System.loadLibrary("NitroOrientationLocker")
|
|
26
|
+
Log.i(TAG, "Successfully loaded NitroOrientationLocker C++ library!")
|
|
27
|
+
didLoad = true
|
|
28
|
+
} catch (e: Error) {
|
|
29
|
+
Log.e(TAG, "Failed to load NitroOrientationLocker C++ library! Is it properly installed and linked? " +
|
|
30
|
+
"Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
|
|
31
|
+
throw e
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|