@applicaster/quick-brick-native-apple 5.20.3 → 5.20.5

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.3",
3
+ "version": "5.20.5",
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.3"
19
+ "tag": "@@applicaster/quick-brick-native-apple/5.20.5"
20
20
  },
21
21
  "requires_arc": true,
22
22
  "source_files": "universal/**/*.{m,swift}",
@@ -34,6 +34,7 @@
34
34
  "dependencies": {
35
35
  "ZappCore": [],
36
36
  "React": [],
37
+ "React-Core": [],
37
38
  "React-RCTLinking": [],
38
39
  "XrayLogger": []
39
40
  },
@@ -17,7 +17,7 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
17
17
  }
18
18
 
19
19
  lazy var logger = Logger.getLogger(for: QuickBrickViewControllerLogs.subsystem)
20
- var currentOrientation = UIDevice.current.orientation
20
+ var currentOrientation: UIDeviceOrientation = .unknown
21
21
 
22
22
  var orientationStack = [UIInterfaceOrientationMask.all]
23
23
  var orientationMask: UIInterfaceOrientationMask = QuickBrickViewController.initialOrientationMask
@@ -47,9 +47,45 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
47
47
  else {
48
48
  return false
49
49
  }
50
+
50
51
  return value.boolValue
51
52
  }
52
53
 
54
+ func getUIOrientation() -> UIInterfaceOrientation {
55
+ guard let interfaceOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation else {
56
+ return .unknown
57
+ }
58
+ return interfaceOrientation
59
+ }
60
+
61
+ func getUIOrientationMappedToDeviceOrientation() -> UIDeviceOrientation {
62
+ let interfaceOrientation = getUIOrientation()
63
+
64
+ switch interfaceOrientation {
65
+ case .landscapeLeft:
66
+ return .landscapeLeft
67
+ case .landscapeRight:
68
+ return .landscapeRight
69
+ case .portrait:
70
+ return .portrait
71
+ case .portraitUpsideDown:
72
+ return .portraitUpsideDown
73
+ default:
74
+ return .unknown
75
+ }
76
+ }
77
+
78
+ func getDeviceOrientation() -> UIDeviceOrientation {
79
+ let deviceOrientation = UIDevice.current.orientation
80
+ if deviceOrientation == .landscapeLeft {
81
+ return .landscapeRight
82
+ } else if deviceOrientation == .landscapeRight {
83
+ return .landscapeLeft
84
+ }
85
+
86
+ return deviceOrientation
87
+ }
88
+
53
89
  /// Allow Orientation for specific screen
54
90
  ///
55
91
  /// - Parameters:
@@ -76,16 +112,55 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
76
112
  }
77
113
  }
78
114
 
