Skip to content

Commit bc29be5

Browse files
committed
feat: new arch
1 parent 1f5db7b commit bc29be5

11 files changed

+365
-58
lines changed

example/ios/Podfile.lock

Lines changed: 104 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ PODS:
12091209
- ReactCommon/turbomodule/bridging
12101210
- ReactCommon/turbomodule/core
12111211
- Yoga
1212-
- react-native-bottom-tabs (0.0.10):
1212+
- react-native-bottom-tabs (0.0.11):
12131213
- DoubleConversion
12141214
- glog
12151215
- RCT-Folly (= 2024.01.01.00)
@@ -1231,7 +1231,71 @@ PODS:
12311231
- ReactCommon/turbomodule/core
12321232
- Yoga
12331233
- react-native-safe-area-context (4.11.0):
1234+
- DoubleConversion
1235+
- glog
1236+
- RCT-Folly (= 2024.01.01.00)
1237+
- RCTRequired
1238+
- RCTTypeSafety
1239+
- React-Core
1240+
- React-debug
1241+
- React-Fabric
1242+
- React-featureflags
1243+
- React-graphics
1244+
- React-ImageManager
1245+
- React-jsi
1246+
- react-native-safe-area-context/common (= 4.11.0)
1247+
- react-native-safe-area-context/fabric (= 4.11.0)
1248+
- React-NativeModulesApple
1249+
- React-RCTFabric
1250+
- React-rendererdebug
1251+
- React-utils
1252+
- ReactCodegen
1253+
- ReactCommon/turbomodule/bridging
1254+
- ReactCommon/turbomodule/core
1255+
- Yoga
1256+
- react-native-safe-area-context/common (4.11.0):
1257+
- DoubleConversion
1258+
- glog
1259+
- RCT-Folly (= 2024.01.01.00)
1260+
- RCTRequired
1261+
- RCTTypeSafety
1262+
- React-Core
1263+
- React-debug
1264+
- React-Fabric
1265+
- React-featureflags
1266+
- React-graphics
1267+
- React-ImageManager
1268+
- React-jsi
1269+
- React-NativeModulesApple
1270+
- React-RCTFabric
1271+
- React-rendererdebug
1272+
- React-utils
1273+
- ReactCodegen
1274+
- ReactCommon/turbomodule/bridging
1275+
- ReactCommon/turbomodule/core
1276+
- Yoga
1277+
- react-native-safe-area-context/fabric (4.11.0):
1278+
- DoubleConversion
1279+
- glog
1280+
- RCT-Folly (= 2024.01.01.00)
1281+
- RCTRequired
1282+
- RCTTypeSafety
12341283
- React-Core
1284+
- React-debug
1285+
- React-Fabric
1286+
- React-featureflags
1287+
- React-graphics
1288+
- React-ImageManager
1289+
- React-jsi
1290+
- react-native-safe-area-context/common
1291+
- React-NativeModulesApple
1292+
- React-RCTFabric
1293+
- React-rendererdebug
1294+
- React-utils
1295+
- ReactCodegen
1296+
- ReactCommon/turbomodule/bridging
1297+
- ReactCommon/turbomodule/core
1298+
- Yoga
12351299
- React-nativeconfig (0.75.3)
12361300
- React-NativeModulesApple (0.75.3):
12371301
- glog
@@ -1490,6 +1554,7 @@ PODS:
14901554
- React-ImageManager
14911555
- React-jsi
14921556
- React-NativeModulesApple
1557+
- React-RCTAppDelegate
14931558
- React-RCTFabric
14941559
- React-rendererdebug
14951560
- React-utils
@@ -1523,6 +1588,29 @@ PODS:
15231588
- ReactCommon/turbomodule/core
15241589
- Yoga
15251590
- RNScreens (3.34.0):
1591+
- DoubleConversion
1592+
- glog
1593+
- RCT-Folly (= 2024.01.01.00)
1594+
- RCTRequired
1595+
- RCTTypeSafety
1596+
- React-Core
1597+
- React-debug
1598+
- React-Fabric
1599+
- React-featureflags
1600+
- React-graphics
1601+
- React-ImageManager
1602+
- React-jsi
1603+
- React-NativeModulesApple
1604+
- React-RCTFabric
1605+
- React-RCTImage
1606+
- React-rendererdebug
1607+
- React-utils
1608+
- ReactCodegen
1609+
- ReactCommon/turbomodule/bridging
1610+
- ReactCommon/turbomodule/core
1611+
- RNScreens/common (= 3.34.0)
1612+
- Yoga
1613+
- RNScreens/common (3.34.0):
15261614
- DoubleConversion
15271615
- glog
15281616
- RCT-Folly (= 2024.01.01.00)
@@ -1576,6 +1664,7 @@ DEPENDENCIES:
15761664
- React-idlecallbacksnativemodule (from `../node_modules/react-native/ReactCommon/react/nativemodule/idlecallbacks`)
15771665
- React-ImageManager (from `../node_modules/react-native/ReactCommon/react/renderer/imagemanager/platform/ios`)
15781666
- React-jsc (from `../node_modules/react-native/ReactCommon/jsc`)
1667+
- React-jsc/Fabric (from `../node_modules/react-native/ReactCommon/jsc`)
15791668
- React-jserrorhandler (from `../node_modules/react-native/ReactCommon/jserrorhandler`)
15801669
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
15811670
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
@@ -1774,15 +1863,15 @@ SPEC CHECKSUMS:
17741863
React-CoreModules: 2d68c251bc4080028f2835fa47504e8f20669a21
17751864
React-cxxreact: bb0dc212b515d6dba6c6ddc4034584e148857db9
17761865
React-debug: fd0ed8ecd5f8a23c7daf5ceaca8aa722a4d083fd
1777-
React-defaultsnativemodule: 0d824306a15dd80e2bea12f4079fbeff9712b301
1778-
React-domnativemodule: 195491d7c1725befd636f84c67bf229203fc7d07
1866+
React-defaultsnativemodule: 8dd41726048ad16c135e1585797de81480c161fc
1867+
React-domnativemodule: a2f6c53b4edd50da888e240ba92b038a7264e713
17791868
React-Fabric: c12ce848f72cba42fb9e97a73a7c99abc6353f23
17801869
React-FabricComponents: 7813d5575c8ea2cda0fef9be4ff9d10987cba512
17811870
React-FabricImage: c511a5d612479cb4606edf3557c071956c8735f6
17821871
React-featureflags: cf78861db9318ae29982fa8953c92d31b276c9ac
1783-
React-featureflagsnativemodule: 54f6decea27c187c2127e3669a7f5bf2e145e637
1872+
React-featureflagsnativemodule: 7ee9bb16c9b3039c78eea088bc99819827981e12
17841873
React-graphics: 7572851bca7242416b648c45d6af87d93d29281e
1785-
React-idlecallbacksnativemodule: 7d21b0e071c3e02bcc897d2c3db51319642dd466
1874+
React-idlecallbacksnativemodule: 2369a5e611553b9d43ec56577ad76d8d6b8e2474
17861875
React-ImageManager: aedf54d34d4475c66f4c3da6b8359b95bee904e4
17871876
React-jsc: 92ac98e0e03ee54fdaa4ac3936285a4fdb166fab
17881877
React-jserrorhandler: 0c8949672a00f2a502c767350e591e3ec3d82fb3
@@ -1792,18 +1881,18 @@ SPEC CHECKSUMS:
17921881
React-jsitracing: 3935b092f85bb1e53b8cf8a00f572413648af46b
17931882
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
17941883
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
1795-
React-microtasksnativemodule: 618b64238e43ef3154079f193aa6649e5320ae19
1796-
react-native-bottom-tabs: f2d0c291b0158846fb8c6964b9535a3ab206fdf2
1797-
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
1884+
React-microtasksnativemodule: 2eb1a69d35e700f752944644c0295cf7161d06c5
1885+
react-native-bottom-tabs: 3ae74275f8e57e846686aa9f3296b4ce2d5d58a1
1886+
react-native-safe-area-context: c6e59b0ac0acb3ddc3247235215775441ca1b2ff
17981887
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
17991888
React-NativeModulesApple: 651670a799672bd54469f2981d91493dda361ddf
18001889
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b
18011890
React-performancetimeline: d15a723422ed500f47cb271f3175abbeb217f5ba
18021891
React-RCTActionSheet: cb2b38a53d03ec22f1159c89667b86c2c490d92d
18031892
React-RCTAnimation: 6836c87c7364f471e9077fda80b7349bc674be33
1804-
React-RCTAppDelegate: fb2037d3472bda5c31ea16a04cc48e19fe81c792
1893+
React-RCTAppDelegate: 8939a29da847bc51a01264d020a58d9d5035e119
18051894
React-RCTBlob: 984c80df29f3b3e3193bfbc2768bd302c889719b
1806-
React-RCTFabric: 5e691cfb4cd3a9060ddbfb04916284c3c6a933e8
1895+
React-RCTFabric: 4bb022567aacec7417d04741cba7e7baaeec6add
18071896
React-RCTImage: 1b2c2c1716db859ffff2d7a06a30b0ec5c677fc5
18081897
React-RCTLinking: 59c07577767e705b0ab95d11e5ad74c61bf2a022
18091898
React-RCTNetwork: f9a827e7d6bc428e0d99cd1fbe0427854354b8c1
@@ -1820,14 +1909,14 @@ SPEC CHECKSUMS:
18201909
React-utils: b2baee839fb869f732d617b97dcfa384b4b4fdb3
18211910
ReactCodegen: f177b8fd67788c5c6ff45a39c7482c5f8d77ace6
18221911
ReactCommon: 627bd3192ef01a351e804e9709673d3741d38fec
1823-
ReactNativeHost: 62249d6e1e42a969159946c035c1cd3f4b1035dd
1912+
ReactNativeHost: a3cd2bc15b6deac7439318607ce5637d8a93a117
18241913
ReactTestApp-DevSupport: b7cd76a3aeee6167f5e14d82f09685059152c426
18251914
ReactTestApp-Resources: 7db90c026cccdf40cfa495705ad436ccc4d64154
1826-
RNGestureHandler: 366823a3ebcc5ddd25550dbfe80e89779c4760b2
1827-
RNScreens: d86f05e9c243a063ca67cda7f4e05d28fe5c31d4
1915+
RNGestureHandler: 6a34af1ea5d9321af615933c271b0c37a00ff473
1916+
RNScreens: f31db3d6a1b987e78ed3a3c13e29e196f3b85b95
18281917
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1829-
Yoga: 4ef80d96a5534f0e01b3055f17d1e19a9fc61b63
1918+
Yoga: 1354c027ab07c7736f99a3bef16172d6f1b12b47
18301919

