react-native-orientation-director 1.0.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 +20 -0
- package/README.md +87 -0
- package/android/build.gradle +120 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/orientationdirector/OrientationDirectorModule.kt +50 -0
- package/android/src/main/java/com/orientationdirector/OrientationDirectorPackage.kt +35 -0
- package/android/src/main/java/com/orientationdirector/implementation/Orientation.kt +12 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorImpl.kt +117 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorUtilsImpl.kt +65 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationEventManager.kt +42 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationLifecycleListener.kt +33 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationSensorListener.kt +26 -0
- package/android/src/newarch/OrientationDirectorSpec.kt +7 -0
- package/android/src/oldarch/OrientationDirectorSpec.kt +16 -0
- package/ios/OrientationDirector.h +22 -0
- package/ios/OrientationDirector.mm +121 -0
- package/ios/implementation/Orientation.swift +12 -0
- package/ios/implementation/OrientationDirectorImpl.swift +126 -0
- package/ios/implementation/OrientationDirectorUtils.swift +111 -0
- package/ios/implementation/OrientationEventManager.swift +56 -0
- package/ios/implementation/OrientationSensorListener.swift +37 -0
- package/ios/react-native-orientation-director-Bridging-Header.h +6 -0
- package/lib/commonjs/NativeOrientationDirector.js +9 -0
- package/lib/commonjs/NativeOrientationDirector.js.map +1 -0
- package/lib/commonjs/RNOrientationDirector.js +49 -0
- package/lib/commonjs/RNOrientationDirector.js.map +1 -0
- package/lib/commonjs/hooks/useDeviceOrientation.hook.js +39 -0
- package/lib/commonjs/hooks/useDeviceOrientation.hook.js.map +1 -0
- package/lib/commonjs/hooks/useInterfaceOrientation.hook.js +39 -0
- package/lib/commonjs/hooks/useInterfaceOrientation.hook.js.map +1 -0
- package/lib/commonjs/index.js +31 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/module.js +23 -0
- package/lib/commonjs/module.js.map +1 -0
- package/lib/commonjs/types/Event.enum.js +13 -0
- package/lib/commonjs/types/Event.enum.js.map +1 -0
- package/lib/commonjs/types/InterfaceOrientationToLocalizedStringProvider.type.js +6 -0
- package/lib/commonjs/types/InterfaceOrientationToLocalizedStringProvider.type.js.map +1 -0
- package/lib/commonjs/types/LockableOrientation.type.js +6 -0
- package/lib/commonjs/types/LockableOrientation.type.js.map +1 -0
- package/lib/commonjs/types/Orientation.enum.js +17 -0
- package/lib/commonjs/types/Orientation.enum.js.map +1 -0
- package/lib/commonjs/types/OrientationEvent.interface.js +6 -0
- package/lib/commonjs/types/OrientationEvent.interface.js.map +1 -0
- package/lib/module/NativeOrientationDirector.js +3 -0
- package/lib/module/NativeOrientationDirector.js.map +1 -0
- package/lib/module/RNOrientationDirector.js +40 -0
- package/lib/module/RNOrientationDirector.js.map +1 -0
- package/lib/module/hooks/useDeviceOrientation.hook.js +31 -0
- package/lib/module/hooks/useDeviceOrientation.hook.js.map +1 -0
- package/lib/module/hooks/useInterfaceOrientation.hook.js +31 -0
- package/lib/module/hooks/useInterfaceOrientation.hook.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/module.js +17 -0
- package/lib/module/module.js.map +1 -0
- package/lib/module/types/Event.enum.js +7 -0
- package/lib/module/types/Event.enum.js.map +1 -0
- package/lib/module/types/InterfaceOrientationToLocalizedStringProvider.type.js +2 -0
- package/lib/module/types/InterfaceOrientationToLocalizedStringProvider.type.js.map +1 -0
- package/lib/module/types/LockableOrientation.type.js +2 -0
- package/lib/module/types/LockableOrientation.type.js.map +1 -0
- package/lib/module/types/Orientation.enum.js +11 -0
- package/lib/module/types/Orientation.enum.js.map +1 -0
- package/lib/module/types/OrientationEvent.interface.js +2 -0
- package/lib/module/types/OrientationEvent.interface.js.map +1 -0
- package/lib/typescript/src/NativeOrientationDirector.d.ts +12 -0
- package/lib/typescript/src/NativeOrientationDirector.d.ts.map +1 -0
- package/lib/typescript/src/RNOrientationDirector.d.ts +17 -0
- package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useDeviceOrientation.hook.d.ts +8 -0
- package/lib/typescript/src/hooks/useDeviceOrientation.hook.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useInterfaceOrientation.hook.d.ts +8 -0
- package/lib/typescript/src/hooks/useInterfaceOrientation.hook.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/module.d.ts +6 -0
- package/lib/typescript/src/module.d.ts.map +1 -0
- package/lib/typescript/src/types/Event.enum.d.ts +6 -0
- package/lib/typescript/src/types/Event.enum.d.ts.map +1 -0
- package/lib/typescript/src/types/InterfaceOrientationToLocalizedStringProvider.type.d.ts +3 -0
- package/lib/typescript/src/types/InterfaceOrientationToLocalizedStringProvider.type.d.ts.map +1 -0
- package/lib/typescript/src/types/LockableOrientation.type.d.ts +3 -0
- package/lib/typescript/src/types/LockableOrientation.type.d.ts.map +1 -0
- package/lib/typescript/src/types/Orientation.enum.d.ts +10 -0
- package/lib/typescript/src/types/Orientation.enum.d.ts.map +1 -0
- package/lib/typescript/src/types/OrientationEvent.interface.d.ts +5 -0
- package/lib/typescript/src/types/OrientationEvent.interface.d.ts.map +1 -0
- package/package.json +178 -0
- package/react-native-orientation-director.podspec +41 -0
- package/src/NativeOrientationDirector.ts +14 -0
- package/src/RNOrientationDirector.ts +64 -0
- package/src/hooks/useDeviceOrientation.hook.ts +40 -0
- package/src/hooks/useInterfaceOrientation.hook.ts +40 -0
- package/src/index.tsx +10 -0
- package/src/module.ts +30 -0
- package/src/types/Event.enum.ts +6 -0
- package/src/types/InterfaceOrientationToLocalizedStringProvider.type.ts +6 -0
- package/src/types/LockableOrientation.type.ts +7 -0
- package/src/types/Orientation.enum.ts +11 -0
- package/src/types/OrientationEvent.interface.ts +5 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#import "OrientationDirector.h"
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This condition is needed to support use_frameworks.
|
|
5
|
+
https://github.com/callstack/react-native-builder-bob/discussions/412#discussioncomment-6352402
|
|
6
|
+
*/
|
|
7
|
+
#if __has_include("react_native_orientation_director-Swift.h")
|
|
8
|
+
#import "react_native_orientation_director-Swift.h"
|
|
9
|
+
#else
|
|
10
|
+
#import "react_native_orientation_director/react_native_orientation_director-Swift"
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
static OrientationDirectorImpl *_director = [OrientationDirectorImpl new];
|
|
14
|
+
|
|
15
|
+
///////////////////////////////////////////////////////////////////////////////////////
|
|
16
|
+
/// EVENT EMITTER SETUP
|
|
17
|
+
///https://github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/swift-event-emitter
|
|
18
|
+
@interface OrientationDirector() <OrientationEventEmitterDelegate>
|
|
19
|
+
@end
|
|
20
|
+
///
|
|
21
|
+
//////////////////////////////////////////////////////////////////////////////////////////
|
|
22
|
+
|
|
23
|
+
@implementation OrientationDirector
|
|
24
|
+
RCT_EXPORT_MODULE()
|
|
25
|
+
|
|
26
|
+
- (instancetype)init
|
|
27
|
+
{
|
|
28
|
+
self = [super init];
|
|
29
|
+
if (self) {
|
|
30
|
+
///////////////////////////////////////////////////////////////////////////////////////
|
|
31
|
+
/// EVENT EMITTER SETUP
|
|
32
|
+
[_director setEventManagerWithDelegate:self];
|
|
33
|
+
///
|
|
34
|
+
//////////////////////////////////////////////////////////////////////////////////////////
|
|
35
|
+
}
|
|
36
|
+
return self;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
///////////////////////////////////////////////////////////////////////////////////////
|
|
40
|
+
/// EVENT EMITTER SETUP
|
|
41
|
+
///
|
|
42
|
+
-(void)startObserving {
|
|
43
|
+
self.isJsListening = YES;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
-(void)stopObserving {
|
|
47
|
+
self.isJsListening = NO;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
51
|
+
return [OrientationEventManager supportedEvents];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void)sendEventWithName:(NSString * _Nonnull)name params:(NSDictionary *)params {
|
|
55
|
+
[self sendEventWithName:name body:params];
|
|
56
|
+
}
|
|
57
|
+
///
|
|
58
|
+
///////////////////////////////////////////////////////////////////////////////////////
|
|
59
|
+
|
|
60
|
+
+ (UIInterfaceOrientationMask)getSupportedInterfaceOrientationsForWindow
|
|
61
|
+
{
|
|
62
|
+
return [_director supportedInterfaceOrientation];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
66
|
+
- (void)getInterfaceOrientation:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
|
|
67
|
+
#else
|
|
68
|
+
RCT_EXPORT_METHOD(getInterfaceOrientation:(RCTPromiseResolveBlock)resolve
|
|
69
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
70
|
+
#endif
|
|
71
|
+
{
|
|
72
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
73
|
+
resolve(@([_director getInterfaceOrientation]));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
78
|
+
- (void)getDeviceOrientation:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject
|
|
79
|
+
#else
|
|
80
|
+
RCT_EXPORT_METHOD(getDeviceOrientation:(RCTPromiseResolveBlock)resolve
|
|
81
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
82
|
+
#endif
|
|
83
|
+
{
|
|
84
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
85
|
+
resolve(@([_director getDeviceOrientation]));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
90
|
+
- (void)lockTo:(double)jsOrientation
|
|
91
|
+
#else
|
|
92
|
+
RCT_EXPORT_METHOD(lockTo:(double)jsOrientation)
|
|
93
|
+
#endif
|
|
94
|
+
{
|
|
95
|
+
NSNumber *jsOrientationNumber = @(jsOrientation);
|
|
96
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
97
|
+
[_director lockToJsOrientation:jsOrientationNumber];
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
102
|
+
- (void)unlock
|
|
103
|
+
#else
|
|
104
|
+
RCT_EXPORT_METHOD(unlock)
|
|
105
|
+
#endif
|
|
106
|
+
{
|
|
107
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
108
|
+
[_director unlock];
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Don't compile this code when we build for the old architecture.
|
|
113
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
114
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
115
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
116
|
+
{
|
|
117
|
+
return std::make_shared<facebook::react::NativeOrientationDirectorSpecJSI>(params);
|
|
118
|
+
}
|
|
119
|
+
#endif
|
|
120
|
+
|
|
121
|
+
@end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Orientation.swift
|
|
3
|
+
// react-native-orientation-director
|
|
4
|
+
//
|
|
5
|
+
// Created by gladiuscode on 19/05/2024.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
@objc public enum Orientation: Int {
|
|
11
|
+
case UNKNOWN, PORTRAIT, LANDSCAPE_RIGHT, PORTRAIT_UPSIDE_DOWN, LANDSCAPE_LEFT, FACE_UP, FACE_DOWN
|
|
12
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//
|
|
2
|
+
// OrientationDirectorImpl.swift
|
|
3
|
+
// react-native-orientation-director
|
|
4
|
+
//
|
|
5
|
+
// Created by gladiuscode on 18/05/2024.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import UIKit
|
|
10
|
+
|
|
11
|
+
@objc public class OrientationDirectorImpl : NSObject {
|
|
12
|
+
private static let TAG = "OrientationDirectorImpl"
|
|
13
|
+
private let sensorListener: OrientationSensorListener
|
|
14
|
+
private let eventManager: OrientationEventManager
|
|
15
|
+
private var isLocked: Bool = false
|
|
16
|
+
private var lastInterfaceOrientation: Orientation = Orientation.UNKNOWN
|
|
17
|
+
private var lastDeviceOrientation: Orientation = Orientation.UNKNOWN
|
|
18
|
+
|
|
19
|
+
@objc public var supportedInterfaceOrientation: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
|
|
20
|
+
|
|
21
|
+
@objc public override init() {
|
|
22
|
+
eventManager = OrientationEventManager()
|
|
23
|
+
sensorListener = OrientationSensorListener()
|
|
24
|
+
super.init()
|
|
25
|
+
sensorListener.setOnOrientationChanged(callback: self.onOrientationChanged)
|
|
26
|
+
lastInterfaceOrientation = initInterfaceOrientation()
|
|
27
|
+
lastDeviceOrientation = initDeviceOrientation()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
///////////////////////////////////////////////////////////////////////////////////////
|
|
31
|
+
/// EVENT EMITTER SETUP
|
|
32
|
+
@objc public func setEventManager(delegate: OrientationEventEmitterDelegate) {
|
|
33
|
+
self.eventManager.delegate = delegate
|
|
34
|
+
}
|
|
35
|
+
///
|
|
36
|
+
//////////////////////////////////////////////////////////////////////////////////////////
|
|
37
|
+
|
|
38
|
+
@objc public func getInterfaceOrientation() -> Orientation {
|
|
39
|
+
return lastInterfaceOrientation
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@objc public func getDeviceOrientation() -> Orientation {
|
|
43
|
+
return lastDeviceOrientation
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@objc public func lockTo(jsOrientation: NSNumber) {
|
|
47
|
+
let orientation = OrientationDirectorUtils.getOrientationFrom(jsOrientation: jsOrientation)
|
|
48
|
+
let mask = OrientationDirectorUtils.getMaskFrom(orientation: orientation)
|
|
49
|
+
|
|
50
|
+
self.requestInterfaceUpdateTo(mask: mask)
|
|
51
|
+
|
|
52
|
+
eventManager.sendInterfaceOrientationDidChange(orientationValue: orientation.rawValue)
|
|
53
|
+
lastInterfaceOrientation = orientation
|
|
54
|
+
isLocked = true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@objc public func unlock() {
|
|
58
|
+
self.requestInterfaceUpdateTo(mask: UIInterfaceOrientationMask.all)
|
|
59
|
+
|
|
60
|
+
let deviceOrientation = OrientationDirectorUtils.getOrientationFrom(deviceOrientation: UIDevice.current.orientation)
|
|
61
|
+
isLocked = false
|
|
62
|
+
self.adaptInterfaceTo(deviceOrientation: deviceOrientation)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private func initInterfaceOrientation() -> Orientation {
|
|
66
|
+
let interfaceOrientation = OrientationDirectorUtils.getInterfaceOrientation()
|
|
67
|
+
return OrientationDirectorUtils.getOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private func initDeviceOrientation() -> Orientation {
|
|
71
|
+
return OrientationDirectorUtils.getOrientationFrom(deviceOrientation: UIDevice.current.orientation)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private func requestInterfaceUpdateTo(mask: UIInterfaceOrientationMask) {
|
|
75
|
+
self.supportedInterfaceOrientation = mask
|
|
76
|
+
|
|
77
|
+
DispatchQueue.main.async {
|
|
78
|
+
if #available(iOS 16.0, *) {
|
|
79
|
+
guard let window = OrientationDirectorUtils.getCurrentWindow() else {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
guard let rootViewController = window.rootViewController else {
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
guard let windowScene = window.windowScene else {
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
rootViewController.setNeedsUpdateOfSupportedInterfaceOrientations()
|
|
92
|
+
|
|
93
|
+
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: mask)) { error in
|
|
94
|
+
print("\(OrientationDirectorImpl.TAG) - requestGeometryUpdate error", error)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
UIDevice.current.setValue(mask.rawValue, forKey: "orientation")
|
|
98
|
+
UIViewController.attemptRotationToDeviceOrientation()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private func onOrientationChanged(uiDeviceOrientation: UIDeviceOrientation) {
|
|
104
|
+
let deviceOrientation = OrientationDirectorUtils.getOrientationFrom(deviceOrientation: uiDeviceOrientation)
|
|
105
|
+
self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
|
|
106
|
+
lastDeviceOrientation = deviceOrientation
|
|
107
|
+
adaptInterfaceTo(deviceOrientation: deviceOrientation)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private func adaptInterfaceTo(deviceOrientation: Orientation) {
|
|
111
|
+
if (isLocked) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (lastInterfaceOrientation == deviceOrientation) {
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (deviceOrientation == Orientation.FACE_UP || deviceOrientation == Orientation.FACE_DOWN) {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
self.eventManager.sendInterfaceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
|
|
124
|
+
lastInterfaceOrientation = deviceOrientation
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//
|
|
2
|
+
// OrientationDirectorUtils.swift
|
|
3
|
+
// react-native-orientation-director
|
|
4
|
+
//
|
|
5
|
+
// Created by gladiuscode on 18/05/2024.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
class OrientationDirectorUtils {
|
|
11
|
+
|
|
12
|
+
private static let TAG = "OrientationDirectorUtils"
|
|
13
|
+
|
|
14
|
+
public static func getOrientationFrom(uiInterfaceOrientation: UIInterfaceOrientation) -> Orientation {
|
|
15
|
+
var orientation = Orientation.UNKNOWN
|
|
16
|
+
|
|
17
|
+
switch(uiInterfaceOrientation) {
|
|
18
|
+
case UIInterfaceOrientation.landscapeRight: // Home button on the right
|
|
19
|
+
orientation = Orientation.LANDSCAPE_LEFT
|
|
20
|
+
case UIInterfaceOrientation.portraitUpsideDown:
|
|
21
|
+
orientation = Orientation.PORTRAIT_UPSIDE_DOWN
|
|
22
|
+
case UIInterfaceOrientation.landscapeLeft: // Home button on the left
|
|
23
|
+
orientation = Orientation.LANDSCAPE_RIGHT
|
|
24
|
+
default:
|
|
25
|
+
orientation = Orientation.PORTRAIT
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return orientation
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static func getOrientationFrom(deviceOrientation: UIDeviceOrientation) -> Orientation {
|
|
32
|
+
var orientation = Orientation.UNKNOWN
|
|
33
|
+
|
|
34
|
+
switch(deviceOrientation) {
|
|
35
|
+
case UIDeviceOrientation.landscapeRight:
|
|
36
|
+
orientation = Orientation.LANDSCAPE_RIGHT
|
|
37
|
+
case UIDeviceOrientation.portraitUpsideDown:
|
|
38
|
+
orientation = Orientation.PORTRAIT_UPSIDE_DOWN
|
|
39
|
+
case UIDeviceOrientation.landscapeLeft:
|
|
40
|
+
orientation = Orientation.LANDSCAPE_LEFT
|
|
41
|
+
case UIDeviceOrientation.faceUp:
|
|
42
|
+
orientation = Orientation.FACE_UP
|
|
43
|
+
case UIDeviceOrientation.faceDown:
|
|
44
|
+
orientation = Orientation.FACE_DOWN
|
|
45
|
+
default:
|
|
46
|
+
orientation = Orientation.PORTRAIT
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return orientation
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static func getOrientationFrom(jsOrientation: NSNumber) -> Orientation {
|
|
53
|
+
var orientation = Orientation.UNKNOWN
|
|
54
|
+
|
|
55
|
+
switch(jsOrientation) {
|
|
56
|
+
case 2:
|
|
57
|
+
orientation = Orientation.LANDSCAPE_RIGHT
|
|
58
|
+
case 3:
|
|
59
|
+
orientation = Orientation.PORTRAIT_UPSIDE_DOWN
|
|
60
|
+
case 4:
|
|
61
|
+
orientation = Orientation.LANDSCAPE_LEFT
|
|
62
|
+
default:
|
|
63
|
+
orientation = Orientation.PORTRAIT
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return orientation
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
Note: .portraitUpsideDown only works for devices with home button
|
|
71
|
+
//https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
|
|
72
|
+
*/
|
|
73
|
+
public static func getMaskFrom(orientation: Orientation) -> UIInterfaceOrientationMask {
|
|
74
|
+
var mask = UIInterfaceOrientationMask.portrait
|
|
75
|
+
|
|
76
|
+
switch(orientation) {
|
|
77
|
+
case Orientation.LANDSCAPE_RIGHT:
|
|
78
|
+
mask = UIInterfaceOrientationMask.landscapeLeft
|
|
79
|
+
case Orientation.PORTRAIT_UPSIDE_DOWN:
|
|
80
|
+
mask = UIInterfaceOrientationMask.portraitUpsideDown
|
|
81
|
+
case Orientation.LANDSCAPE_LEFT:
|
|
82
|
+
mask = UIInterfaceOrientationMask.landscapeRight
|
|
83
|
+
default:
|
|
84
|
+
mask = UIInterfaceOrientationMask.portrait
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return mask
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public static func getInterfaceOrientation() -> UIInterfaceOrientation {
|
|
91
|
+
guard let windowScene = self.getCurrentWindow()?.windowScene else {
|
|
92
|
+
return UIInterfaceOrientation.unknown
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return windowScene.interfaceOrientation;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* This function is needed to get the current available window.
|
|
99
|
+
Here in React Native we should have only one window tho.
|
|
100
|
+
https://stackoverflow.com/questions/57134259/how-to-resolve-keywindow-was-deprecated-in-ios-13-0/58031897#58031897
|
|
101
|
+
*/
|
|
102
|
+
public static func getCurrentWindow() -> UIWindow? {
|
|
103
|
+
return UIApplication
|
|
104
|
+
.shared
|
|
105
|
+
.connectedScenes
|
|
106
|
+
.compactMap { $0 as? UIWindowScene }
|
|
107
|
+
.flatMap { $0.windows }
|
|
108
|
+
.last { $0.isKeyWindow }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//
|
|
2
|
+
// OrientationEventEmitter.swift
|
|
3
|
+
// react-native-orientation-director
|
|
4
|
+
//
|
|
5
|
+
// Created by gladiuscode on 18/05/2024.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
@objc public class OrientationEventManager : NSObject {
|
|
11
|
+
@objc public weak var delegate: OrientationEventEmitterDelegate? = nil
|
|
12
|
+
|
|
13
|
+
func sendDeviceOrientationDidChange(orientationValue: Int) {
|
|
14
|
+
guard let delegate = delegate else {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!delegate.isJsListening) {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let params = Dictionary(dictionaryLiteral: ("orientation", orientationValue))
|
|
23
|
+
delegate.sendEvent(name: Event.DeviceOrientationDidChange.rawValue, params: params as NSDictionary)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func sendInterfaceOrientationDidChange(orientationValue: Int) {
|
|
27
|
+
guard let delegate = delegate else {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!delegate.isJsListening) {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let params = Dictionary(dictionaryLiteral: ("orientation", orientationValue))
|
|
36
|
+
delegate.sendEvent(name: Event.InterfaceOrientationDidChange.rawValue, params: params as NSDictionary)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@objc public protocol OrientationEventEmitterDelegate {
|
|
41
|
+
var isJsListening: Bool { get set }
|
|
42
|
+
|
|
43
|
+
func sendEvent(name: String, params: NSDictionary)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public extension OrientationEventManager {
|
|
47
|
+
|
|
48
|
+
enum Event: String, CaseIterable {
|
|
49
|
+
case DeviceOrientationDidChange
|
|
50
|
+
case InterfaceOrientationDidChange
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@objc static var supportedEvents: [String] {
|
|
54
|
+
return Event.allCases.map(\.rawValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//
|
|
2
|
+
// OrientationSensorListener.swift
|
|
3
|
+
// react-native-orientation-director
|
|
4
|
+
//
|
|
5
|
+
// Created by gladiuscode on 18/05/2024.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
public class OrientationSensorListener {
|
|
11
|
+
private var onOrientationChangedCallback: ((_ deviceOrientation: UIDeviceOrientation) -> Void)? = nil
|
|
12
|
+
|
|
13
|
+
init() {
|
|
14
|
+
NotificationCenter.default.addObserver(
|
|
15
|
+
self,
|
|
16
|
+
selector: #selector(orientationDidChange),
|
|
17
|
+
name: UIDevice.orientationDidChangeNotification,
|
|
18
|
+
object: nil
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
deinit {
|
|
23
|
+
NotificationCenter.default.removeObserver(self)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func setOnOrientationChanged(callback: @escaping (_ deviceOrientation: UIDeviceOrientation) -> Void) {
|
|
27
|
+
self.onOrientationChangedCallback = callback
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@objc func orientationDidChange(_ notification: Notification) {
|
|
31
|
+
guard let onOrientationChangedCallback = self.onOrientationChangedCallback else {
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
onOrientationChangedCallback(UIDevice.current.orientation)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('OrientationDirector');
|
|
9
|
+
//# sourceMappingURL=NativeOrientationDirector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeOrientationDirector.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAYpCC,gCAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _module = _interopRequireWildcard(require("./module"));
|
|
8
|
+
var _Event = _interopRequireDefault(require("./types/Event.enum"));
|
|
9
|
+
var _Orientation = require("./types/Orientation.enum");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
class RNOrientationDirector {
|
|
14
|
+
static _localizedStringProvider = {
|
|
15
|
+
[_Orientation.Orientation.unknown]: 'Unknown',
|
|
16
|
+
[_Orientation.Orientation.portrait]: 'Portrait',
|
|
17
|
+
[_Orientation.Orientation.portraitUpsideDown]: 'Portrait Upside Down',
|
|
18
|
+
[_Orientation.Orientation.landscapeLeft]: 'Landscape Left',
|
|
19
|
+
[_Orientation.Orientation.landscapeRight]: 'Landscape Right',
|
|
20
|
+
[_Orientation.Orientation.faceUp]: 'Face Up',
|
|
21
|
+
[_Orientation.Orientation.faceDown]: 'Face Down'
|
|
22
|
+
};
|
|
23
|
+
setLocalizedStringProvider(provider) {
|
|
24
|
+
RNOrientationDirector._localizedStringProvider = provider;
|
|
25
|
+
}
|
|
26
|
+
static getInterfaceOrientation() {
|
|
27
|
+
return _module.default.getInterfaceOrientation();
|
|
28
|
+
}
|
|
29
|
+
static getDeviceOrientation() {
|
|
30
|
+
return _module.default.getDeviceOrientation();
|
|
31
|
+
}
|
|
32
|
+
static lockTo(orientation) {
|
|
33
|
+
_module.default.lockTo(orientation);
|
|
34
|
+
}
|
|
35
|
+
static unlock() {
|
|
36
|
+
_module.default.unlock();
|
|
37
|
+
}
|
|
38
|
+
static listenForDeviceOrientationChanges(callback) {
|
|
39
|
+
return _module.EventEmitter.addListener(_Event.default.DeviceOrientationDidChange, callback);
|
|
40
|
+
}
|
|
41
|
+
static listenForInterfaceOrientationChanges(callback) {
|
|
42
|
+
return _module.EventEmitter.addListener(_Event.default.InterfaceOrientationDidChange, callback);
|
|
43
|
+
}
|
|
44
|
+
static convertOrientationToHumanReadableString(orientation) {
|
|
45
|
+
return RNOrientationDirector._localizedStringProvider[orientation];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var _default = exports.default = RNOrientationDirector;
|
|
49
|
+
//# sourceMappingURL=RNOrientationDirector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_module","_interopRequireWildcard","require","_Event","_interopRequireDefault","_Orientation","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","RNOrientationDirector","_localizedStringProvider","Orientation","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","setLocalizedStringProvider","provider","getInterfaceOrientation","Module","getDeviceOrientation","lockTo","orientation","unlock","listenForDeviceOrientationChanges","callback","EventEmitter","addListener","Event","DeviceOrientationDidChange","listenForInterfaceOrientationChanges","InterfaceOrientationDidChange","convertOrientationToHumanReadableString","_default","exports"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAAuD,SAAAE,uBAAAE,G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2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _RNOrientationDirector = _interopRequireDefault(require("../RNOrientationDirector"));
|
|
9
|
+
var _Orientation = require("../types/Orientation.enum");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
/**
|
|
14
|
+
* Hook that returns the current device orientation.
|
|
15
|
+
* It listens for orientation changes and updates the state accordingly.
|
|
16
|
+
*/
|
|
17
|
+
const useDeviceOrientation = () => {
|
|
18
|
+
const initialRender = (0, _react.useRef)(false);
|
|
19
|
+
const [orientation, setOrientation] = _react.default.useState(_Orientation.Orientation.unknown);
|
|
20
|
+
_react.default.useEffect(() => {
|
|
21
|
+
if (initialRender.current) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
initialRender.current = true;
|
|
25
|
+
_RNOrientationDirector.default.getDeviceOrientation().then(setOrientation);
|
|
26
|
+
}, []);
|
|
27
|
+
_react.default.useEffect(() => {
|
|
28
|
+
const onChange = event => {
|
|
29
|
+
setOrientation(event.orientation);
|
|
30
|
+
};
|
|
31
|
+
const subscription = _RNOrientationDirector.default.listenForDeviceOrientationChanges(onChange);
|
|
32
|
+
return () => {
|
|
33
|
+
subscription.remove();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
return orientation;
|
|
37
|
+
};
|
|
38
|
+
var _default = exports.default = useDeviceOrientation;
|
|
39
|
+
//# sourceMappingURL=useDeviceOrientation.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_RNOrientationDirector","_interopRequireDefault","_Orientation","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useDeviceOrientation","initialRender","useRef","orientation","setOrientation","React","useState","Orientation","unknown","useEffect","current","RNOrientationDirector","getDeviceOrientation","then","onChange","event","subscription","listenForDeviceOrientationChanges","remove","_default","exports"],"sourceRoot":"../../../src","sources":["hooks/useDeviceOrientation.hook.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAAwD,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAA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AAK;MAC5CX,cAAc,CAACW,KAAK,CAACZ,WAAW,CAAC;IACnC,CAAC;IAED,MAAMa,YAAY,GAChBL,8BAAqB,CAACM,iCAAiC,CAACH,QAAQ,CAAC;IACnE,OAAO,MAAM;MACXE,YAAY,CAACE,MAAM,CAAC,CAAC;IACvB,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOf,WAAW;AACpB,CAAC;AAAC,IAAAgB,QAAA,GAAAC,OAAA,CAAAvC,OAAA,GAEamB,oBAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _RNOrientationDirector = _interopRequireDefault(require("../RNOrientationDirector"));
|
|
9
|
+
var _Orientation = require("../types/Orientation.enum");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
/**
|
|
14
|
+
* Hook that returns the current interface orientation.
|
|
15
|
+
* It listens for orientation changes and updates the state accordingly.
|
|
16
|
+
*/
|
|
17
|
+
const useInterfaceOrientation = () => {
|
|
18
|
+
const initialRender = (0, _react.useRef)(false);
|
|
19
|
+
const [orientation, setOrientation] = _react.default.useState(_Orientation.Orientation.unknown);
|
|
20
|
+
_react.default.useEffect(() => {
|
|
21
|
+
if (initialRender.current) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
initialRender.current = true;
|
|
25
|
+
_RNOrientationDirector.default.getInterfaceOrientation().then(setOrientation);
|
|
26
|
+
}, []);
|
|
27
|
+
_react.default.useEffect(() => {
|
|
28
|
+
const onChange = event => {
|
|
29
|
+
setOrientation(event.orientation);
|
|
30
|
+
};
|
|
31
|
+
const subscription = _RNOrientationDirector.default.listenForInterfaceOrientationChanges(onChange);
|
|
32
|
+
return () => {
|
|
33
|
+
subscription.remove();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
return orientation;
|
|
37
|
+
};
|
|
38
|
+
var _default = exports.default = useInterfaceOrientation;
|
|
39
|
+
//# sourceMappingURL=useInterfaceOrientation.hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_RNOrientationDirector","_interopRequireDefault","_Orientation","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useInterfaceOrientation","initialRender","useRef","orientation","setOrientation","React","useState","Orientation","unknown","useEffect","current","RNOrientationDirector","getInterfaceOrientation","then","onChange","event","subscription","listenForInterfaceOrientationChanges","remove","_default","exports"],"sourceRoot":"../../../src","sources":["hooks/useInterfaceOrientation.hook.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AAAwD,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GA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