Skip to content

Commit 865c6c1

Browse files
committed
feat: add new arch
1 parent f130f89 commit 865c6c1

18 files changed

+345
-193
lines changed

Apps/BRNPlayground/ios/Podfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ require_relative '../node_modules/react-native-permissions/scripts/setup'
44
workspace 'BRNPlayground.xcworkspace'
55

66
options = {
7-
:bridgeless_enabled => false,
8-
:fabric_enabled => false,
7+
:bridgeless_enabled => true,
8+
:fabric_enabled => true,
99
:hermes_enabled => true,
1010
}
1111

Apps/BRNPlayground/ios/Podfile.lock

+54-12
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,28 @@ PODS:
12591259
- ReactCommon/turbomodule/core
12601260
- Yoga
12611261
- react-native-slider (4.5.2):
1262+
- DoubleConversion
1263+
- glog
1264+
- hermes-engine
1265+
- RCT-Folly (= 2024.01.01.00)
1266+
- RCTRequired
1267+
- RCTTypeSafety
1268+
- React-Core
1269+
- React-debug
1270+
- React-Fabric
1271+
- React-featureflags
1272+
- React-graphics
1273+
- React-ImageManager
1274+
- react-native-slider/common (= 4.5.2)
1275+
- React-NativeModulesApple
1276+
- React-RCTFabric
1277+
- React-rendererdebug
1278+
- React-utils
1279+
- ReactCodegen
1280+
- ReactCommon/turbomodule/bridging
1281+
- ReactCommon/turbomodule/core
1282+
- Yoga
1283+
- react-native-slider/common (4.5.2):
12621284
- DoubleConversion
12631285
- glog
12641286
- hermes-engine
@@ -1554,6 +1576,7 @@ PODS:
15541576
- React-graphics
15551577
- React-ImageManager
15561578
- React-NativeModulesApple
1579+
- React-RCTAppDelegate
15571580
- React-RCTFabric
15581581
- React-rendererdebug
15591582
- React-utils
@@ -1566,7 +1589,26 @@ PODS:
15661589
- React-jsi
15671590
- ReactTestApp-Resources (1.0.0-dev)
15681591
- RNPermissions (4.1.5):
1592+
- DoubleConversion
1593+
- glog
1594+
- hermes-engine
1595+
- RCT-Folly (= 2024.01.01.00)
1596+
- RCTRequired
1597+
- RCTTypeSafety
15691598
- React-Core
1599+
- React-debug
1600+
- React-Fabric
1601+
- React-featureflags
1602+
- React-graphics
1603+
- React-ImageManager
1604+
- React-NativeModulesApple
1605+
- React-RCTFabric
1606+
- React-rendererdebug
1607+
- React-utils
1608+
- ReactCodegen
1609+
- ReactCommon/turbomodule/bridging
1610+
- ReactCommon/turbomodule/core
1611+
- Yoga
15701612
- SocketRocket (0.7.0)
15711613
- Yoga (0.0.0)
15721614

