1
1
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
2
- import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh';
2
+ import { ComponentBuilderContext, RNOHCoreContext,RNAbility } from '@ rnoh/react-native-openharmony ';
3
3
import {
4
4
RNApp,
5
- RNAbility,
6
5
AnyJSBundleProvider,
7
6
ResourceJSBundleProvider,
8
7
TraceJSBundleProviderDecorator,
9
- } from 'rnoh'
8
+ } from '@ rnoh/react-native-openharmony '
10
9
import { createRNPackages } from '../RNPackagesFactory'
10
+ import preferences from '@ohos.data.preferences';
11
11
12
- @Builder
13
- export function CustomComponentBuilder(ctx: ComponentBuilderContext) {
12
+ const arkTsComponentNames: Array<string> = [];
14
13
14
+ @Builder
15
+ export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
16
+ // There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
17
+ Stack() {
18
+ }
19
+ .position({ x: 0, y: 0 })
15
20
}
16
21
17
22
23
+ const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
24
+
18
25
@Entry
19
26
@Component
20
27
struct Index {
21
- @StorageLink('RNAbility ') private rnAbility: RNAbility | undefined = undefined
28
+ @StorageLink('RNOHCoreContext ') private rnohCoreContext: RNOHCoreContext | undefined = undefined
22
29
@State shouldShow: boolean = false
23
- @State message: string = 'Hello World';
24
30
25
31
aboutToAppear(): void {
26
32
this.shouldShow = true
@@ -30,28 +36,37 @@ struct Index {
30
36
// NOTE: this is required since `Ability`'s `onBackPressed` function always
31
37
// terminates or puts the app in the background, but we want Ark to ignore it completely
32
38
// when handled by RN
33
- return this.rnAbility?.onBackPress();
39
+ this.rnohCoreContext!.dispatchBackPress()
40
+
41
+ // this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
42
+ return true
34
43
}
35
44
36
45
build() {
37
46
Column() {
38
- if (this.rnAbility && this.shouldShow) {
47
+ if (this.rnohCoreContext && this.shouldShow) {
39
48
RNApp({
40
- rnInstanceConfig: { createRNPackages },
49
+ rnInstanceConfig: {
50
+ createRNPackages,
51
+ enableNDKTextMeasuring: true,
52
+ enableBackgroundExecutor: false,
53
+ enableCAPIArchitecture: true,
54
+ arkTsComponentNames: arkTsComponentNames,
55
+ },
41
56
initialProps: { "foo": "bar" } as Record<string, string>,
42
57
appKey: "harmony_use_pushy",
43
- buildCustomComponent: CustomComponentBuilder ,
58
+ wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder ,
44
59
onSetUp: (rnInstance) => {
45
60
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
46
61
},
47
62
jsBundleProvider: new TraceJSBundleProviderDecorator(
48
63
new AnyJSBundleProvider([
49
64
// MetroJSBundleProvider.fromServerIp('127.0.0.1'),
50
- // new ResourceJSBundleProvider(this.rnAbility.context .resourceManager, 'hermes_bundle.hbc'),
51
- new FileJSBundleProvider(this.rnAbility.context ),
52
- new ResourceJSBundleProvider(this.rnAbility.context .resourceManager, 'bundle.harmony.js')
65
+ // new ResourceJSBundleProvider(rnohCoreContext.uiAbilityContext .resourceManager, 'hermes_bundle.hbc'),
66
+ new FileJSBundleProvider(this.rnohCoreContext.uiAbilityContext ),
67
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext .resourceManager, 'bundle.harmony.js')
53
68
]),
54
- this.rnAbility.getLogger() ),
69
+ this.rnohCoreContext.logger ),
55
70
})
56
71
}
57
72
}
0 commit comments