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
22 changes: 4 additions & 18 deletions Example/harmony_use_pushy/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
## 运行harmony_use_pushy项目步骤

### 1.将项目克隆到本地后在项目根目录创建libs文件夹。

### 2.然后将[`rnoh`](https://github.com/bozaigao/rnoh)克隆到libs文件夹中。

说明:rnoh项目基于react-native 0.72.5版本适配,如果使用最新的RN版本可能会报错,项目适配RN新版本请关注[`gitee仓库`](https://gitee.com/openharmony-sig/ohos_react_native/tree/0.72.5-ohos-5.0-release/tester/harmony/react_native_openharmony/src/main)

### 3.进入rnoh项目执行下面命令对rnoh项目依赖的C++库进行初始化;
```
git submodule update --init --recursive
```

### 4. 确保在react-native-update根目录已经执行过yarn submodule命令。
说明:这个命令会在harmony/src/main/cpp目录生成HDiffPatch和lzma的C++模块依赖。

### 5. 在项目根目录执行下面命令安装第三方依赖。
### 1. 在项目根目录执行下面命令安装第三方依赖。
```
yarn install
```

### 6. 在项目根目录执行下面命令生成bundle包文件。
### 2. 在项目根目录执行下面命令生成bundle包文件。
```
yarn build
```
说明:这个命令会在harmony/entry/src/main/resources/rawfile目录生成Hbundle.harmony.js和assets文件,同时会基于该内容在.pushy/output目录生成ppk包。

**注意⚠️**:在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js,不要随意修改包名,因为diff是匹配该包名进行生成的。

### 7. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目
### 3. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目
![image](./sync.png)

### 8 运行效果图
### 4 运行效果图
![image](./demo.png)
4 changes: 0 additions & 4 deletions Example/harmony_use_pushy/harmony/build-profile.json5
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
}
]
},
{
name: 'rnoh',
srcPath: '../libs/rnoh',
},
{
name: 'pushy',
srcPath: '../node_modules/react-native-update/harmony',
Expand Down
2 changes: 1 addition & 1 deletion Example/harmony_use_pushy/harmony/entry/hvigorfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export function generatePushyBuildTime(str?: string) {
export default {
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
}
}
19 changes: 10 additions & 9 deletions Example/harmony_use_pushy/harmony/entry/oh-package-lock.json5

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

2 changes: 1 addition & 1 deletion Example/harmony_use_pushy/harmony/entry/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "",
"license": "",
"dependencies": {
"rnoh": "file:../../libs/rnoh",
"@rnoh/react-native-openharmony": "0.72.38",
"pushy": "file:../../node_modules/react-native-update/harmony"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ cmake_minimum_required(VERSION 3.16)
project(rnapp)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../libs/rnoh/src/main/cpp")
set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
set(LOG_VERBOSITY_LEVEL 1)
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
add_compile_definitions(WITH_HITRACE_SYSTRACE)

add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
add_subdirectory("${RNOH_CPP_DIR}" ./rn)

file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1

add_library(rnoh_app SHARED
${GENERATED_CPP_FILES}
"./PackageProvider.cpp"
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {RNPackageContext, RNPackage} from 'rnoh/ts';
import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
import {PushyPackage} from 'pushy/ts';

export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RNAbility} from 'rnoh/ts';
import {RNAbility} from '@rnoh/react-native-openharmony';

export default class EntryAbility extends RNAbility {
getPagePath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh';
import { ComponentBuilderContext, RNOHCoreContext,RNAbility } from '@rnoh/react-native-openharmony';
import {
RNApp,
RNAbility,
AnyJSBundleProvider,
ResourceJSBundleProvider,
TraceJSBundleProviderDecorator,
} from 'rnoh'
} from '@rnoh/react-native-openharmony'
import { createRNPackages } from '../RNPackagesFactory'
import preferences from '@ohos.data.preferences';

@Builder
export function CustomComponentBuilder(ctx: ComponentBuilderContext) {
const arkTsComponentNames: Array<string> = [];

@Builder
export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
// There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
Stack() {
}
.position({ x: 0, y: 0 })
}


const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)

@Entry
@Component
struct Index {
@StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined
@StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
@State shouldShow: boolean = false
@State message: string = 'Hello World';

aboutToAppear(): void {
this.shouldShow = true
Expand All @@ -30,28 +36,37 @@ struct Index {
// NOTE: this is required since `Ability`'s `onBackPressed` function always
// terminates or puts the app in the background, but we want Ark to ignore it completely
// when handled by RN
return this.rnAbility?.onBackPress();
this.rnohCoreContext!.dispatchBackPress()

// this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
return true
}

build() {
Column() {
if (this.rnAbility && this.shouldShow) {
if (this.rnohCoreContext && this.shouldShow) {
RNApp({
rnInstanceConfig: { createRNPackages },
rnInstanceConfig: {
createRNPackages,
enableNDKTextMeasuring: true,
enableBackgroundExecutor: false,
enableCAPIArchitecture: true,
arkTsComponentNames: arkTsComponentNames,
},
initialProps: { "foo": "bar" } as Record<string, string>,
appKey: "harmony_use_pushy",
buildCustomComponent: CustomComponentBuilder,
wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
onSetUp: (rnInstance) => {
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
},
jsBundleProvider: new TraceJSBundleProviderDecorator(
new AnyJSBundleProvider([
// MetroJSBundleProvider.fromServerIp('127.0.0.1'),
// new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'hermes_bundle.hbc'),
new FileJSBundleProvider(this.rnAbility.context),
new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'bundle.harmony.js')
// new ResourceJSBundleProvider(rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
new FileJSBundleProvider(this.rnohCoreContext.uiAbilityContext),
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
]),
this.rnAbility.getLogger()),
this.rnohCoreContext.logger),
})
}
}
Expand Down
Loading