-
-
Notifications
You must be signed in to change notification settings - Fork 632
Expand file tree
/
Copy pathRNSStackController.swift
More file actions
65 lines (50 loc) · 1.67 KB
/
RNSStackController.swift
File metadata and controls
65 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Foundation
import UIKit
@objc
public class RNSStackController: UINavigationController, ReactMountingTransactionObserving {
private var needsChildViewControllersUpdate = false
private let stackHostComponentView: RNSStackHostComponentView
@objc public required init(stackHostComponentView: RNSStackHostComponentView) {
self.stackHostComponentView = stackHostComponentView
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
return nil
}
// MARK: Signals
@objc
public func setNeedsUpdateOfChildViewControllers() {
needsChildViewControllersUpdate = true
}
// MARK: Updating
@objc
public func updateChildViewControllersIfNeeded() {
if needsChildViewControllersUpdate {
updateChildViewControllers()
}
}
@objc
public func updateChildViewControllers() {
precondition(
needsChildViewControllersUpdate,
"[RNScreens] Child view controller must be invalidated when update is forced!")
let activeControllers = sourceAllViewControllers()
.filter { screenCtrl in screenCtrl.screen.activityMode == .attached }
setViewControllers(activeControllers, animated: true)
needsChildViewControllersUpdate = false
}
private func sourceAllViewControllers() -> [RNSStackScreenController] {
let screenStackComponents =
stackHostComponentView.reactSubviews() as! [RNSStackScreenComponentView]
return screenStackComponents.lazy.map(\.controller)
}
// MARK: ReactMountingTransactionObserving
@objc
public func reactMountingTransactionWillMount() {
// noop
}
@objc
public func reactMountingTransactionDidMount() {
updateChildViewControllersIfNeeded()
}
}