Skip to content

Commit 3ebf766

Browse files
committed
[wip] new arch android
1 parent 315f635 commit 3ebf766

File tree

14 files changed

+161
-10
lines changed

14 files changed

+161
-10
lines changed

Apps/BRNPlayground/android/gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
4040
# to write custom TurboModules/Fabric components OR use libraries that
4141
# are providing them.
4242
# Note that this is incompatible with web debugging.
43-
#newArchEnabled=true
43+
newArchEnabled=false
44+
hermesEnabled=true
4445

4546
# Uncomment the line below if building react-native from source
4647
#ANDROID_NDK_VERSION=26.1.10909125

Apps/BRNPlayground/android/gradle/wrapper/gradle-wrapper.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
#Mon Sep 23 14:46:34 CEST 2024
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
45
networkTimeout=10000
56
validateDistributionUrl=true
67
zipStoreBase=GRADLE_USER_HOME

Apps/BRNPlayground/ios/Podfile

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

77
options = {
8-
:bridgeless_enabled => true,
9-
:fabric_enabled => true,
108
:hermes_enabled => true,
119
}
1210

Modules/@babylonjs/react-native-iosandroid/android/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ def safeExtGet(prop, fallback) {
2020
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
2121
}
2222

23+
def isNewArchitectureEnabled() {
24+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
25+
}
26+
2327
apply plugin: 'com.android.library'
2428

29+
if (isNewArchitectureEnabled()) {
30+
apply plugin: 'com.facebook.react'
31+
}
32+
2533
def rootBuildDir = "${rootProject.rootDir}/../../../../Build/Android"
2634
def extractedLibDir = "${rootBuildDir}/lib"
2735