@@ -1802,16 +1844,16 @@ SPEC CHECKSUMS:
18021844
React-CoreModules: 2d68c251bc4080028f2835fa47504e8f20669a21
18031845
React-cxxreact: 5f233f8ac7ea4772e49462e0ab2b0a15a4f80ab7
18041846
React-debug: fd0ed8ecd5f8a23c7daf5ceaca8aa722a4d083fd
1805-
React-defaultsnativemodule: 10f0f8bc38d8dc7d2273572cd85ed0b71298ecdd
1806-
React-domnativemodule: bfef3dda59e7030b498d0d78628f4adf414ab8e4
1847+
React-defaultsnativemodule: 1f9a0cae1ef7e05a6ea2bbec2e5eff6eb70da16a
1848+
React-domnativemodule: 38d632c6963ab2d08f5ce67808e070439bd1461c
18071849
React-Fabric: 3d0f5e2735d2f77a897ee684edeff7bb0e061919
18081850
React-FabricComponents: 68032a85a3c25c9c8d6ce676d8af9a85e2370f24
18091851
React-FabricImage: f8ac2df576703097b5b2f8d972b162cdca855aa3
18101852
React-featureflags: cf78861db9318ae29982fa8953c92d31b276c9ac
1811-
React-featureflagsnativemodule: d04eb5c3f0ac33fe70b060d97e8649bfd69c5f1e
1853+
React-featureflagsnativemodule: 99ffda7fc2cc0f9578b05b84d8b4a2e9dcb39b8b
18121854
React-graphics: 7572851bca7242416b648c45d6af87d93d29281e
18131855
React-hermes: 95c27801c60615345ee6256eafa6d597ce983b8b
1814-
React-idlecallbacksnativemodule: f5f0b760ec2739b30e315e1afee3dd3a5a93c3b6
1856+
React-idlecallbacksnativemodule: e4fd9ee09b8481dd22f1e173984e5ee2730712ce
18151857
React-ImageManager: aedf54d34d4475c66f4c3da6b8359b95bee904e4
18161858
React-jserrorhandler: 0c8949672a00f2a502c767350e591e3ec3d82fb3
18171859
React-jsi: d77bb442a4b0849063f2bd22d3c1fa71918713b7
@@ -1820,18 +1862,18 @@ SPEC CHECKSUMS:
18201862
React-jsitracing: 3935b092f85bb1e53b8cf8a00f572413648af46b
18211863
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
18221864
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
1823-
React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e
1824-
react-native-babylon: 6234712503667b128f2a21b17d0d6dcc03c51552
1825-
react-native-slider: 97ce0bd921f40de79cead9754546d5e4e7ba44f8
1865+
React-microtasksnativemodule: 0b6b90da7f203e3015e1252ec3cba49c8ddd85ad
1866+
react-native-babylon: 5ce7247a4d0d7135ad07cbff3d1ecea6658243e4
1867+
react-native-slider: e1f4b4538f7de7417b626174874f4f58d4cf6c28
18261868
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
18271869
React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27
18281870
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b
18291871
React-performancetimeline: d15a723422ed500f47cb271f3175abbeb217f5ba
18301872
React-RCTActionSheet: cb2b38a53d03ec22f1159c89667b86c2c490d92d
18311873
React-RCTAnimation: 6836c87c7364f471e9077fda80b7349bc674be33
1832-
React-RCTAppDelegate: 2f11edfa7302451c792591f9a7838ca86cdcec34
1874+
React-RCTAppDelegate: 603240f6a7d7eefeeffe4e29dd0be70dc35208cf
18331875
React-RCTBlob: 516dbbd38397f5013394fdd1cc65408cc82e37a1
1834-
React-RCTFabric: b281a52c2b9726b0c64880e1535f2100013d5f7c
1876+
React-RCTFabric: 7298604d497db4fe445cd704bd1097636643ee89
18351877
React-RCTImage: 1b2c2c1716db859ffff2d7a06a30b0ec5c677fc5
18361878
React-RCTLinking: 59c07577767e705b0ab95d11e5ad74c61bf2a022
18371879
React-RCTNetwork: f9a827e7d6bc428e0d99cd1fbe0427854354b8c1
@@ -1849,13 +1891,13 @@ SPEC CHECKSUMS:
18491891
React-utils: f2afa6acd905ca2ce7bb8ffb4a22f7f8a12534e8
18501892
ReactCodegen: ff95a93d5ab5d9b2551571886271478eaa168565
18511893
ReactCommon: 289214026502e6a93484f4a46bcc0efa4f3f2864
1852-
ReactNativeHost: c66372f767ef829c03a9b5ba0e3355db51c2902d
1894+
ReactNativeHost: a27bb5af1c4d73dd3e80cc7ce295407f414e0e8c
18531895
ReactTestApp-DevSupport: 946bdd9e86ef05a3201d4f5af3166659f39564d0
18541896
ReactTestApp-Resources: 7db90c026cccdf40cfa495705ad436ccc4d64154
1855-
RNPermissions: 5a2dafe37c8e0a3fa1d6e0783a1490b1b7fd92d6
1897+
RNPermissions: d6c457e463b72e1d84e10474cd6645931338f8e5
18561898
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
18571899
Yoga: 4ef80d96a5534f0e01b3055f17d1e19a9fc61b63
18581900

