@applicaster/quick-brick-native-apple 5.20.4 → 5.20.6

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "QuickBrickApple",
3
- "version": "5.20.4",
3
+ "version": "5.20.6",
4
4
  "platforms": {
5
5
  "ios": "14.0",
6
6
  "tvos": "14.0"
@@ -16,7 +16,7 @@
16
16
  "authors": "Applicaster LTD.",
17
17
  "source": {
18
18
  "git": "https://github.com/applicaster/Zapp-Frameworks.git",
19
- "tag": "@@applicaster/quick-brick-native-apple/5.20.4"
19
+ "tag": "@@applicaster/quick-brick-native-apple/5.20.6"
20
20
  },
21
21
  "requires_arc": true,
22
22
  "source_files": "universal/**/*.{m,swift}",
@@ -0,0 +1,33 @@
1
+ //
2
+ // UIInterfaceOrientationMask+ReactNative.swift
3
+ // QuickBrickApple
4
+ //
5
+ // Created by Anton Kononenko on 10/11/22.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ extension UIInterfaceOrientationMask {
11
+ func toString() -> String {
12
+ switch self {
13
+ case .portrait:
14
+ return "portrait"
15
+ case .landscapeRight:
16
+ return "landscapeRight"
17
+ case .landscapeLeft:
18
+ return "landscapeLeft"
19
+ case .landscape:
20
+ return "landscape"
21
+ case .portraitUpsideDown:
22
+ return "portraitUpsideDown"
23
+ case .portrait:
24
+ return "portrait"
25
+ case .all:
26
+ return "all"
27
+ case .allButUpsideDown:
28
+ return "allButUpsideDown"
29
+ default:
30
+ return "all"
31
+ }
32
+ }
33
+ }
@@ -17,7 +17,6 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
17
17
  }
18
18
 
19
19
  lazy var logger = Logger.getLogger(for: QuickBrickViewControllerLogs.subsystem)
20
- var currentOrientation = UIDevice.current.orientation
21
20
 
22
21
  var orientationStack = [UIInterfaceOrientationMask.all]
23
22
  var orientationMask: UIInterfaceOrientationMask = QuickBrickViewController.initialOrientationMask
@@ -26,6 +25,10 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
26
25
  orientationMask
27
26
  }
28
27
 
28
+ override var prefersHomeIndicatorAutoHidden: Bool {
29
+ homeIndicatorAutoHidden
30
+ }
31
+
29
32
  override public var shouldAutorotate: Bool {
30
33
  true
31
34
  }
@@ -47,146 +50,150 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
47
50
  else {
48
51
  return false
49
52
  }
53
+
50
54
  return value.boolValue
51
55
  }
52
56
 
