Skip to content

Commit

Permalink
[wip] new arch android
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Sep 25, 2024
1 parent aaed7af commit 8c8cb5b
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Apps/BRNPlayground/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
# Note that this is incompatible with web debugging.
#newArchEnabled=true
newArchEnabled=false
hermesEnabled=true

# Uncomment the line below if building react-native from source
#ANDROID_NDK_VERSION=26.1.10909125
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon Sep 23 14:46:34 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 0 additions & 2 deletions Apps/BRNPlayground/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ require_relative '../node_modules/react-native-permissions/scripts/setup'
workspace 'BRNPlayground.xcworkspace'

options = {
:bridgeless_enabled => true,
:fabric_enabled => true,
:hermes_enabled => true,
}

Expand Down
31 changes: 31 additions & 0 deletions Modules/@babylonjs/react-native-iosandroid/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: 'com.android.library'

if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}

def rootBuildDir = "${rootProject.rootDir}/../../../../Build/Android"
def extractedLibDir = "${rootBuildDir}/lib"

Expand Down Expand Up @@ -77,6 +85,8 @@ android {
defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

versionCode 1
versionName "1.0"
externalNativeBuild {
Expand Down Expand Up @@ -140,6 +150,19 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/fabric/java",
"generated/jni",
"generated/java",
]
} else {
java.srcDirs += ["src/paper/java"]
}
}
}
}

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

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../../react-native/spec")
libraryName = "BabylonModuleSpec"
codegenJavaPackageName = "com.babylonreactnative"
}
}

def configureReactNativePom(def pom) {
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.babylonreactnative;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;

@ReactModule(name = BabylonModule.NAME)
public final class BabylonModule extends NativeBabylonModuleSpec {
static final String NAME = "EngineViewNativeComponent";

BabylonModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@NonNull
@Override
public String getName() {
return BabylonModule.NAME;
}

@Override
public void initialize(Promise promise) {
// this.getReactApplicationContext().runOnJSQueueThread(() -> {
// BabylonNativeInterop.initialize(this.getReactApplicationContext());
// promise.resolve(null);
// });
}

@Override
public void resetView(Promise promise) {
// this.getReactApplicationContext().runOnUiQueueThread(() -> {
// BabylonNativeInterop.resetView();
// promise.resolve(null);
// });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.babylonreactnative;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewManagerDelegate;
import com.facebook.react.viewmanagers.EngineViewNativeComponentManagerDelegate;
import com.facebook.react.viewmanagers.EngineViewNativeComponentManagerInterface;

@ReactModule(name = EngineViewManager.NAME)
public final class EngineViewManager extends SimpleViewManager<EngineView> implements EngineViewNativeComponentManagerInterface<EngineView> {
private final ViewManagerDelegate<EngineView> mDelegate;

static final String NAME = "EngineViewNativeComponent";
@NonNull
@Override
public String getName() {
return EngineViewManager.NAME;
}

public EngineViewManager() {
mDelegate = new EngineViewNativeComponentManagerDelegate<>(this);
}

@Nullable
@Override
protected ViewManagerDelegate<EngineView> getDelegate() {
return mDelegate;
}

@NonNull
@Override
protected EngineView createViewInstance(@NonNull ThemedReactContext reactContext) {
return new EngineView(reactContext);
}

// @Override
// public void onDropViewInstance(@NonNull EngineView view) {
// super.onDropViewInstance(view);
// // TODO: Native view specific cleanup
// }

@Override
public void setIsTransparent(EngineView view, boolean value) {
view.setIsTransparent(value);
}

@Override
public void setAntiAliasing(EngineView view, int value) {
view.setAntiAliasing(value);
}

@Override
public void setAndroidView(EngineView view, @Nullable String value) {
view.setAndroidView(value);
}

@Override
public void takeSnapshot(EngineView view) {
view.takeSnapshot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;

public final class BabylonNativeInterop {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package com.babylonreactnative;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.facebook.react.BaseReactPackage;
import com.facebook.react.ReactPackage;
import com.facebook.react.TurboReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.facebook.react.uimanager.ViewManager;

public class BabylonPackage implements ReactPackage {
@NonNull
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new BabylonModule(reactContext));
}

@NonNull
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Arrays.<ViewManager>asList(new EngineViewManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class EngineViewManager extends SimpleViewManager<EngineView> {
@NonNull
@Override
public String getName() {
return "EngineView";
return "EngineViewNativeComponent";
}

@ReactProp(name = "isTransparent")
Expand Down
5 changes: 2 additions & 3 deletions Modules/@babylonjs/react-native/EngineView.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { Component, FunctionComponent, SyntheticEvent, useCallback, useEffect, useState, useRef, useMemo } from 'react';
import { ViewProps, View, Text, findNodeHandle, UIManager } from 'react-native';
import { View, Text, findNodeHandle, UIManager } from 'react-native';
import { Camera, SceneInstrumentation } from '@babylonjs/core';
import { ReactNativeEngine } from './ReactNativeEngine';
import { useModuleInitializer, useRenderLoop } from './NativeEngineHook';
import { NativeEngineViewProps, NativeEngineView } from './NativeEngineView';

export interface EngineViewProps extends ViewProps {
export interface EngineViewProps extends NativeEngineViewProps {
camera?: Camera;
displayFrameRate?: boolean;
isTransparent?: boolean;
androidView?: "TextureView" | "SurfaceView" | "SurfaceViewZTopMost" | "SurfaceViewZMediaOverlay";
antiAliasing?: 0 | 1 | 2 | 4 | 8 | 16;
onInitialized?: (view: EngineViewCallbacks) => void;
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/@babylonjs/react-native/NativeEngineView.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import EngineView from './spec/EngineViewNativeComponent'
import EngineView, {NativeProps} from './spec/EngineViewNativeComponent'

export { EngineView as NativeEngineView };
export type { NativeProps as NativeEngineViewProps };
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface NativeProps extends ViewProps {
isTransparent?: WithDefault<boolean, false>;
antiAliasing?: Int32;
onSnapshotDataReturned?: DirectEventHandler<null>;
// Android only
androidView?: string;
}

type EngineViewViewType = HostComponent<NativeProps>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export interface Spec extends TurboModule {
resetView(): Promise<void>;
}

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

0 comments on commit 8c8cb5b

Please sign in to comment.