1859-
PODFILE CHECKSUM: c0272fe43d76243a8a0abcc5781bde0430d39023
1901+
PODFILE CHECKSUM: 777c486daf104b2094434716417a60c0da74e09e
18601902

18611903
COCOAPODS: 1.15.2

Apps/BRNPlayground/package-lock.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#import <UIKit/UIKit.h>
3+
#import <MetalKit/MetalKit.h>
4+
#import <React/RCTBridge.h>
5+
#import <React/RCTComponent.h>
6+
7+
@interface EngineView : MTKView
8+
9+
@property (nonatomic, copy) RCTDirectEventBlock onSnapshotDataReturned;
10+
@property (nonatomic, assign) BOOL isTransparent;
11+
@property (nonatomic, assign) NSNumber* antiAliasing;
12+
13+
- (void)setMSAA:(NSNumber*)value;
14+
- (void)takeSnapshot;
15+
- (void)setIsTransparentFlag:(NSNumber*)isTransparentFlag;
16+
17+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#import "BabylonEngineView.h"
2+
#include "BabylonNativeInterop.h"
3+
4+
@implementation EngineView {
5+
MTKView* xrView;
6+
}
7+
8+
- (instancetype)init {
9+
if (self = [super initWithFrame:CGRectZero device:MTLCreateSystemDefaultDevice()]) {
10+
super.translatesAutoresizingMaskIntoConstraints = false;
11+
super.colorPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
12+
super.depthStencilPixelFormat = MTLPixelFormatDepth32Float;
13+
}
14+
return self;
15+
}
16+
17+
- (void)setIsTransparentFlag:(NSNumber*)isTransparentFlag {
18+
BOOL isTransparent = [isTransparentFlag intValue] == 1;
19+
if(isTransparent){
20+
[self setOpaque:NO];
21+
} else {
22+
[self setOpaque:YES];
23+
}
24+
self.isTransparent = isTransparent;
25+
}
26+
27+
- (void)setMSAA:(NSNumber*)value {
28+
[BabylonNativeInterop updateMSAA:value];
29+
}
30+
31+
- (void)setBounds:(CGRect)bounds {
32+
[super setBounds:bounds];
33+
[BabylonNativeInterop updateView:self];
34+
}
35+
36+
- (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
37+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
38+
}
39+
40+
- (void)touchesMoved:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
41+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
42+
}
43+
44+
- (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
45+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
46+
}
47+
48+
- (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
49+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
50+
}
51+
52+
- (void)drawRect:(CGRect)rect {
53+
if ([BabylonNativeInterop isXRActive]) {
54+
if (!xrView) {
55+
xrView = [[MTKView alloc] initWithFrame:self.bounds device:self.device];
56+
xrView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
57+
xrView.userInteractionEnabled = false;
58+
[self addSubview:xrView];
59+
[BabylonNativeInterop updateXRView:xrView];
60+
}
61+
} else if (xrView) {
62+
[BabylonNativeInterop updateXRView:nil];
63+
[xrView removeFromSuperview];
64+
xrView = nil;
65+
}
66+
67+
[BabylonNativeInterop renderView];
68+
}
69+
70+
-(void)dealloc {
71+
[BabylonNativeInterop updateXRView:nil];
72+
}
73+
74+
- (void)takeSnapshot {
75+
// We must take the screenshot on the main thread otherwise we might fail to get a valid handle on the view's image.
76+
dispatch_async(dispatch_get_main_queue(), ^{
77+
// Start the graphics context.
78+
UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES /* opaque */, 0.0f);
79+
80+
// Draw the current state of the view into the graphics context.
81+
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:NO];
82+
83+
// Grab the image from the graphics context, and convert into a base64 encoded JPG.
84+
UIImage* capturedImage = UIGraphicsGetImageFromCurrentImageContext();
85+
UIGraphicsEndImageContext();
86+
NSData* jpgData = UIImageJPEGRepresentation(capturedImage, .8f);
87+
NSString* encodedData = [jpgData base64EncodedStringWithOptions:0];
88+
89+
// Fire the onSnapshotDataReturned event if hooked up.
90+
if (self.onSnapshotDataReturned != nil) {
91+
self.onSnapshotDataReturned(@{ @"data":encodedData});
92+
}
93+
});
94+
}
95+
96+
@end

