mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-09 03:35:14 +08:00
react-native-pushy适配harmony (#461)
* init * update * udpate * update * update * update * add pushy build time logic
This commit is contained in:
1
Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore
vendored
Normal file
1
Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jsbundle.h
|
@@ -0,0 +1,15 @@
|
||||
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_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
|
||||
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
|
||||
|
||||
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
|
||||
add_library(rnoh_app SHARED
|
||||
"./PackageProvider.cpp"
|
||||
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
|
||||
)
|
||||
target_link_libraries(rnoh_app PUBLIC rnoh)
|
||||
target_link_libraries(rnoh_app PUBLIC rnoh_pushy)
|
@@ -0,0 +1,9 @@
|
||||
#include "RNOH/PackageProvider.h"
|
||||
#include "PushyPackage.h"
|
||||
using namespace rnoh;
|
||||
|
||||
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
|
||||
return {
|
||||
std::make_shared<PushyPackage>(ctx)
|
||||
};
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
import type {RNPackageContext, RNPackage} from 'rnoh/ts';
|
||||
import {PushyPackage} from 'pushy/ts';
|
||||
|
||||
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
|
||||
return [new PushyPackage(ctx)];
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import {RNAbility} from 'rnoh/ts';
|
||||
|
||||
export default class EntryAbility extends RNAbility {
|
||||
getPagePath() {
|
||||
return 'pages/Index';
|
||||
}
|
||||
|
||||
shouldCleanUpRNInstance__hack() {
|
||||
return true // Used by RNOH devs. If set to true, the app may crash.
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
|
||||
|
||||
export default class EntryBackupAbility extends BackupExtensionAbility {
|
||||
async onBackup() {
|
||||
hilog.info(0x0000, 'testTag', 'onBackup ok');
|
||||
}
|
||||
|
||||
async onRestore(bundleVersion: BundleVersion) {
|
||||
hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
|
||||
import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh';
|
||||
import {
|
||||
RNApp,
|
||||
RNAbility,
|
||||
AnyJSBundleProvider,
|
||||
ResourceJSBundleProvider,
|
||||
TraceJSBundleProviderDecorator,
|
||||
} from 'rnoh'
|
||||
import { createRNPackages } from '../RNPackagesFactory'
|
||||
|
||||
@Builder
|
||||
export function CustomComponentBuilder(ctx: ComponentBuilderContext) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined
|
||||
@State shouldShow: boolean = false
|
||||
@State message: string = 'Hello World';
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.shouldShow = true
|
||||
}
|
||||
|
||||
onBackPress(): boolean | undefined {
|
||||
// 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();
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
if (this.rnAbility && this.shouldShow) {
|
||||
RNApp({
|
||||
rnInstanceConfig: { createRNPackages },
|
||||
initialProps: { "foo": "bar" } as Record<string, string>,
|
||||
appKey: "harmony_use_pushy",
|
||||
buildCustomComponent: CustomComponentBuilder,
|
||||
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')
|
||||
]),
|
||||
this.rnAbility.getLogger()),
|
||||
})
|
||||
}
|
||||
}
|
||||
.height('100%')
|
||||
.width('100%')
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:layered_image",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
{
|
||||
"name": "EntryBackupAbility",
|
||||
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
|
||||
"type": "backup",
|
||||
"exported": false,
|
||||
"metadata": [
|
||||
{
|
||||
"name": "ohos.extension.backup",
|
||||
"resource": "$profile:backup_config"
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.WRITE_MEDIA",
|
||||
"reason": "$string:reason_write_media",
|
||||
"usedScene": {
|
||||
"when": "always",
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.READ_MEDIA",
|
||||
"reason": "$string:reason_read_media",
|
||||
"usedScene": {
|
||||
"when": "always",
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.INTERNET"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "Access_location",
|
||||
"value": "access location"
|
||||
},
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "reason_write_media",
|
||||
"value": "Write files to internal storage"
|
||||
},
|
||||
{
|
||||
"name": "reason_read_media",
|
||||
"value": "Read files to internal storage"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"layered-image":
|
||||
{
|
||||
"background" : "$media:background",
|
||||
"foreground" : "$media:foreground"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"allowToBackupRestore": true
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
File diff suppressed because one or more lines are too long
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "模块描述"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user