Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions react-native-harmony/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
7 changes: 7 additions & 0 deletions react-native-harmony/harmony/rn_babylon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
./BuildProfile.ets
17 changes: 17 additions & 0 deletions react-native-harmony/harmony/rn_babylon/BuildProfile.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Use these variables when you tailor your ArkTS code. They must be of the const type.
*/
export const HAR_VERSION = '0.0.1-0.0.1';
export const BUILD_MODE_NAME = 'debug';
export const DEBUG = true;
export const TARGET_NAME = 'default';

/**
* BuildProfile Class is used only for compatibility purposes.
*/
export default class BuildProfile {
static readonly HAR_VERSION = HAR_VERSION;
static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
static readonly DEBUG = DEBUG;
static readonly TARGET_NAME = TARGET_NAME;
}
12 changes: 12 additions & 0 deletions react-native-harmony/harmony/rn_babylon/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"apiType": 'stageMode',
"targets": [
{
"name": "default",
"runtimeOS": "HarmonyOS"
},
{
"name": "ohosTest",
}
]
}
2 changes: 2 additions & 0 deletions react-native-harmony/harmony/rn_babylon/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
export { harTasks } from '@ohos/hvigor-ohos-plugin';
2 changes: 2 additions & 0 deletions react-native-harmony/harmony/rn_babylon/index.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./ts"
// export * from "./src/main/ets/NativeEngineView"
20 changes: 20 additions & 0 deletions react-native-harmony/harmony/rn_babylon/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions react-native-harmony/harmony/rn_babylon/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
license: '',
devDependencies: {},
author: '',
name: "bl",
description: '',
type: 'module',
version: '0.0.1-0.0.1',
main: 'index.ets',
dependencies: {
"@rnoh/react-native-openharmony": "^0.72.58",
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* MIT License
*
* Copyright (C) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef RN_BABYLON_SRC_MAIN_CPP_BABYLONPACKAGE_H
#define RN_BABYLON_SRC_MAIN_CPP_BABYLONPACKAGE_H

#include "RnohReactNativeHarmonyBabylonPackage.h"

namespace rnoh {
class BabylonPackage : public RnohReactNativeHarmonyBabylonPackage {
using Super = RnohReactNativeHarmonyBabylonPackage;
using Super::Super;
};
} // namespace rnoh

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

# Configure Babylon Native to use JSI
set(NAPI_JAVASCRIPT_ENGINE "JSI" CACHE STRING "The JavaScript engine to power N-API" FORCE)

set(BABYLON_REACT_NATIVE_SHARED_DIR "${NODE_MODULES}/@react-native-oh-tpl/babylonjs-react-native/shared")

include(${BABYLON_REACT_NATIVE_SHARED_DIR}/CMakeLists.txt)

add_subdirectory("${BABYLON_REACT_NATIVE_SHARED_DIR}" ./babaylonjsshared)
add_subdirectory(${babylonnative_SOURCE_DIR} ./babylonnaitve)

file(GLOB_RECURSE rnoh_babylon_SRC CONFIGURE_DEPENDS *.cpp)
add_library(rnoh_babylon SHARED ${rnoh_babylon_SRC}
${SHARED_SOURCES}
)

target_include_directories(rnoh_babylon PUBLIC
${SHARED_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR})

find_library(
EGL-lib
EGL
)

find_library(
GLES-lib
GLESv3
)

target_link_libraries(rnoh_babylon PUBLIC rnoh
libace_ndk.z.so
libhilog_ndk.z.so
libnative_drawing.so
libnative_window.so
libffrt.z.so
${EGL-lib} ${GLES-lib}
NativeInput
NativeOptimizations
GraphicsDevice
NativeTracing
NativeCamera
NativeXr
NativeCapture
NativeEngine
Window
Canvas
XMLHttpRequest
JsRuntime
pixelmap
image_packer
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* MIT License
*
* Copyright (C) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef RN_BABYLON_SRC_MAIN_CPP_COMPONENTDESCRIPTORS_H
#define RN_BABYLON_SRC_MAIN_CPP_COMPONENTDESCRIPTORS_H

#include "ShadowNodes.h"
#include <react/renderer/core/ConcreteComponentDescriptor.h>

namespace facebook {
namespace react {
using EngineViewComponentDescriptor = ConcreteComponentDescriptor<EngineViewShadowNode>;
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* MIT License
*
* Copyright (C) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "EventEmitters.h"

namespace facebook {
namespace react {
void EngineViewEventEmitter::onSnapshotDataReturned(SnapshotEventData event) const {
dispatchEvent("snapshotDataReturned", [event = std::move(event)](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "data", event.data);
return payload;
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* MIT License
*
* Copyright (C) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef RN_BABYLON_SRC_MAIN_CPP_EVENTEMITTERS_H
#define RN_BABYLON_SRC_MAIN_CPP_EVENTEMITTERS_H

#include <jsi/jsi.h>
#include <react/renderer/components/view/ViewEventEmitter.h>

namespace facebook {
namespace react {
class JSI_EXPORT EngineViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;

struct SnapshotEventData {
std::string data;
};
void onSnapshotDataReturned(SnapshotEventData value) const;
};
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* MIT License
*
* Copyright (C) 2025 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef RN_BABYLON_SRC_MAIN_CPP_NATIVEENGINEVIEWJSIBINDER_H
#define RN_BABYLON_SRC_MAIN_CPP_NATIVEENGINEVIEWJSIBINDER_H

#include "RNOH/BaseComponentJSIBinder.h"
#include "RNOHCorePackage/ComponentBinders/ViewComponentJSIBinder.h"

namespace rnoh {
class NativeEngineViewJSIBinder : public ViewComponentJSIBinder {
protected:
facebook::jsi::Object createNativeProps(facebook::jsi::Runtime &rt) override {
auto object = ViewComponentJSIBinder::createNativeProps(rt);
object.setProperty(rt, "isTransparent", "boolean");
object.setProperty(rt, "antiAliasing", "number");
object.setProperty(rt, "androidView", "string");
return object;
}

facebook::jsi::Object createCommands(facebook::jsi::Runtime &rt) override {
auto commands = ViewComponentJSIBinder::createCommands(rt);
commands.setProperty(rt, "takeSnapshot", "takeSnapshot");
return commands;
}

facebook::jsi::Object createBubblingEventTypes(facebook::jsi::Runtime &rt) override {
facebook::jsi::Object events(rt);
return events;
}

facebook::jsi::Object createDirectEventTypes(facebook::jsi::Runtime &rt) override {
facebook::jsi::Object events(rt);
events.setProperty(rt, "topSnapshotDataReturned", createDirectEvent(rt, "onSnapshotDataReturned"));
return events;
}
};
}

#endif
Loading