53
- /// Allow Orientation for specific screen
54
- ///
55
- /// - Parameters:
56
- /// - orientation: int value representing
57
- /// JS_PORTAIT = 1
58
- /// JS_LANDSCAPE = 1
59
- /// JS_LANDSCAPE_REVERSED = 4
60
- /// JS_PORTAIT_REVERSED = 8
61
- /// JS_LANDSCAPE_SENSOR = JS_LANDSCAPE | JS_LANDSCAPE_REVERSED
62
- /// JS_PORTAIT_SENSOR = JS_PORTAIT | JS_PORTAIT_REVERSED
63
- /// JS_FULL_SENSOR = JS_LANDSCAPE_SENSOR | JS_PORTAIT_SENSOR
64
- /// JS_SENSOR = JS_LANDSCAPE_SENSOR | JS_PORTAIT
65
- public func allowOrientationForScreen(_ orientation: Int) {
66
- orientationMask = mapOrientation(orientation)
57
+ var currentInterfaceOrientation: UIInterfaceOrientation = .unknown
58
+ func getUIOrientation() -> UIInterfaceOrientation {
59
+ guard let interfaceOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation else {
60
+ return .unknown
61
+ }
62
+ return interfaceOrientation
63
+ }
64
+
65
+ var currentDeviceOrientation: UIDeviceOrientation = .unknown
66
+ func getDeviceOrientation() -> UIDeviceOrientation {
67
+ UIDevice.current.orientation
68
+ }
69
+
70
+ public func allowOrientationForScreen(_ orientation: ReactNativeOrientation) {
71
+ orientationMask = orientation.toInterfaceOrientationMask()
72
+ // TODO: Remove orientation stack
67
73
  orientationStack.append(orientationMask)
68
- forceOrientationIfNeeded(orientationMask: orientationMask)
74
+ forceOrientationWithMaskIfNeeded(orientationMask)
69
75
  }
70
76
 
71
77
  /// Release Orientation for specific screen to previous state
72
78
  public func releaseOrientationForScreen() {
73
79
  if orientationStack.count > 1 {
74
80
  _ = orientationStack.dropLast()
75
- forceOrientationIfNeeded(orientationMask: orientationStack.last ?? UIInterfaceOrientationMask.all)
81
+ forceOrientationWithMaskIfNeeded(orientationStack.last ?? UIInterfaceOrientationMask.all)
76
82
  }
77
83
  }
78
84
 
79
- override func viewWillTransition(to _: CGSize, with _: UIViewControllerTransitionCoordinator) {
80
- ReactNativeEventEmitter.orientationChange(toOrientation: UIDevice.current.orientation, fromOrientation: currentOrientation)
81
- currentOrientation = UIDevice.current.orientation
85
+ override func viewWillTransition(to size: CGSize,
86
+ with coordinator: UIViewControllerTransitionCoordinator) {
87
+ super.viewWillTransition(to: size, with: coordinator)
88
+ let isLandscape = size.width > size.height
89
+ let interfaceOrientation = isLandscape ?
90
+ UIInterfaceOrientation.landscapeLeft :
91
+ UIInterfaceOrientation.portrait
92
+
93
+ let reactNativeToOrientation = ReactNativeOrientation.fromInterfaceOrientation(orientation: interfaceOrientation)
94
+ let reactNativefromOrientation = ReactNativeOrientation.fromInterfaceOrientation(orientation: currentInterfaceOrientation)
95
+ currentInterfaceOrientation = interfaceOrientation
96
+
97
+ ReactNativeEventEmitter.orientationChange(toOrientation: reactNativeToOrientation,
98
+ fromOrientation: reactNativefromOrientation)
99
+
100
+ logger?.debugLog(message: "viewWillTransition: interface orientation was changed to: \(interfaceOrientation.toString())",
101
+ category: QuickBrickViewControllerLogs.forceOrientation.category)
82
102
  }
83
103
 
84
104
  override func viewWillAppear(_ animated: Bool) {
85
105
  super.viewWillAppear(animated)
86
- currentOrientation = UIDevice.current.orientation
87
- }
88
-
89
- private func mapOrientation(_ orientation: Int) -> UIInterfaceOrientationMask {
90
- let JS_PORTAIT = 0x0000_0001
91
- let JS_LANDSCAPE = 0x0000_0002 // landscapeRight: 2,
92
- let JS_LANDSCAPE_REVERSED = 0x0000_0004
93
- let JS_PORTAIT_REVERSED = 0x0000_0008
94
- let JS_LANDSCAPE_SENSOR = JS_LANDSCAPE | JS_LANDSCAPE_REVERSED
95
- let JS_PORTAIT_SENSOR = JS_PORTAIT | JS_PORTAIT_REVERSED
96
- let JS_FULL_SENSOR = JS_LANDSCAPE_SENSOR | JS_PORTAIT_SENSOR
97
- let JS_SENSOR = JS_LANDSCAPE_SENSOR | JS_PORTAIT
98
-
99
- switch orientation {
100
- case JS_PORTAIT:
101
- return UIInterfaceOrientationMask.portrait
102
- case JS_LANDSCAPE:
103
- return UIInterfaceOrientationMask.landscapeRight
104
- case JS_LANDSCAPE_REVERSED:
105
- return UIInterfaceOrientationMask.landscapeLeft
106
- case JS_LANDSCAPE_SENSOR:
107
- return UIInterfaceOrientationMask.landscape
108
- case JS_PORTAIT_REVERSED:
109
- return UIInterfaceOrientationMask.portraitUpsideDown
110
- case JS_PORTAIT_SENSOR:
111
- return UIInterfaceOrientationMask.portrait
112
- case JS_FULL_SENSOR:
113
- return UIInterfaceOrientationMask.all
114
- case JS_SENSOR:
115
- return UIInterfaceOrientationMask.allButUpsideDown
116
- default:
117
- return UIInterfaceOrientationMask.all
106
+ UIDevice.current.beginGeneratingDeviceOrientationNotifications()
107
+ NotificationCenter.default.addObserver(self,
108
+ selector: #selector(deviceDidRotate(notification:)),
109
+ name: UIDevice.orientationDidChangeNotification,
110
+ object: nil)
111
+ }
112
+
113
+ override func viewDidAppear(_ animated: Bool) {
114
+ super.viewDidAppear(animated)
115
+ // Initial device orientation
116
+ currentDeviceOrientation = getDeviceOrientation()
117
+ currentInterfaceOrientation = getUIOrientation()
118
+ }
119
+
120
+ override func viewWillDisappear(_ animated: Bool) {
121
+ super.viewWillDisappear(animated)
122
+ NotificationCenter.default.removeObserver(self)
123
+ if UIDevice.current.isGeneratingDeviceOrientationNotifications {
124
+ UIDevice.current.endGeneratingDeviceOrientationNotifications()
118
125
  }
119
126
  }
120
127
 
121
- private func mapOrientationMask(_ orientationMask: UIInterfaceOrientationMask) -> UIInterfaceOrientation {
122
- switch orientationMask {
123
- case UIInterfaceOrientationMask.portrait:
124
- return UIInterfaceOrientation.portrait
125
- case UIInterfaceOrientationMask.landscape:
126
- return UIInterfaceOrientation.landscapeRight
127
- case UIInterfaceOrientationMask.landscapeRight:
128
- return UIInterfaceOrientation.landscapeRight
129
- case UIInterfaceOrientationMask.landscapeLeft:
130
- return UIInterfaceOrientation.landscapeLeft
131
- case UIInterfaceOrientationMask.all:
132
- return UIInterfaceOrientation.portrait
133
- case UIInterfaceOrientationMask.allButUpsideDown:
134
- return UIInterfaceOrientation.portrait
135
- case UIInterfaceOrientationMask.portraitUpsideDown:
136
- return UIInterfaceOrientation.portraitUpsideDown
137
- default:
138
- return UIInterfaceOrientation.portrait
128
+ @objc func deviceDidRotate(notification _: NSNotification) {
129
+ let deviceOrientation = getDeviceOrientation()
130
+
131
+ // In this cases we does not want to send notifications
132
+ if deviceOrientation == .unknown ||
133
+ deviceOrientation == .faceDown ||
134
+ deviceOrientation == .faceUp {
135
+ return
139
136
  }
137
+
138
+ let reactNativeToOrientation = ReactNativeOrientation.fromDeviceOrientation(orientation: deviceOrientation)
139
+ let reactNativeFromOrientation = ReactNativeOrientation.fromDeviceOrientation(orientation: currentDeviceOrientation)
140
+ currentDeviceOrientation = deviceOrientation
141
+
142
+ ReactNativeEventEmitter.orientationChange(toOrientation: reactNativeToOrientation,
143
+ fromOrientation: reactNativeFromOrientation,
144
+ physicalChange: true)
145
+
146
+ logger?.debugLog(message: "deviceDidRotate: device oritation changed to: \(deviceOrientation.toString())",
147
+ category: QuickBrickViewControllerLogs.forceOrientation.category)
140
148
  }
141
149
 
142
- private func forceOrientationIfNeeded(orientationMask: UIInterfaceOrientationMask) {
143
- switch orientationMask {
144
- case UIInterfaceOrientationMask.portrait:
145
- if !UIDevice.current.orientation.isPortrait {
146
- forceOrientation(UIInterfaceOrientation.portrait)
147
- }
148
- case UIInterfaceOrientationMask.landscape:
149
- if !UIDevice.current.orientation.isLandscape {
150
- let statusBarOrientation = UIApplication.shared.statusBarOrientation
151
- if statusBarOrientation == UIInterfaceOrientation.landscapeLeft {
152
- forceOrientation(UIInterfaceOrientation.landscapeLeft)
153
- } else {
154
- forceOrientation(UIInterfaceOrientation.landscapeRight)
155
- }
156
- }
157
- case UIInterfaceOrientationMask.landscapeRight:
158
- if UIDevice.current.orientation.rawValue != UIInterfaceOrientation.landscapeRight.rawValue {
159
- forceOrientation(UIInterfaceOrientation.landscapeRight)
160
- }
161
- case UIInterfaceOrientationMask.landscapeLeft:
162
- if UIDevice.current.orientation.rawValue != UIInterfaceOrientation.landscapeLeft.rawValue {
163
- forceOrientation(UIInterfaceOrientation.landscapeLeft)
164
- }
165
- case UIInterfaceOrientationMask.all:
166
- break
167
- case UIInterfaceOrientationMask.allButUpsideDown:
168
- if !UIDevice.current.orientation.isLandscape, UIDevice.current.orientation.rawValue != UIInterfaceOrientation.portrait.rawValue {
169
- forceOrientation(UIInterfaceOrientation.portrait)
170
- }
171
- case UIInterfaceOrientationMask.portraitUpsideDown:
172
- if UIDevice.current.orientation.rawValue != UIInterfaceOrientation.portraitUpsideDown.rawValue {
173
- forceOrientation(UIInterfaceOrientation.portraitUpsideDown)
174
- }
175
- default:
176
- break
150
+ private func forceOrientationWithMaskIfNeeded(_ orientationMask: UIInterfaceOrientationMask) {
151
+ if #available(iOS 16.0, *) {
152
+ logger?.debugLog(message: "\(QuickBrickViewControllerLogs.forceOrientation.message) UI orientation to: \(orientationMask.toString())",
153
+ category: QuickBrickViewControllerLogs.forceOrientation.category)
154
+
155
+ let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
156
+ windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask))
157
+ UIViewController.attemptRotationToDeviceOrientation()
158
+ return
177
159
  }
160
+
161
+ if isSupportOrientation(mask: orientationMask,
162
+ interfaceOrientation: currentInterfaceOrientation) {
163
+ return
164
+ }
165
+
166
+ logger?.debugLog(message: "\(QuickBrickViewControllerLogs.forceOrientation.message) UI orientation to: \(orientationMask.toString())",
167
+ category: QuickBrickViewControllerLogs.forceOrientation.category)
168
+
169
+ changeOrienation(orientationMask: orientationMask)
178
170
  }
179
171
 
180
- private func forceOrientation(_ orientation: UIInterfaceOrientation) {
181
- logger?.debugLog(message: QuickBrickViewControllerLogs.forceOrientation.message,
182
- category: QuickBrickViewControllerLogs.forceOrientation.category,
183
- data: ["orientation": "\(orientation.rawValue)"])
172
+ func changeOrienation(orientationMask: UIInterfaceOrientationMask) {
173
+ func setDeviceOrientation(_ orientaion: UIDeviceOrientation) {
174
+ UIDevice.current.setValue(orientaion.rawValue,
175
+ forKey: "orientation")
176
+ }
177
+
178
+ if orientationMask == .landscapeRight {
179
+ setDeviceOrientation(UIDeviceOrientation.landscapeLeft)
180
+ } else if orientationMask == .landscapeLeft {
181
+ setDeviceOrientation(UIDeviceOrientation.landscapeRight)
182
+ } else if orientationMask == .landscape {
183
+ if currentDeviceOrientation == .landscapeLeft || currentDeviceOrientation == .landscapeRight {
184
+ setDeviceOrientation(currentDeviceOrientation)
185
+ } else {
186
+ setDeviceOrientation(UIDeviceOrientation.landscapeRight)
187
+ }
188
+
189
+ } else if orientationMask == .portrait {
190
+ setDeviceOrientation(UIDeviceOrientation.portrait)
191
+ }
184
192
 
185
- UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
186
193
  UIViewController.attemptRotationToDeviceOrientation()
187
194
  }
188
195
 
189
- override var prefersHomeIndicatorAutoHidden: Bool {
190
- homeIndicatorAutoHidden
196
+ func isSupportOrientation(mask: UIInterfaceOrientationMask, interfaceOrientation: UIInterfaceOrientation) -> Bool {
197
+ (mask.rawValue & (1 << interfaceOrientation.rawValue)) != 0
191
198
  }
192
199
  }
@@ -2,7 +2,7 @@
2
2
  // ReactNativeEventEmitter.swift
3
3
  // QuickBrickApple
4
4
  //
5
- // Created by Pawel Buderaski on 24/08/2021.
5
+ // Created by Anton Kononenko on 10/11/2022.
6
6
  //
7
7
 
8
8
  import Foundation
@@ -12,9 +12,13 @@ import React
12
12
  open class ReactNativeEventEmitter: RCTEventEmitter {
13
13
  public static var emitter: RCTEventEmitter!
14
14
 
15
- public static func orientationChange(toOrientation: UIDeviceOrientation, fromOrientation: UIDeviceOrientation) {
15
+ public static func orientationChange(toOrientation: ReactNativeOrientation,
16
+ fromOrientation: ReactNativeOrientation,
17
+ physicalChange: Bool = false) {
16
18
  if toOrientation.rawValue > 0 {
17
- emitter.sendEvent(withName: "orientationChange", body: ["toOrientation": toOrientation.mapOrientation(), "fromOrientation": fromOrientation.mapOrientation()])
19
+ emitter?.sendEvent(withName: "orientationChange", body: ["toOrientation": toOrientation.rawValue,
20
+ "fromOrientation": fromOrientation.rawValue,
21
+ "physicalChange": physicalChange])
18
22
  }
19
23
  }
20
24
 
@@ -0,0 +1,71 @@
1
+ //
2
+ // ReactNativeOrientation.swift
3
+ // QuickBrickApple
4
+ //
5
+ // Created by Anna Bauza on 03/02/2020.
6
+ //
7
+
8
+ import UIKit
9
+ import ZappCore
10
+
11
+ public enum ReactNativeOrientation: Int {
12
+ case unknown = 0
13
+ case portrait = 1
14
+ case landscapeRight = 2
15
+ case landscapeLeft = 4
16
+ case portraitUpsideDown = 8
17
+ case landscape = 6
18
+ case all = 15
19
+ case allButUpsideDown = 7
20
+
21
+ static func fromInterfaceOrientation(orientation: UIInterfaceOrientation) -> ReactNativeOrientation {
22
+ switch orientation {
23
+ case .portrait:
24
+ return .portrait
25
+ case .landscapeLeft:
26
+ return .landscapeLeft
27
+ case .landscapeRight:
28
+ return .landscapeRight
29
+ case .portraitUpsideDown:
30
+ return .portraitUpsideDown
31
+ default:
32
+ return .unknown
33
+ }
34
+ }
35
+
36
+ static func fromDeviceOrientation(orientation: UIDeviceOrientation) -> ReactNativeOrientation {
37
+ switch orientation {
38
+ case .portrait:
39
+ return .portrait
40
+ case .landscapeLeft:
41
+ return .landscapeRight
42
+ case .landscapeRight:
43
+ return .landscapeLeft
44
+ case .portraitUpsideDown:
45
+ return .portraitUpsideDown
46
+ default:
47
+ return .unknown
48
+ }
49
+ }
50
+
51
+ func toInterfaceOrientationMask() -> UIInterfaceOrientationMask {
52
+ switch self {
53
+ case .portrait:
54
+ return .portrait
55
+ case .landscapeLeft:
56
+ return .landscapeLeft
57
+ case .landscapeRight:
58
+ return .landscapeRight
59
+ case .landscape:
60
+ return .landscape
61
+ case .portraitUpsideDown:
62
+ return .portraitUpsideDown
63
+ case .all:
64
+ return .all
65
+ case .allButUpsideDown:
66
+ return .allButUpsideDown
67
+ default:
68
+ return .portrait
69
+ }
70
+ }
71
+ }
@@ -200,8 +200,10 @@ extension ReactNativeManager: QuickBrickManagerDelegate {
200
200
  }
201
201
 
202
202
  public func allowOrientationForScreen(_ payload: [String: Any]) {
203
- if let qbViewController = reactNativeViewController() as? QuickBrickViewController, let orientation = payload["orientation"] as? Int {
204
- qbViewController.allowOrientationForScreen(orientation)
203
+ if let qbViewController = reactNativeViewController() as? QuickBrickViewController,
204
+ let orientation = payload["orientation"] as? Int,
205
+ let reactNativeOrientation = ReactNativeOrientation(rawValue: orientation) {
206
+ qbViewController.allowOrientationForScreen(reactNativeOrientation)
205
207
  }
206
208
  }
207
209
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-native-apple",
3
- "version": "5.20.4",
3
+ "version": "5.20.6",
4
4
  "description": "iOS and tvOS native code for QuickBrick applications. This package is used to provide native logic for QuickBrick",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,31 +0,0 @@
1
- //
2
- // UIDeviceOrientation+Extension.swift
3
- // QuickBrickApple
4
- //
5
- // Created by Anton Kononenko on 8/30/21.
6
- // Copyright © 2021 Anton Kononenko. All rights reserved.
7
- //
8
-
9
- import Foundation
10
- import React
11
-
12
- extension UIDeviceOrientation {
13
- func mapOrientation() -> Int {
14
- var orientation = 0
15
-
16
- switch self {
17
- case .portrait:
18
- orientation = 1
19
- case .landscapeRight:
20
- orientation = 2
21
- case .landscapeLeft:
22
- orientation = 4
23
- case .portraitUpsideDown:
24
- orientation = 8
25
- default:
26
- orientation = 0
27
- }
28
-
29
- return orientation
30
- }
31
- }