Modules/@babylonjs/react-native-iosandroid/ios/BabylonModule.mm

+22-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
#import <React/RCTBridgeModule.h>
44
#import <ReactCommon/CallInvoker.h>
5+
#import <React/RCTInvalidating.h>
6+
7+
#ifdef RCT_NEW_ARCH_ENABLED
8+
#import <BabylonModuleSpec/BabylonModuleSpec.h>
9+
#endif
510

611
#import <Foundation/Foundation.h>
712

8-
@interface RCTBridge (RCTTurboModule)
13+
@interface RCTBridge (CallInvoker)
914
- (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker;
1015
@end
1116

12-
@interface BabylonModule : NSObject <RCTBridgeModule>
17+
@interface BabylonModule : NSObject <RCTBridgeModule, RCTInvalidating>
18+
@end
19+
20+
#ifdef RCT_NEW_ARCH_ENABLED
21+
@interface BabylonModule () <NativeBabylonModuleSpec>
1322
@end
23+
#endif // RCT_NEW_ARCH_ENABLED
1424

1525
@implementation BabylonModule
1626

@@ -32,4 +42,14 @@ @implementation BabylonModule
3242
});
3343
}
3444

45+
- (void)invalidate {
46+
[BabylonNativeInterop invalidate];
47+
}
48+
49+
#ifdef RCT_NEW_ARCH_ENABLED
50+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
51+
return std::make_shared<facebook::react::NativeBabylonModuleSpecJSI>(params);
52+
}
53+
#endif // RCT_NEW_ARCH_ENABLED
54+
3555
@end

Modules/@babylonjs/react-native-iosandroid/ios/BabylonNativeInterop.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
@interface BabylonNativeInterop : NSObject
77
+ (void)initialize:(RCTBridge*)bridge;
8+
+ (void)invalidate;
89
+ (void)updateView:(MTKView*)mtkView;
910
+ (void)updateMSAA:(NSNumber*)value;
1011
+ (void)renderView;

Modules/@babylonjs/react-native-iosandroid/ios/BabylonNativeInterop.mm

+2-10
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,11 @@ + (void)initialize:(RCTBridge*)bridge {
3737
} };
3838

3939
BabylonNative::Initialize(*GetJSIRuntime(bridge), std::move(jsDispatcher));
40-
41-
[[NSNotificationCenter defaultCenter] removeObserver:self
42-
name:RCTBridgeWillInvalidateModulesNotification
43-
object:bridge.parentBridge];
44-
45-
[[NSNotificationCenter defaultCenter] addObserver:self
46-
selector:@selector(onBridgeWillInvalidate:)
47-
name:RCTBridgeWillInvalidateModulesNotification
48-
object:bridge.parentBridge];
4940
}
5041

5142
// NOTE: This happens during dev mode reload, when the JS engine is being shutdown and restarted.
52-
+ (void)onBridgeWillInvalidate:(NSNotification*)notification
43+
// It's called by RCTInvalidating.
44+
+ (void)invalidate
5345
{
5446
BabylonNative::Deinitialize();
5547
}

0 commit comments

Comments
 (0)