@nativue/core 0.15.3 → 0.15.4

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.
@@ -40,6 +40,21 @@ public final class NativueAppDelegate: NSObject, UIApplicationDelegate, UNUserNo
40
40
  /// Set by App.swift before any of the app's events.
41
41
  public static var plugins: [NativuePlugin] = []
42
42
 
43
+ /// iOS warns at every launch about a delegate handling remote notifications without the
44
+ /// remote-notification background mode: with no plugin listening and no mode, it doesn't handle them.
45
+ override public func responds(to selector: Selector!) -> Bool {
46
+ guard selector == Self.remoteNotificationSelector else { return super.responds(to: selector) }
47
+
48
+ let isListened = Self.plugins.contains { $0 is AppLifecycleListener }
49
+
50
+ return (isListened || Self.hasRemoteNotificationMode) && super.responds(to: selector)
51
+ }
52
+
53
+ private static let remoteNotificationSelector =
54
+ NSSelectorFromString("application:didReceiveRemoteNotification:fetchCompletionHandler:")
55
+ private static let hasRemoteNotificationMode =
56
+ (Bundle.main.object(forInfoDictionaryKey: "UIBackgroundModes") as? [String])?.contains("remote-notification") == true
57
+
43
58
  private var lifecycleListeners: [AppLifecycleListener] {
44
59
  Self.plugins.compactMap { $0 as? AppLifecycleListener }
45
60
  }
package/ios/Bridge.swift CHANGED
@@ -200,7 +200,7 @@ final class Bridge {
200
200
  windowSizeDidChange(to: rootView.bounds.size)
201
201
 
202
202
  for contentRoot in contentRootsByNodeId.values {
203
- (contentRoot as? ModalController)?.dismissIfDetached()
203
+ (contentRoot as? ModalController)?.followPlaceholder()
204
204
  contentRoot.layoutContent()
205
205
  }
206
206
  }
