-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS landscape orientation code problems (#608)
^ALTAPPS-873
- Loading branch information
1 parent
58ca45b
commit 785846d
Showing
8 changed files
with
121 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 18 additions & 1 deletion
19
...llApp/iosHyperskillApp/Sources/Frameworks/WebController/WebViewNavigationController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
import UIKit | ||
|
||
final class WebViewNavigationController: UINavigationController {} | ||
final class WebViewNavigationController: UINavigationController { | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
// ALTAPPS-453: Fix iOS 16 Password AutoFill crash | ||
if #available(iOS 16.0, *) { | ||
InterfaceOrientationChangesPublisher.publishSupportedInterfaceOrientationsDidChange(to: .all) | ||
} | ||
} | ||
|
||
override func viewDidDisappear(_ animated: Bool) { | ||
super.viewDidDisappear(animated) | ||
|
||
if #available(iOS 16.0, *) { | ||
InterfaceOrientationChangesPublisher.publishSupportedInterfaceOrientationsResetToDefault() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...rskillApp/Sources/Systems/InterfaceOrientation/InterfaceOrientationChangesPublisher.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
|
||
enum InterfaceOrientationChangesPublisher { | ||
static func publishSupportedInterfaceOrientationsDidChange( | ||
to supportedInterfaceOrientations: UIInterfaceOrientationMask | ||
) { | ||
NotificationCenter.default.post( | ||
name: .supportedInterfaceOrientationsDidChange, | ||
object: supportedInterfaceOrientations | ||
) | ||
} | ||
|
||
static func publishSupportedInterfaceOrientationsResetToDefault() { | ||
NotificationCenter.default.post(name: .supportedInterfaceOrientationsResetToDefault, object: nil) | ||
} | ||
} | ||
|
||
extension NSNotification.Name { | ||
static let supportedInterfaceOrientationsDidChange = NSNotification.Name("SupportedInterfaceOrientationsDidChange") | ||
|
||
static let supportedInterfaceOrientationsResetToDefault = | ||
NSNotification.Name("SupportedInterfaceOrientationsResetToDefault") | ||
} |
42 changes: 42 additions & 0 deletions
42
...p/iosHyperskillApp/Sources/Systems/InterfaceOrientation/InterfaceOrientationManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
final class InterfaceOrientationManager { | ||
private(set) var supportedInterfaceOrientations: UIInterfaceOrientationMask | ||
private let defaultSupportedInterfaceOrientations: UIInterfaceOrientationMask | ||
|
||
init(device: UIDevice = .current) { | ||
let defaultOrientations: UIInterfaceOrientationMask = device.userInterfaceIdiom == .phone ? .portrait : .all | ||
|
||
self.supportedInterfaceOrientations = defaultOrientations | ||
self.defaultSupportedInterfaceOrientations = defaultOrientations | ||
|
||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(handleSupportedInterfaceOrientationsDidChange(_:)), | ||
name: .supportedInterfaceOrientationsDidChange, | ||
object: nil | ||
) | ||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(handleSupportedInterfaceOrientationsResetToDefault), | ||
name: .supportedInterfaceOrientationsResetToDefault, | ||
object: nil | ||
) | ||
} | ||
|
||
@objc | ||
private func handleSupportedInterfaceOrientationsDidChange(_ notification: Foundation.Notification) { | ||
guard let newSupportedInterfaceOrientations = notification.object as? UIInterfaceOrientationMask else { | ||
return | ||
} | ||
|
||
supportedInterfaceOrientations = newSupportedInterfaceOrientations | ||
} | ||
|
||
@objc | ||
private func handleSupportedInterfaceOrientationsResetToDefault() { | ||
supportedInterfaceOrientations = defaultSupportedInterfaceOrientations | ||
UIViewController.attemptRotationToDeviceOrientation() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...erskillApp/Sources/Systems/InterfaceOrientation/View+SupportedInterfaceOrientations.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import SwiftUI | ||
|
||
extension View { | ||
func supportedInterfaceOrientations(_ supportedInterfaceOrientations: UIInterfaceOrientationMask) -> some View { | ||
onAppear { | ||
InterfaceOrientationChangesPublisher | ||
.publishSupportedInterfaceOrientationsDidChange(to: supportedInterfaceOrientations) | ||
} | ||
.onDisappear { | ||
InterfaceOrientationChangesPublisher.publishSupportedInterfaceOrientationsResetToDefault() | ||
} | ||
} | ||
} |