1 | #import "RNSScreenStackHeaderSubview.h"
|
2 | #import "RNSConvert.h"
|
3 |
|
4 | #ifdef RCT_NEW_ARCH_ENABLED
|
5 | #import <react/renderer/components/rnscreens/ComponentDescriptors.h>
|
6 | #import <react/renderer/components/rnscreens/EventEmitters.h>
|
7 | #import <react/renderer/components/rnscreens/RCTComponentViewHelpers.h>
|
8 |
|
9 | #import <React/RCTConversions.h>
|
10 | #import <React/RCTFabricComponentsPlugins.h>
|
11 | #endif // RCT_NEW_ARCH_ENABLED
|
12 |
|
13 | #ifdef RCT_NEW_ARCH_ENABLED
|
14 | namespace react = facebook::react;
|
15 | #endif // RCT_NEW_ARCH_ENABLED
|
16 |
|
17 | @interface RCTBridge (Private)
|
18 | + (RCTBridge *)currentBridge;
|
19 | @end
|
20 |
|
21 | @implementation RNSScreenStackHeaderSubview
|
22 |
|
23 | #pragma mark - Common
|
24 |
|
25 | #ifdef RCT_NEW_ARCH_ENABLED
|
26 |
|
27 | #pragma mark - Fabric specific
|
28 |
|
29 | - (instancetype)initWithFrame:(CGRect)frame
|
30 | {
|
31 | if (self = [super initWithFrame:frame]) {
|
32 | static const auto defaultProps = std::make_shared<const react::RNSScreenStackHeaderSubviewProps>();
|
33 | _props = defaultProps;
|
34 | }
|
35 |
|
36 | return self;
|
37 | }
|
38 |
|
39 | #pragma mark - RCTComponentViewProtocol
|
40 |
|
41 | - (void)prepareForRecycle
|
42 | {
|
43 | [super prepareForRecycle];
|
44 | }
|
45 |
|
46 | - (void)updateProps:(react::Props::Shared const &)props oldProps:(react::Props::Shared const &)oldProps
|
47 | {
|
48 | const auto &newHeaderSubviewProps = *std::static_pointer_cast<const react::RNSScreenStackHeaderSubviewProps>(props);
|
49 |
|
50 | [self setType:[RNSConvert RNSScreenStackHeaderSubviewTypeFromCppEquivalent:newHeaderSubviewProps.type]];
|
51 | [super updateProps:props oldProps:oldProps];
|
52 | }
|
53 |
|
54 | + (react::ComponentDescriptorProvider)componentDescriptorProvider
|
55 | {
|
56 | return react::concreteComponentDescriptorProvider<react::RNSScreenStackHeaderSubviewComponentDescriptor>();
|
57 | }
|
58 |
|
59 | - (void)updateLayoutMetrics:(const react::LayoutMetrics &)layoutMetrics
|
60 | oldLayoutMetrics:(const react::LayoutMetrics &)oldLayoutMetrics
|
61 | {
|
62 | CGRect frame = RCTCGRectFromRect(layoutMetrics.frame);
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | if (!std::isfinite(frame.size.width) || !std::isfinite(frame.size.height)) {
|
69 | RCTLogWarn(
|
70 | @"-[UIView(ComponentViewProtocol) updateLayoutMetrics:oldLayoutMetrics:]: Received invalid layout metrics (%@) for a view (%@).",
|
71 | NSStringFromCGRect(frame),
|
72 | self);
|
73 | } else {
|
74 | self.bounds = CGRect{CGPointZero, frame.size};
|
75 | }
|
76 | }
|
77 |
|
78 | #else
|
79 | #pragma mark - Paper specific
|
80 |
|
81 | - (instancetype)initWithBridge:(RCTBridge *)bridge
|
82 | {
|
83 | if (self = [super init]) {
|
84 | _bridge = bridge;
|
85 | }
|
86 | return self;
|
87 | }
|
88 |
|
89 | - (void)reactSetFrame:(CGRect)frame
|
90 | {
|
91 |
|
92 |
|
93 | [super reactSetFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
|
94 | }
|
95 |
|
96 | #endif // RCT_NEW_ARCH_ENABLED
|
97 |
|
98 | - (RCTBridge *)bridge
|
99 | {
|
100 | #ifdef RCT_NEW_ARCH_ENABLED
|
101 | return [RCTBridge currentBridge];
|
102 | #else
|
103 | return _bridge;
|
104 | #endif // RCT_NEW_ARCH_ENABLED
|
105 | }
|
106 |
|
107 | @end
|
108 |
|
109 | @implementation RNSScreenStackHeaderSubviewManager
|
110 |
|
111 | RCT_EXPORT_MODULE()
|
112 |
|
113 | RCT_EXPORT_VIEW_PROPERTY(type, RNSScreenStackHeaderSubviewType)
|
114 |
|
115 | #ifdef RCT_NEW_ARCH_ENABLED
|
116 | #else
|
117 | - (UIView *)view
|
118 | {
|
119 | return [[RNSScreenStackHeaderSubview alloc] initWithBridge:self.bridge];
|
120 | }
|
121 | #endif
|
122 |
|
123 | @end
|
124 |
|
125 | #ifdef RCT_NEW_ARCH_ENABLED
|
126 | Class<RCTComponentViewProtocol> RNSScreenStackHeaderSubviewCls(void)
|
127 | {
|
128 | return RNSScreenStackHeaderSubview.class;
|
129 | }
|
130 | #endif
|
131 |
|
132 | @implementation RCTConvert (RNSScreenStackHeaderSubview)
|
133 |
|
134 | RCT_ENUM_CONVERTER(
|
135 | RNSScreenStackHeaderSubviewType,
|
136 | (@{
|
137 | @"back" : @(RNSScreenStackHeaderSubviewTypeBackButton),
|
138 | @"left" : @(RNSScreenStackHeaderSubviewTypeLeft),
|
139 | @"right" : @(RNSScreenStackHeaderSubviewTypeRight),
|
140 | @"title" : @(RNSScreenStackHeaderSubviewTypeTitle),
|
141 | @"center" : @(RNSScreenStackHeaderSubviewTypeCenter),
|
142 | @"searchBar" : @(RNSScreenStackHeaderSubviewTypeSearchBar),
|
143 | }),
|
144 | RNSScreenStackHeaderSubviewTypeTitle,
|
145 | integerValue)
|
146 |
|
147 | @end
|