Skip to content

Commit ce351f7

Browse files
authored
fix(iOS): wrong interface orientation value after reset (#15)
1 parent 0e9c382 commit ce351f7

1 file changed

Lines changed: 31 additions & 23 deletions

File tree

ios/implementation/OrientationDirectorImpl.swift

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,20 @@ import UIKit
7979
}
8080

8181
let supportedInterfaceOrientations = OrientationDirectorUtils.readSupportedInterfaceOrientationsFromBundle()
82-
guard let firstSupportedInterfaceOrientation = supportedInterfaceOrientations.first else {
82+
if (supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.portrait)) {
83+
self.updateLastInterfaceOrientation(value: Orientation.PORTRAIT)
84+
return
85+
}
86+
if (supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.landscapeRight)) {
87+
self.updateLastInterfaceOrientation(value: Orientation.LANDSCAPE_LEFT)
88+
return
89+
}
90+
if (supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.landscapeLeft)) {
91+
self.updateLastInterfaceOrientation(value: Orientation.LANDSCAPE_RIGHT)
8392
return
8493
}
8594

86-
let orientation = OrientationDirectorUtils.getOrientationFrom(mask: firstSupportedInterfaceOrientation)
87-
self.updateLastInterfaceOrientation(value: orientation)
95+
self.updateLastInterfaceOrientation(value: Orientation.PORTRAIT_UPSIDE_DOWN)
8896
}
8997

9098
private func initInitialSupportedInterfaceOrientations() -> UIInterfaceOrientationMask {
@@ -113,29 +121,25 @@ import UIKit
113121
private func requestInterfaceUpdateTo(mask: UIInterfaceOrientationMask) {
114122
self.supportedInterfaceOrientations = mask
115123

116-
DispatchQueue.main.async {
117-
if #available(iOS 16.0, *) {
118-
guard let window = OrientationDirectorUtils.getCurrentWindow() else {
119-
return
120-
}
124+
if #available(iOS 16.0, *) {
125+
let window = OrientationDirectorUtils.getCurrentWindow()
121126

122-
guard let rootViewController = window.rootViewController else {
123-
return
124-
}
127+
guard let rootViewController = window?.rootViewController else {
128+
return
129+
}
125130

126-
guard let windowScene = window.windowScene else {
127-
return
128-
}
131+
guard let windowScene = window?.windowScene else {
132+
return
133+
}
129134

130-
rootViewController.setNeedsUpdateOfSupportedInterfaceOrientations()
135+
rootViewController.setNeedsUpdateOfSupportedInterfaceOrientations()
131136

132-
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: mask)) { error in
133-
print("\(OrientationDirectorImpl.TAG) - requestGeometryUpdate error", error)
134-
}
135-
} else {
136-
UIDevice.current.setValue(mask.rawValue, forKey: "orientation")
137-
UIViewController.attemptRotationToDeviceOrientation()
137+
windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: mask)) { error in
138+
print("\(OrientationDirectorImpl.TAG) - requestGeometryUpdate error", error)
138139
}
140+
} else {
141+
UIDevice.current.setValue(mask.rawValue, forKey: "orientation")
142+
UIViewController.attemptRotationToDeviceOrientation()
139143
}
140144
}
141145

@@ -148,11 +152,15 @@ import UIKit
148152

149153
private func adaptInterfaceTo(deviceOrientation: Orientation) {
150154
if (isLocked) {
151-
return
155+
return
152156
}
153157

154158
if (lastInterfaceOrientation == deviceOrientation) {
155-
return
159+
return
160+
}
161+
162+
if (deviceOrientation == Orientation.FACE_UP || deviceOrientation == Orientation.FACE_DOWN) {
163+
return
156164
}
157165

158166
let deviceOrientationMask = OrientationDirectorUtils.getMaskFrom(orientation: deviceOrientation)

0 commit comments

Comments
 (0)