79
- override func viewWillTransition(to _: CGSize, with _: UIViewControllerTransitionCoordinator) {
80
- ReactNativeEventEmitter.orientationChange(toOrientation: UIDevice.current.orientation, fromOrientation: currentOrientation)
81
- currentOrientation = UIDevice.current.orientation
115
+ override func viewWillTransition(to _: CGSize,
116
+ with _: UIViewControllerTransitionCoordinator) {
117
+ let orientation = getUIOrientationMappedToDeviceOrientation()
118
+
119
+ ReactNativeEventEmitter.orientationChange(toOrientation: orientation,
120
+ fromOrientation: currentOrientation)
121
+ logger?.debugLog(message: "viewWillTransition: ui orientation was change to: \(orientation.toString())",
122
+ category: QuickBrickViewControllerLogs.forceOrientation.category)
82
123
  }
83
124
 
84
125
  override func viewWillAppear(_ animated: Bool) {
85
126
  super.viewWillAppear(animated)
127
+ UIDevice.current.beginGeneratingDeviceOrientationNotifications()
128
+ NotificationCenter.default.addObserver(self,
129
+ selector: #selector(deviceDidRotate(notification:)),
130
+ name: UIDevice.orientationDidChangeNotification,
131
+ object: nil)
132
+
133
+ // Initial device orientation
86
134
  currentOrientation = UIDevice.current.orientation
87
135
  }
88
136
 
137
+ override func viewWillDisappear(_ animated: Bool) {
138
+ super.viewWillDisappear(animated)
139
+ NotificationCenter.default.removeObserver(self)
140
+ if UIDevice.current.isGeneratingDeviceOrientationNotifications {
141
+ UIDevice.current.endGeneratingDeviceOrientationNotifications()
142
+ }
143
+ }
144
+
145
+ @objc func deviceDidRotate(notification _: NSNotification) {
146
+ let deviceOrientation = getDeviceOrientation()
147
+
148
+ // In this cases we does not want to send notifications
149
+ if deviceOrientation == .unknown ||
150
+ deviceOrientation == .faceDown ||
151
+ deviceOrientation == .faceUp {
152
+ return
153
+ }
154
+
155
+ ReactNativeEventEmitter.orientationChange(toOrientation: deviceOrientation,
156
+ fromOrientation: currentOrientation,
157
+ physicalChange: true)
158
+ logger?.debugLog(message: "deviceDidRotate: UI oritation changed to: \(getUIOrientation().toString())",
159
+ category: QuickBrickViewControllerLogs.forceOrientation.category)
160
+
161
+ currentOrientation = deviceOrientation
162
+ }
163
+
89
164
  private func mapOrientation(_ orientation: Int) -> UIInterfaceOrientationMask {
90
165
  let JS_PORTAIT = 0x0000_0001
91
166
  let JS_LANDSCAPE = 0x0000_0002 // landscapeRight: 2,
@@ -140,50 +215,46 @@ class QuickBrickViewController: UIViewController, UILayerViewControllerProtocol
140
215
  }
141
216
 
142
217
  private func forceOrientationIfNeeded(orientationMask: UIInterfaceOrientationMask) {
218
+ let interfaceOrientation = getUIOrientation()
143
219
  switch orientationMask {
144
220
  case UIInterfaceOrientationMask.portrait:
145
- if !UIDevice.current.orientation.isPortrait {
146
- forceOrientation(UIInterfaceOrientation.portrait)
147
- }
221
+ forceOrientation(UIInterfaceOrientation.portrait)
148
222
  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 {
223
+
224
+ if interfaceOrientation == .landscapeRight {
159
225
  forceOrientation(UIInterfaceOrientation.landscapeRight)
160
- }
161
- case UIInterfaceOrientationMask.landscapeLeft:
162
- if UIDevice.current.orientation.rawValue != UIInterfaceOrientation.landscapeLeft.rawValue {
226
+ } else {
163
227
  forceOrientation(UIInterfaceOrientation.landscapeLeft)
164
228
  }
229
+
230
+ case UIInterfaceOrientationMask.landscapeRight:
231
+ forceOrientation(UIInterfaceOrientation.landscapeRight)
232
+
233
+ case UIInterfaceOrientationMask.landscapeLeft:
234
+ forceOrientation(UIInterfaceOrientation.landscapeLeft)
235
+
165
236
  case UIInterfaceOrientationMask.all:
166
237
  break
167
238
  case UIInterfaceOrientationMask.allButUpsideDown:
168
- if !UIDevice.current.orientation.isLandscape, UIDevice.current.orientation.rawValue != UIInterfaceOrientation.portrait.rawValue {
169
- forceOrientation(UIInterfaceOrientation.portrait)
170
- }
239
+ forceOrientation(UIInterfaceOrientation.portrait)
240
+
171
241
  case UIInterfaceOrientationMask.portraitUpsideDown:
172
- if UIDevice.current.orientation.rawValue != UIInterfaceOrientation.portraitUpsideDown.rawValue {
173
- forceOrientation(UIInterfaceOrientation.portraitUpsideDown)
174
- }
242
+ forceOrientation(UIInterfaceOrientation.portraitUpsideDown)
175
243
  default:
176
244
  break
177
245
  }
178
246
  }
179
247
 
180
248
  private func forceOrientation(_ orientation: UIInterfaceOrientation) {
181
- logger?.debugLog(message: QuickBrickViewControllerLogs.forceOrientation.message,
182
- category: QuickBrickViewControllerLogs.forceOrientation.category,
183
- data: ["orientation": "\(orientation.rawValue)"])
184
-
185
- UIDevice.current.setValue(orientation.rawValue, forKey: "orientation")
186
- UIViewController.attemptRotationToDeviceOrientation()
249
+ if let newOrientation = UIDeviceOrientation(rawValue: orientation.rawValue) {
250
+ logger?.debugLog(message: "\(QuickBrickViewControllerLogs.forceOrientation.message) UI oritation to: \(orientation.toString())",
251
+ category: QuickBrickViewControllerLogs.forceOrientation.category,
252
+ data: ["newDeviceOrientation": newOrientation.toString(),
253
+ "newInterfaceOrientation": orientation.toString()])
254
+ UIDevice.current.setValue(newOrientation,
255
+ forKey: "orientation")
256
+ UIViewController.attemptRotationToDeviceOrientation()
257
+ }
187
258
  }
188
259
 
189
260
  override var prefersHomeIndicatorAutoHidden: Bool {
@@ -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: UIDeviceOrientation,
16
+ fromOrientation: UIDeviceOrientation,
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.mapOrientation(),
20
+ "fromOrientation": fromOrientation.mapOrientation(),
21
+ "physicalChange": physicalChange])
18
22
  }
19
23
  }
20
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-native-apple",
3
- "version": "5.20.3",
3
+ "version": "5.20.5",
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"