Skip to content

Commit abcbafa

Browse files
authored
feat(ios)!: emit CAPBridgeViewController notifications (#8211)
1 parent a0e713a commit abcbafa

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

ios/Capacitor/Capacitor/CAPBridgeViewController.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,7 @@ import Cordova
2727
return false
2828
}()
2929

30-
// TODO: Remove in Capacitor 8 after moving status bar plugin extensions code
31-
@objc func handleViewDidAppear() {
32-
if bridge?.config.hasInitialFocus ?? true {
33-
self.webView?.becomeFirstResponder()
34-
}
35-
}
36-
37-
deinit {
38-
NotificationCenter.default.removeObserver(self)
39-
}
40-
4130
override public final func loadView() {
42-
NotificationCenter.default.addObserver(self, selector: #selector(self.handleViewDidAppear), name: Notification.Name(rawValue: "CapacitorViewDidAppear"), object: nil)
4331
// load the configuration and set the logging flag
4432
let configDescriptor = instanceDescriptor()
4533
let configuration = InstanceConfiguration(with: configDescriptor, isDebug: CapacitorBridge.isDevEnvironment)
@@ -76,11 +64,17 @@ import Cordova
7664

7765
override open func viewDidAppear(_ animated: Bool) {
7866
super.viewDidAppear(animated)
67+
NotificationCenter.default.post(Notification(name: .capacitorViewDidAppear))
7968
if bridge?.config.hasInitialFocus ?? true {
8069
self.webView?.becomeFirstResponder()
8170
}
8271
}
8372

73+
override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
74+
super.viewWillTransition(to: size, with: coordinator)
75+
NotificationCenter.default.post(Notification(name: .capacitorViewWillTransition))
76+
}
77+
8478
override open func canPerformUnwindSegueAction(_ action: Selector, from fromViewController: UIViewController, withSender sender: Any) -> Bool {
8579
return false
8680
}

ios/Capacitor/Capacitor/CAPNotifications.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extension Notification.Name {
1616
public static let capacitorDecidePolicyForNavigationAction =
1717
Notification.Name(rawValue: "CapacitorDecidePolicyForNavigationActionNotification")
1818
public static let capacitorStatusBarTapped = Notification.Name(rawValue: "CapacitorStatusBarTappedNotification")
19+
public static let capacitorViewDidAppear = Notification.Name(rawValue: "CapacitorViewDidAppear")
20+
public static let capacitorViewWillTransition = Notification.Name(rawValue: "CapacitorViewWillTransition")
1921
}
2022

2123
@objc extension NSNotification {
@@ -26,6 +28,8 @@ extension Notification.Name {
2628
public static let capacitorDidFailToRegisterForRemoteNotifications = Notification.Name.capacitorDidFailToRegisterForRemoteNotifications
2729
public static let capacitorDecidePolicyForNavigationAction = Notification.Name.capacitorDecidePolicyForNavigationAction
2830
public static let capacitorStatusBarTapped = Notification.Name.capacitorStatusBarTapped
31+
public static let capacitorViewDidAppear = Notification.Name.capacitorViewDidAppear
32+
public static let capacitorViewWillTransition = Notification.Name.capacitorViewWillTransition
2933
}
3034

3135
/**

0 commit comments

Comments
 (0)