Skip to content

Commit b755acc

Browse files
authored
chore(Stack): refactor component definition & nomenclature on native side (#3493)
## Description Closes software-mansion/react-native-screens-labs#743 ## Changes - **Move stack related native components to dedicated directory** - **Rename native spec file of `StackHost` component** - **Change `RNSScreenStackHost` component definition to `RNSStackHost`** - **Rename `RNSScreenStackHostComponentView` -> `RNSStackHostComponentView`**
1 parent 6978a6d commit b755acc

18 files changed

+49
-48
lines changed

ios/gamma/stack/RNSScreenStackHostComponentViewManager.mm

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

ios/gamma/stack/RNSStackController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import UIKit
44
@objc
55
public class RNSStackController: UINavigationController, ReactMountingTransactionObserving {
66
private var needsChildViewControllersUpdate = false
7-
private let screenStackHostComponentView: RNSScreenStackHostComponentView
7+
private let stackHostComponentView: RNSStackHostComponentView
88

9-
@objc public required init(stackHostComponentView: RNSScreenStackHostComponentView) {
10-
self.screenStackHostComponentView = stackHostComponentView
9+
@objc public required init(stackHostComponentView: RNSStackHostComponentView) {
10+
self.stackHostComponentView = stackHostComponentView
1111
super.init(nibName: nil, bundle: nil)
1212
}
1313

@@ -38,7 +38,7 @@ public class RNSStackController: UINavigationController, ReactMountingTransactio
3838
"[RNScreens] Child view controller must be invalidated when update is forced!")
3939

4040
let activeControllers = sourceAllViewControllers()
41-
.filter { screenCtrl in screenCtrl.screenStackComponentView.maxLifecycleState == .attached }
41+
.filter { screenCtrl in screenCtrl.screen.maxLifecycleState == .attached }
4242

4343
setViewControllers(activeControllers, animated: true)
4444

@@ -47,7 +47,7 @@ public class RNSStackController: UINavigationController, ReactMountingTransactio
4747

4848
private func sourceAllViewControllers() -> [RNSStackScreenController] {
4949
let screenStackComponents =
50-
screenStackHostComponentView.reactSubviews() as! [RNSStackScreenComponentView]
50+
stackHostComponentView.reactSubviews() as! [RNSStackScreenComponentView]
5151
return screenStackComponents.lazy.map(\.controller)
5252
}
5353

ios/gamma/stack/RNSScreenStackHostComponentView.h renamed to ios/gamma/stack/RNSStackHostComponentView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
NS_ASSUME_NONNULL_BEGIN
99

10-
@interface RNSScreenStackHostComponentView : RNSReactBaseView
10+
@interface RNSStackHostComponentView : RNSReactBaseView
1111

1212
@property (nonatomic, nonnull, strong, readonly) RNSStackController *stackController;
1313

ios/gamma/stack/RNSScreenStackHostComponentView.mm renamed to ios/gamma/stack/RNSStackHostComponentView.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import "RNSScreenStackHostComponentView.h"
1+
#import "RNSStackHostComponentView.h"
22

33
#import <React/RCTConversions.h>
44
#import <React/RCTMountingTransactionObserving.h>
@@ -13,10 +13,10 @@
1313

1414
namespace react = facebook::react;
1515

16-
@interface RNSScreenStackHostComponentView () <RCTMountingTransactionObserving>
16+
@interface RNSStackHostComponentView () <RCTMountingTransactionObserving>
1717
@end
1818

19-
@implementation RNSScreenStackHostComponentView {
19+
@implementation RNSStackHostComponentView {
2020
RNSStackController *_Nonnull _controller;
2121
NSMutableArray<RNSStackScreenComponentView *> *_Nonnull _reactSubviews;
2222

@@ -107,7 +107,7 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
107107

108108
+ (react::ComponentDescriptorProvider)componentDescriptorProvider
109109
{
110-
return react::concreteComponentDescriptorProvider<react::RNSScreenStackHostComponentDescriptor>();
110+
return react::concreteComponentDescriptorProvider<react::RNSStackHostComponentDescriptor>();
111111
}
112112

113113
+ (BOOL)shouldBeRecycled
@@ -137,7 +137,7 @@ - (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction
137137

138138
@end
139139

140-
Class<RCTComponentViewProtocol> RNSScreenStackHostCls(void)
140+
Class<RCTComponentViewProtocol> RNSStackHostCls(void)
141141
{
142-
return RNSScreenStackHostComponentView.class;
142+
return RNSStackHostComponentView.class;
143143
}

ios/gamma/stack/RNSScreenStackHostComponentViewManager.h renamed to ios/gamma/stack/RNSStackHostComponentViewManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
NS_ASSUME_NONNULL_BEGIN
66

7-
@interface RNSScreenStackHostComponentViewManager : RCTViewManager
7+
@interface RNSStackHostComponentViewManager : RCTViewManager
88

99
@end
1010

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import "RNSStackHostComponentViewManager.h"
2+
3+
@implementation RNSStackHostComponentViewManager
4+
5+
RCT_EXPORT_MODULE(RNSStackHostViewManager)
6+
7+
@end

ios/gamma/stack/RNSStackScreenComponentView.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
NS_ASSUME_NONNULL_BEGIN
77

88
@class RNSStackScreenController;
9-
@class RNSScreenStackHostComponentView;
9+
@class RNSStackHostComponentView;
1010

11-
typedef NS_ENUM(int, RNSScreenStackLifecycleState) {
12-
RNSScreenStackLifecycleInitial = 0,
13-
RNSScreenStackLifecycleDetached = 1,
14-
RNSScreenStackLifecycleAttached = 2,
11+
typedef NS_ENUM(int, RNSStackScreenLifecycleState) {
12+
RNSStackScreenLifecycleInitial = 0,
13+
RNSStackScreenLifecycleDetached = 1,
14+
RNSStackScreenLifecycleAttached = 2,
1515
};
1616

1717
@interface RNSStackScreenComponentView : RNSReactBaseView
1818

19-
@property (nonatomic, weak, readwrite, nullable) RNSScreenStackHostComponentView *stackHost;
19+
@property (nonatomic, weak, readwrite, nullable) RNSStackHostComponentView *stackHost;
2020
@property (nonatomic, strong, readonly, nonnull) RNSStackScreenController *controller;
2121

2222
@property (nonatomic, strong, readonly, nullable) NSString *screenKey;
23-
@property (nonatomic, readonly) RNSScreenStackLifecycleState maxLifecycleState;
23+
@property (nonatomic, readonly) RNSStackScreenLifecycleState maxLifecycleState;
2424

2525
@end
2626

ios/gamma/stack/RNSStackScreenComponentView.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ - (void)resetProps
4949

5050
// container state
5151
_screenKey = nil;
52-
_maxLifecycleState = RNSScreenStackLifecycleInitial;
52+
_maxLifecycleState = RNSStackScreenLifecycleInitial;
5353
}
5454

5555
- (void)setupController
@@ -87,7 +87,7 @@ - (void)updateProps:(const facebook::react::Props::Shared &)props
8787
const auto &newComponentProps = *std::static_pointer_cast<const react::RNSStackScreenProps>(props);
8888

8989
if (oldComponentProps.maxLifecycleState != newComponentProps.maxLifecycleState) {
90-
_maxLifecycleState = static_cast<RNSScreenStackLifecycleState>(newComponentProps.maxLifecycleState);
90+
_maxLifecycleState = static_cast<RNSStackScreenLifecycleState>(newComponentProps.maxLifecycleState);
9191
_needsLifecycleStateUpdate = YES;
9292
}
9393

ios/gamma/stack/RNSStackScreenController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import UIKit
33

44
@objc
55
public class RNSStackScreenController: UIViewController {
6-
let screenStackComponentView: RNSStackScreenComponentView
6+
let screen: RNSStackScreenComponentView
77
private var reactEventEmitter: RNSStackScreenComponentEventEmitter {
8-
return screenStackComponentView.reactEventEmitter()
8+
return screen.reactEventEmitter()
99
}
1010

1111
@objc public required init(componentView: RNSStackScreenComponentView) {
12-
self.screenStackComponentView = componentView
12+
self.screen = componentView
1313
super.init(nibName: nil, bundle: nil)
1414
}
1515

@@ -22,7 +22,7 @@ public class RNSStackScreenController: UIViewController {
2222
return navCtrl as? RNSStackController
2323
}
2424

25-
if let stackHost = self.screenStackComponentView.stackHost {
25+
if let stackHost = self.screen.stackHost {
2626
return stackHost.stackController
2727
}
2828

ios/stubs/RNSGammaStubs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
NS_ASSUME_NONNULL_BEGIN
1111

12-
@interface RNSScreenStackHostComponentView : NSObject
12+
@interface RNSStackHostComponentView : NSObject
1313
@end
1414

1515
@interface RNSStackScreenComponentView : NSObject

0 commit comments

Comments
 (0)