@@ -77,6 +85,8 @@ android {
7785
defaultConfig {
7886
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
7987
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
88+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
89+
8090
versionCode 1
8191
versionName "1.0"
8292
externalNativeBuild {
@@ -140,6 +150,19 @@ android {
140150
sourceCompatibility JavaVersion.VERSION_1_8
141151
targetCompatibility JavaVersion.VERSION_1_8
142152
}
153+
sourceSets {
154+
main {
155+
if (isNewArchitectureEnabled()) {
156+
java.srcDirs += [
157+
"src/fabric/java",
158+
"generated/jni",
159+
"generated/java",
160+
]
161+
} else {
162+
java.srcDirs += ["src/paper/java"]
163+
}
164+
}
165+
}
143166
}
144167

145168
repositories {
@@ -157,6 +180,14 @@ dependencies {
157180
extractLibs 'com.facebook.fbjni:fbjni:0.3.0', 'com.google.ar:core:1.22.0'
158181
}
159182

183+
if (isNewArchitectureEnabled()) {
184+
react {
185+
jsRootDir = file("../../react-native/spec")
186+
libraryName = "BabylonModuleSpec"
187+
codegenJavaPackageName = "com.babylonreactnative"
188+
}
189+
}
190+
160191
def configureReactNativePom(def pom) {
161192
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
162193

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.babylonreactnative;
2+
3+
import androidx.annotation.NonNull;
4+
5+
import com.facebook.react.bridge.Promise;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.module.annotations.ReactModule;
8+
9+
@ReactModule(name = BabylonModule.NAME)
10+
public final class BabylonModule extends NativeBabylonModuleSpec {
11+
static final String NAME = "EngineViewNativeComponent";
12+
13+
BabylonModule(ReactApplicationContext reactContext) {
14+
super(reactContext);
15+
}
16+
17+
@NonNull
18+
@Override
19+
public String getName() {
20+
return BabylonModule.NAME;
21+
}
22+
23+
@Override
24+
public void initialize(Promise promise) {
25+
// this.getReactApplicationContext().runOnJSQueueThread(() -> {
26+
// BabylonNativeInterop.initialize(this.getReactApplicationContext());
27+
// promise.resolve(null);
28+
// });
29+
}
30+
31+
@Override
32+
public void resetView(Promise promise) {
33+
// this.getReactApplicationContext().runOnUiQueueThread(() -> {
34+
// BabylonNativeInterop.resetView();
35+
// promise.resolve(null);
36+
// });
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.babylonreactnative;
2+
3+
import android.view.View;
4+
5+
import androidx.annotation.NonNull;
6+
import androidx.annotation.Nullable;
7+
8+
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.module.annotations.ReactModule;
10+
import com.facebook.react.uimanager.SimpleViewManager;
11+
import com.facebook.react.uimanager.ThemedReactContext;
12+
import com.facebook.react.uimanager.ViewManagerDelegate;
13+
import com.facebook.react.viewmanagers.EngineViewNativeComponentManagerDelegate;
14+
import com.facebook.react.viewmanagers.EngineViewNativeComponentManagerInterface;
15+
16+
@ReactModule(name = EngineViewManager.NAME)
17+
public final class EngineViewManager extends SimpleViewManager<EngineView> implements EngineViewNativeComponentManagerInterface<EngineView> {
18+
private final ViewManagerDelegate<EngineView> mDelegate;
19+
20+
static final String NAME = "EngineViewNativeComponent";
21+
@NonNull
22+
@Override
23+
public String getName() {
24+
return EngineViewManager.NAME;
25+
}
26+
27+
public EngineViewManager() {
28+
mDelegate = new EngineViewNativeComponentManagerDelegate<>(this);
29+
}
30+
31+
@Nullable
32+
@Override
33+
protected ViewManagerDelegate<EngineView> getDelegate() {
34+
return mDelegate;
35+
}
36+
37+
@NonNull
38+
@Override
39+
protected EngineView createViewInstance(@NonNull ThemedReactContext reactContext) {
40+
return new EngineView(reactContext);
41+
}
42+
43+
// @Override
44+
// public void onDropViewInstance(@NonNull EngineView view) {
45+
// super.onDropViewInstance(view);
46+
// // TODO: Native view specific cleanup
47+
// }
48+
49+
@Override
50+
public void setIsTransparent(EngineView view, boolean value) {
51+
view.setIsTransparent(value);
52+
}
53+
54+
@Override
55+
public void setAntiAliasing(EngineView view, int value) {
56+
view.setAntiAliasing(value);
57+
}
58+
59+
@Override
60+
public void setAndroidView(EngineView view, @Nullable String value) {
61+
view.setAndroidView(value);
62+
}
63+
64+
@Override
65+
public void takeSnapshot(EngineView view) {
66+
view.takeSnapshot();
67+
}
68+
}

Modules/@babylonjs/react-native-iosandroid/android/src/main/java/com/babylonreactnative/BabylonNativeInterop.java

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.facebook.react.bridge.ActivityEventListener;
1010
import com.facebook.react.bridge.LifecycleEventListener;
1111
import com.facebook.react.bridge.ReactContext;
12+
import com.facebook.react.bridge.RuntimeExecutor;
1213
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
1314

1415
public final class BabylonNativeInterop {

Modules/@babylonjs/react-native-iosandroid/android/src/main/java/com/babylonreactnative/BabylonPackage.java

+11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
package com.babylonreactnative;
22

3+
import androidx.annotation.NonNull;
4+
import androidx.annotation.Nullable;
5+
36
import java.util.Arrays;
7+
import java.util.HashMap;
48
import java.util.List;
9+
import java.util.Map;
510

11+
import com.facebook.react.BaseReactPackage;
612
import com.facebook.react.ReactPackage;
13+
import com.facebook.react.TurboReactPackage;
714
import com.facebook.react.bridge.NativeModule;
815
import com.facebook.react.bridge.ReactApplicationContext;
16+
import com.facebook.react.module.model.ReactModuleInfo;
17+
import com.facebook.react.module.model.ReactModuleInfoProvider;
918
import com.facebook.react.uimanager.ViewManager;
1019

1120
public class BabylonPackage implements ReactPackage {
21+
@NonNull
1222
@Override
1323
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
1424
return Arrays.<NativeModule>asList(new BabylonModule(reactContext));
1525
}
1626

27+
@NonNull
1728
@Override
1829
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
1930
return Arrays.<ViewManager>asList(new EngineViewManager());
+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class EngineViewManager extends SimpleViewManager<EngineView> {
2020
@NonNull
2121
@Override
2222
public String getName() {
23-
return "EngineView";
23+
return "EngineViewNativeComponent";
2424
}
2525

2626
@ReactProp(name = "isTransparent")

Modules/@babylonjs/react-native/EngineView.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import React, { Component, FunctionComponent, SyntheticEvent, useCallback, useEffect, useState, useRef, useMemo } from 'react';
2-
import { ViewProps, View, Text, findNodeHandle, UIManager } from 'react-native';
2+
import { View, Text, findNodeHandle, UIManager } from 'react-native';
33
import { Camera, SceneInstrumentation } from '@babylonjs/core';
44
import { ReactNativeEngine } from './ReactNativeEngine';
55
import { useModuleInitializer, useRenderLoop } from './NativeEngineHook';
66
import { NativeEngineViewProps, NativeEngineView } from './NativeEngineView';
77

8-
export interface EngineViewProps extends ViewProps {
8+
export interface EngineViewProps extends NativeEngineViewProps {
99
camera?: Camera;
1010
displayFrameRate?: boolean;
1111
isTransparent?: boolean;
12-
androidView?: "TextureView" | "SurfaceView" | "SurfaceViewZTopMost" | "SurfaceViewZMediaOverlay";
1312
antiAliasing?: 0 | 1 | 2 | 4 | 8 | 16;
1413
onInitialized?: (view: EngineViewCallbacks) => void;
1514
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import EngineView from './spec/EngineViewNativeComponent'
1+
import EngineView, {NativeProps} from './spec/EngineViewNativeComponent'
22

33
export { EngineView as NativeEngineView };
4+
export type { NativeProps as NativeEngineViewProps };

Modules/@babylonjs/react-native/spec/EngineViewNativeComponent.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface NativeProps extends ViewProps {
1212
isTransparent?: WithDefault<boolean, false>;
1313
antiAliasing?: Int32;
1414
onSnapshotDataReturned?: DirectEventHandler<null>;
15+
// Android only
16+
androidView?: string;
1517
}
1618

1719
type EngineViewViewType = HostComponent<NativeProps>;

Modules/@babylonjs/react-native/spec/NativeBabylonModule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export interface Spec extends TurboModule {
66
resetView(): Promise<void>;
77
}
88

9-
export default TurboModuleRegistry.get<Spec>("BabylonModule");
9+
export default TurboModuleRegistry.getEnforcing<Spec>("BabylonModule");

0 commit comments

Comments
 (0)