18311920
PODFILE CHECKSUM: 539add55dc6c2e7f9754e288b1ce4fd8583819ae
18321921

1833-
COCOAPODS: 1.15.2
1922+
COCOAPODS: 1.14.3

ios/Extensions.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@ extension UIView {
1818
])
1919
}
2020
}
21+
22+
extension UIImage {
23+
func resizeImageTo(size: CGSize) -> UIImage? {
24+
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
25+
self.draw(in: CGRect(origin: CGPoint.zero, size: size))
26+
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()!
27+
UIGraphicsEndImageContext()
28+
return resizedImage
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
2+
#import <React/RCTViewComponentView.h>
3+
#import <UIKit/UIKit.h>
4+
5+
NS_ASSUME_NONNULL_BEGIN
6+
7+
@interface RCTTabViewComponentView: RCTViewComponentView
8+
@end
9+
10+
NS_ASSUME_NONNULL_END
11+
12+
#endif /* RCT_NEW_ARCH_ENABLED */
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#ifdef RCT_NEW_ARCH_ENABLED
2+
#import "RCTTabViewComponentView.h"
3+
4+
#import <react/renderer/components/RNCTabViewSpec/ComponentDescriptors.h>
5+
#import <react/renderer/components/RNCTabViewSpec/EventEmitters.h>
6+
#import <react/renderer/components/RNCTabViewSpec/Props.h>
7+
#import <react/renderer/components/RNCTabViewSpec/RCTComponentViewHelpers.h>
8+
9+
#import <React/RCTFabricComponentsPlugins.h>
10+
11+
#if __has_include("react_native_bottom_tabs/react_native_bottom_tabs-Swift.h")
12+
#import "react_native_bottom_tabs/react_native_bottom_tabs-Swift.h"
13+
#else
14+
#import "react_native_bottom_tabs-Swift.h"
15+
#endif
16+
17+
#import <React/RCTImageLoader.h>
18+
#import <React/RCTImageSource.h>
19+
#import <React/RCTBridge+Private.h>
20+
#import "RCTImagePrimitivesConversions.h"
21+
22+
23+
using namespace facebook::react;
24+
25+
@interface RCTTabViewComponentView () <RCTRNCTabViewViewProtocol, TabViewProviderDelegate> {
26+
}
27+
28+
@end
29+
30+
@implementation RCTTabViewComponentView {
31+
TabViewProvider *_tabViewProvider;
32+
NSMutableArray<UIView *> *_reactSubviews;
33+
}
34+
35+
+ (ComponentDescriptorProvider)componentDescriptorProvider
36+
{
37+
return concreteComponentDescriptorProvider<RNCTabViewComponentDescriptor>();
38+
}
39+
40+
- (instancetype)initWithFrame:(CGRect)frame
41+
{
42+
if (self = [super initWithFrame:frame]) {
43+
static const auto defaultProps = std::make_shared<const RNCTabViewProps>();
44+
// FIXME: This works but it's not the best solution
45+
RCTImageLoader *imageLoader = [[RCTBridge currentBridge] moduleForName:@"ImageLoader"];
46+
_tabViewProvider = [[TabViewProvider alloc] initWithDelegate:self imageLoader:imageLoader];
47+
_reactSubviews = [NSMutableArray new];
48+
self.contentView = _tabViewProvider;
49+
_props = defaultProps;
50+
}
51+
52+
return self;
53+
}
54+
55+
- (void)prepareForRecycle {
56+
[super prepareForRecycle];
57+
_reactSubviews = [NSMutableArray new];
58+
self.contentView = nil;
59+
_tabViewProvider = nil;
60+
}
61+
62+
- (void)layoutSubviews {
63+
[super layoutSubviews];
64+
_tabViewProvider.children = [self reactSubviews];
65+
}
66+
67+
- (NSArray<UIView *> *)reactSubviews
68+
{
69+
return _reactSubviews;
70+
}
71+
72+
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index {
73+
[_reactSubviews insertObject:childComponentView atIndex:index];
74+
_tabViewProvider.children = [self reactSubviews];
75+
}
76+
77+
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index {
78+
[_reactSubviews removeObjectAtIndex:index];
79+
80+
[childComponentView removeFromSuperview];
81+
}
82+
83+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
84+
{
85+
const auto &oldViewProps = *std::static_pointer_cast<RNCTabViewProps const>(_props);
86+
const auto &newViewProps = *std::static_pointer_cast<RNCTabViewProps const>(props);
87+
88+
if (oldViewProps.translucent != newViewProps.translucent) {
89+
_tabViewProvider.translucent = newViewProps.translucent;
90+
}
91+
92+
if (oldViewProps.icons != newViewProps.icons) {
93+
auto iconsArray = [[NSMutableArray alloc] init];
94+
for (auto &source : newViewProps.icons) {
95+
auto imageSource = [[RCTImageSource alloc] initWithURLRequest:NSURLRequestFromImageSource(source) size:CGSizeMake(source.size.width, source.size.height) scale:source.scale];
96+
[iconsArray addObject:imageSource];
97+
}
98+
99+
_tabViewProvider.icons = iconsArray;
100+
}
101+
102+
if (oldViewProps.sidebarAdaptable != newViewProps.sidebarAdaptable) {
103+
_tabViewProvider.sidebarAdaptable = newViewProps.sidebarAdaptable;
104+
}
105+
106+
if (oldViewProps.disablePageAnimations != newViewProps.disablePageAnimations) {
107+
_tabViewProvider.disablePageAnimations = newViewProps.disablePageAnimations;
108+
}
109+
110+
if (oldViewProps.labeled != newViewProps.labeled) {
111+
_tabViewProvider.labeled = newViewProps.labeled;
112+
}
113+
114+
if (oldViewProps.ignoresTopSafeArea != newViewProps.ignoresTopSafeArea) {
115+
_tabViewProvider.ignoresTopSafeArea = newViewProps.ignoresTopSafeArea;
116+
}
117+
118+
if (oldViewProps.selectedPage != newViewProps.selectedPage) {
119+
_tabViewProvider.selectedPage = [NSString stringWithCString:toString(newViewProps.selectedPage).c_str() encoding:NSASCIIStringEncoding];
120+
}
121+
122+
if (oldViewProps.scrollEdgeAppearance != newViewProps.scrollEdgeAppearance) {
123+
_tabViewProvider.scrollEdgeAppearance = [NSString stringWithCString:toString(newViewProps.scrollEdgeAppearance).c_str() encoding:NSASCIIStringEncoding];
124+
}
125+
126+
if (oldViewProps.labeled != newViewProps.labeled) {
127+
_tabViewProvider.labeled = newViewProps.labeled;
128+
}
129+
130+
// FIXME: This only compares size changes because RNCTabViewItemsStruct doesn't have `==` comparison implemented.
131+
if (oldViewProps.items.size() != newViewProps.items.size()) {
132+
_tabViewProvider.items = convertItemsToArray(newViewProps.items);
133+
}
134+
135+
[super updateProps:props oldProps:oldProps];
136+
}
137+
138+
139+
NSArray* convertItemsToArray(const std::vector<RNCTabViewItemsStruct>& items) {
140+
NSMutableArray *result = [NSMutableArray array];
141+
142+
for (const auto& item : items) {
143+
NSDictionary *dict = @{
144+
@"key": [NSString stringWithUTF8String:item.key.c_str()],
145+
@"title": [NSString stringWithUTF8String:item.title.c_str()],
146+
@"sfSymbol": [NSString stringWithUTF8String:item.sfSymbol.c_str()],
147+
@"badge": [NSString stringWithUTF8String:item.badge.c_str()]
148+
};
149+
150+
[result addObject:dict];
151+
}
152+
153+
return result;
154+
}
155+
156+
157+
// MARK: TabViewProviderDelegate
158+
159+
- (void)onPageSelectedWithKey:(NSString *)key {
160+
auto eventEmitter = std::static_pointer_cast<const RNCTabViewEventEmitter>(_eventEmitter);
161+
if (eventEmitter) {
162+
eventEmitter->onPageSelected(RNCTabViewEventEmitter::OnPageSelected{
163+
.key = [key cStringUsingEncoding:kCFStringEncodingUTF8]
164+
});
165+
}
166+
}
167+
168+
@end
169+
170+
Class<RCTComponentViewProtocol> RNCTabViewCls(void)
171+
{
172+
return RCTTabViewComponentView.class;
173+
}
174+
175+
#endif // RCT_NEW_ARCH_ENABLED
176+
177+

0 commit comments

Comments
 (0)