Skip to content

Commit 71bee46

Browse files
committed
refactor(iOS): migrate RNSStackController to Swift (#81)
- **Migrate RNSStackScreenController to Swift** Stage 1 - currently there is parallel type StackController. In next stage I'll remove old implementation & rename the new one. - **Add missing @objc annotations** This is required for these methods to be visible from ObjC code - **Remove old implementation & rename the new one to use naming conv.** - **Add missing setNeedsUpdateOfChildViewControllers method**
1 parent adb6295 commit 71bee46

6 files changed

+50
-74
lines changed

ios/gamma/RNSReactMountingTransactionObserving.h

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
@objc
4+
protocol ReactMountingTransactionObserving {
5+
func reactMountingTransactionWillMount()
6+
func reactMountingTransactionDidMount()
7+
}

ios/gamma/stack/RNSScreenStackHostComponentView.mm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#import <react/renderer/components/rnscreens/Props.h>
99
#import <react/renderer/components/rnscreens/RCTComponentViewHelpers.h>
1010

11-
#import "RNSStackController.h"
1211
#import "RNSStackScreenComponentView.h"
1312
#import "RNScreens-Swift.h"
1413

@@ -111,7 +110,7 @@ - (void)mountingTransactionWillMount:(const facebook::react::MountingTransaction
111110
withSurfaceTelemetry:(const facebook::react::SurfaceTelemetry &)surfaceTelemetry
112111
{
113112
_hasModifiedReactSubviewsInCurrentTransaction = false;
114-
[_controller reactMountingTransactionWillMount:transaction];
113+
[_controller reactMountingTransactionWillMount];
115114
}
116115

117116
- (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction &)transaction
@@ -127,7 +126,7 @@ - (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction
127126

128127
[_controller setNeedsUpdateOfChildViewControllers:childViewControllers];
129128
}
130-
[_controller reactMountingTransactionDidMount:transaction];
129+
[_controller reactMountingTransactionDidMount];
131130
}
132131

133132
@end

ios/gamma/stack/RNSStackController.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

ios/gamma/stack/RNSStackController.mm

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Foundation
2+
import UIKit
3+
4+
@objc
5+
class RNSStackController : UINavigationController, ReactMountingTransactionObserving {
6+
private var pendingChildViewControllers: [RNSStackScreenController]?
7+
8+
@objc
9+
func setNeedsUpdateOfChildViewControllers(_ viewControllers: [RNSStackScreenController]) {
10+
pendingChildViewControllers = viewControllers
11+
}
12+
13+
@objc
14+
func updateChildViewControllersIfNeeded() {
15+
if pendingChildViewControllers != nil {
16+
updateChildViewControllers()
17+
}
18+
}
19+
20+
@objc
21+
func updateChildViewControllers() {
22+
guard let pendingChildViewControllers = pendingChildViewControllers else {
23+
fatalError("[RNScreens] Pending update must not be nil while it is forced!")
24+
}
25+
26+
setViewControllers(pendingChildViewControllers, animated: true)
27+
self.pendingChildViewControllers = nil
28+
}
29+
30+
// MARK: ReactMountingTransactionObserving
31+
32+
@objc
33+
func reactMountingTransactionWillMount() {
34+
// noop
35+
}
36+
37+
@objc
38+
func reactMountingTransactionDidMount() {
39+
updateChildViewControllersIfNeeded()
40+
}
41+
}

0 commit comments

Comments
 (0)