@@ -491,8 +491,7 @@ final class Bridge {
491
491
  // MARK: - Main thread
492
492
 
493
493
  private func resetNodeTree() {
494
- // Sheets of the old tree's screen stacks too, which only their stack knows about.
495
- rootView.hostWindow?.rootViewController?.dismiss(animated: false)
494
+ dismissPresentedControllers()
496
495
  rootView.subviews.forEach { $0.removeFromSuperview() }
497
496
  contentRootsByNodeId.values.forEach { ($0 as? ModalController)?.setVisible(false) }
498
497
  contentRootsByNodeId = [:]
@@ -539,7 +538,7 @@ final class Bridge {
539
538
  private func forgetNode(id: Int) {
540
539
  let node = nodesById.removeValue(forKey: id)
541
540
  (node?.view as? ScreenStackView)?.dismissPresentedScreens()
542
- modalController(id)?.dismissIfDetached()
541
+ modalController(id)?.detach()
543
542
  contentRootsByNodeId[id] = nil
544
543
  gestureReportersByNodeId[id] = nil
545
544
  reportedLayoutsByNodeId[id] = nil
@@ -569,6 +568,29 @@ final class Bridge {
569
568
  evaluate { [unowned self] in runtime?.call("__layoutsChanged", arguments: [changedLayouts]) }
570
569
  }
571
570
 
571
+ /// What's presented over the controller holding the root view: an app's own sheet holding the
572
+ /// NativueView stays.
573
+ private func dismissPresentedControllers() {
574
+ guard let root = rootView.hostWindow?.rootViewController else { return }
575
+
576
+ let presentations = Array(sequence(first: root, next: \.presentedViewController))
577
+ guard let holderIndex = presentations.lastIndex(where: { rootView.isDescendant(of: $0.view) }),
578
+ holderIndex < presentations.count - 1 else { return }
579
+
580
+ presentations[holderIndex].dismiss(animated: false)
581
+ }
582
+
583
+ /// In the window, or under a full-screen modal that the controller holding it presented: UIKit takes
584
+ /// the views under one out of the window. A screen pushed under another, or an unselected tab, is not.
585
+ private func isOnScreen(_ view: UIView) -> Bool {
586
+ if view.window != nil { return true }
587
+
588
+ let holder = sequence(first: view, next: { $0.superview }).compactMap { $0.next as? UIViewController }.last
589
+ guard let holder, let presented = holder.presentedViewController else { return false }
590
+
591
+ return presented.presentingViewController === holder
592
+ }
593
+
572
594
  private func modalController(_ id: Int) -> ModalController? {
573
595
  contentRootsByNodeId[id] as? ModalController
574
596
  }
@@ -682,6 +704,10 @@ final class Bridge {
682
704
  case "Modal":
683
705
  let modalController = ModalController()
684
706
  modalController.onEvent = { [unowned self] eventName in dispatchEvent(eventName, toNodeId: id) }
707
+ modalController.hostWindow = { [unowned self] in rootView.hostWindow }
708
+ modalController.isPlaceholderOnScreen = { [unowned self, unowned modalController] in
709
+ isOnScreen(modalController.placeholderView)
710
+ }
685
711
  contentRootsByNodeId[id] = modalController
686
712
 
687
713
  let node = NativeNode(view: modalController.placeholderView, measuresContent: false)
@@ -14,6 +14,11 @@ final class ModalController: UIViewController, ContentRoot, UIAdaptivePresentati
14
14
  let placeholderView = UIView()
15
15
 
16
16
  var onEvent: ((String) -> Void)?
17
+ /// The app's window: the placeholder's is nil while a full-screen modal covers it.
18
+ var hostWindow: () -> UIWindow? = { nil }
19
+ /// The placeholder is in the window, or covered by a full-screen modal: not in a screen pushed under
20
+ /// another, an unselected tab or a deactivated <KeepAlive>.
21
+ var isPlaceholderOnScreen: () -> Bool = { false }
17
22
  var animationType = "none"
18
23
  var presentationStyleName = "fullScreen"
19
24
  var transparent = false
@@ -39,20 +44,26 @@ final class ModalController: UIViewController, ContentRoot, UIAdaptivePresentati
39
44
  contentNode.calculateLayout(width: view.bounds.width, height: view.bounds.height)
40
45
  }
41
46
 
42
- /// Deferred to after the current batch, so the placeholder is already in the window when presenting.
47
+ /// Deferred to after the current batch, so the placeholder is already on screen when presenting.
43
48
  func setVisible(_ visible: Bool) {
44
49
  wantsVisible = visible
45
50
  DispatchQueue.main.async { [self] in applyVisibility() }
46
51
  }
47
52
 
48
53
  /// The <Modal> left the tree (an ancestor's v-if): its content must go too.
49
- func dismissIfDetached() {
50
- guard placeholderView.window == nil else { return }
51
-
54
+ func detach() {
52
55
  wantsVisible = false
53
56
  applyVisibility()
54
57
  }
55
58
 
59
+ /// Closed while its placeholder is off screen (a tab switched, a <KeepAlive> deactivated), and shown
60
+ /// again when it's back, if JS still wants it.
61
+ func followPlaceholder() {
62
+ guard !isTransitioning else { return }
63
+
64
+ if !isPlaceholderOnScreen() { dismissIfPresented() } else if wantsVisible && !isPresented { present() }
65
+ }
66
+
56
67
  private func applyVisibility() {
57
68
  guard !isTransitioning else { return }
58
69
 
@@ -60,7 +71,7 @@ final class ModalController: UIViewController, ContentRoot, UIAdaptivePresentati
60
71
  }
61
72
 
62
73
  private func present() {
63
- guard !isPresented, let presenter = topViewController() else { return }
74
+ guard !isPresented, isPlaceholderOnScreen(), let presenter = topViewController() else { return }
64
75
 
65
76
  view.backgroundColor = transparent ? .clear : .systemBackground
66
77
  modalPresentationStyle = transparent
@@ -89,7 +100,7 @@ final class ModalController: UIViewController, ContentRoot, UIAdaptivePresentati
89
100
  }
90
101
 
91
102
  private func topViewController() -> UIViewController? {
92
- var top = placeholderView.window?.rootViewController
103
+ var top = hostWindow()?.rootViewController
93
104
 
94
105
  while let presented = top?.presentedViewController, presented !== self {
95
106
  top = presented
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativue/core",
3
- "version": "0.15.3",
3
+ "version": "0.15.4",
4
4
  "description": "Vue rendering real native views on iOS and Android",
5
5
  "keywords": [
6
6
  "vue",