@react-native-ohos/slider 5.1.2-rc.1 → 5.1.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +187 -183
- package/COMMITTERS.md +5 -5
- package/LICENSE +8 -8
- package/OAT.xml +72 -72
- package/README.OpenSource +10 -10
- package/README.md +12 -12
- package/babel.config.json +3 -3
- package/dist/Slider.js +1 -1
- package/dist/components/StepNumber.js +1 -1
- package/dist/components/StepsIndicator.js +1 -1
- package/dist/components/TrackMark.js +1 -1
- package/dist/utils/styles.js +1 -1
- package/example/.eslintrc +18 -18
- package/example/.node-version +6 -6
- package/example/.prettierrc.js +7 -7
- package/example/.watchmanconfig +5 -5
- package/example/app.json +3 -3
- package/example/babel.config.js +9 -9
- package/example/contexts.ts +9 -9
- package/example/harmony/AppScope/app.json5 +10 -10
- package/example/harmony/AppScope/resources/base/element/string.json +8 -8
- package/example/harmony/build-profile.template.json5 +35 -35
- package/example/harmony/codelinter.json +32 -32
- package/example/harmony/entry/build-profile.json5 +21 -21
- package/example/harmony/entry/hvigorfile.ts +8 -8
- package/example/harmony/entry/oh-package.json5 +10 -10
- package/example/harmony/entry/src/main/cpp/CMakeLists.txt +41 -41
- package/example/harmony/entry/src/main/cpp/PackageProvider.cpp +16 -16
- package/example/harmony/entry/src/main/ets/RNPackagesFactory.ets +13 -13
- package/example/harmony/entry/src/main/ets/entryability/EntryAbility.ets +27 -27
- package/example/harmony/entry/src/main/ets/pages/Index.ets +125 -125
- package/example/harmony/entry/src/main/ets/pages/SurfaceDeadlockTest.ets +135 -135
- package/example/harmony/entry/src/main/ets/pages/TouchDisplayer.ets +43 -43
- package/example/harmony/entry/src/main/module.json5 +51 -51
- package/example/harmony/entry/src/main/resources/base/element/color.json +7 -7
- package/example/harmony/entry/src/main/resources/base/element/string.json +15 -15
- package/example/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -5
- package/example/harmony/format.ps1 +17 -17
- package/example/harmony/hvigor/hvigor-config.json5 +20 -20
- package/example/harmony/hvigorfile.ts +8 -8
- package/example/harmony/oh-package.json5 +11 -11
- package/example/index.js +10 -10
- package/example/jest.config.js +11 -11
- package/example/metro.config.js +30 -30
- package/example/package.json +58 -58
- package/example/react-native.config.js +11 -11
- package/example/scripts/create-build-profile.js +45 -45
- package/example/src/index.tsx +22 -22
- package/example/tsconfig.json +19 -19
- package/harmony/slider/oh-package.json5 +10 -10
- package/harmony/slider.har +0 -0
- package/package.json +92 -92
- package/react-native.config.js +11 -11
- package/src/RNCSliderNativeComponent.ts +51 -51
- package/src/Slider.tsx +356 -356
- package/src/components/StepNumber.tsx +23 -23
- package/src/components/StepsIndicator.tsx +89 -89
- package/src/components/TrackMark.tsx +59 -59
- package/src/index.ts +9 -9
- package/src/utils/constants.ts +17 -17
- package/src/utils/styles.ts +61 -61
- package/tsconfig.json +23 -23
- package/typings/index.d.ts +214 -214
- package/.github/Examples/Slider-Android-Example.gif +0 -0
- package/.github/Examples/Slider-Web-Example.gif +0 -0
- package/.github/Examples/Slider-Windows-Example.gif +0 -0
- package/.github/Examples/Slider-iOS-Example.gif +0 -0
- package/.github/ISSUE_TEMPLATE/BUG_REPORT.md +0 -38
- package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +0 -14
- package/.github/ISSUE_TEMPLATE/QUESTION.md +0 -9
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -11
- package/.github/workflows/ReactNativeSlider-CI.yml +0 -231
- package/harmony/slider/README.OpenSource +0 -11
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
-
// Use of this source code is governed by a MIT license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
#include "RNOH/PackageProvider.h"
|
|
6
|
-
#include "generated/RNOHGeneratedPackage.h"
|
|
7
|
-
#include "SliderPackage.h"
|
|
8
|
-
|
|
9
|
-
using namespace rnoh;
|
|
10
|
-
|
|
11
|
-
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx)
|
|
12
|
-
{
|
|
13
|
-
return {
|
|
14
|
-
std::make_shared<RNOHGeneratedPackage>(ctx), // generated by codegen v1
|
|
15
|
-
std::make_shared<SliderPackage>(ctx)
|
|
16
|
-
};
|
|
1
|
+
// Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
#include "RNOH/PackageProvider.h"
|
|
6
|
+
#include "generated/RNOHGeneratedPackage.h"
|
|
7
|
+
#include "SliderPackage.h"
|
|
8
|
+
|
|
9
|
+
using namespace rnoh;
|
|
10
|
+
|
|
11
|
+
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx)
|
|
12
|
+
{
|
|
13
|
+
return {
|
|
14
|
+
std::make_shared<RNOHGeneratedPackage>(ctx), // generated by codegen v1
|
|
15
|
+
std::make_shared<SliderPackage>(ctx)
|
|
16
|
+
};
|
|
17
17
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
|
|
9
|
-
|
|
10
|
-
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
|
|
11
|
-
return [
|
|
12
|
-
];
|
|
13
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
|
|
9
|
+
|
|
10
|
+
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
|
|
11
|
+
return [
|
|
12
|
+
];
|
|
13
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {RNAbility} from '@rnoh/react-native-openharmony';
|
|
8
|
-
import { AbilityConstant, Want } from '@kit.AbilityKit';
|
|
9
|
-
|
|
10
|
-
export default class EntryAbility extends RNAbility {
|
|
11
|
-
|
|
12
|
-
onCreate(want: Want) {
|
|
13
|
-
super.onCreate(want)
|
|
14
|
-
this.handleWeChatCallIfNeed(want)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
getPagePath() {
|
|
18
|
-
return 'pages/Index';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
onNewWant(want: Want, _launchParam: AbilityConstant.LaunchParam): void {
|
|
22
|
-
this.handleWeChatCallIfNeed(want)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private handleWeChatCallIfNeed(want: Want) {
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {RNAbility} from '@rnoh/react-native-openharmony';
|
|
8
|
+
import { AbilityConstant, Want } from '@kit.AbilityKit';
|
|
9
|
+
|
|
10
|
+
export default class EntryAbility extends RNAbility {
|
|
11
|
+
|
|
12
|
+
onCreate(want: Want) {
|
|
13
|
+
super.onCreate(want)
|
|
14
|
+
this.handleWeChatCallIfNeed(want)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getPagePath() {
|
|
18
|
+
return 'pages/Index';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onNewWant(want: Want, _launchParam: AbilityConstant.LaunchParam): void {
|
|
22
|
+
this.handleWeChatCallIfNeed(want)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private handleWeChatCallIfNeed(want: Want) {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
AnyJSBundleProvider,
|
|
9
|
-
ComponentBuilderContext,
|
|
10
|
-
FileJSBundleProvider,
|
|
11
|
-
MetroJSBundleProvider,
|
|
12
|
-
ResourceJSBundleProvider,
|
|
13
|
-
RNApp,
|
|
14
|
-
RNOHErrorDialog,
|
|
15
|
-
RNOHLogger,
|
|
16
|
-
TraceJSBundleProviderDecorator,
|
|
17
|
-
RNOHCoreContext
|
|
18
|
-
} from '@rnoh/react-native-openharmony';
|
|
19
|
-
import font from '@ohos.font';
|
|
20
|
-
import { createRNPackages } from '../RNPackagesFactory';
|
|
21
|
-
import { RNCSlider, SLIDER_TYPE } from "@react-native-ohos/slider"
|
|
22
|
-
const arkTsComponentNames: Array<string> = [
|
|
23
|
-
SLIDER_TYPE
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
@Builder
|
|
27
|
-
export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
|
|
28
|
-
// There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
|
|
29
|
-
Stack() {
|
|
30
|
-
if (ctx.componentName === SLIDER_TYPE) {
|
|
31
|
-
RNCSlider({
|
|
32
|
-
ctx: ctx.rnComponentContext,
|
|
33
|
-
tag: ctx.tag,
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
.position({ x: 0, y: 0 })
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* If you want to use custom fonts, you need to register them here.
|
|
45
|
-
* We should support react-native-asset to handle registering fonts automatically.
|
|
46
|
-
*/
|
|
47
|
-
const fonts: font.FontOptions[] = [
|
|
48
|
-
{
|
|
49
|
-
familyName: 'Pacifico-Regular',
|
|
50
|
-
familySrc: '/assets/fonts/Pacifico-Regular.ttf'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
familyName: 'StintUltraCondensed-Regular',
|
|
54
|
-
familySrc: '/assets/fonts/StintUltraCondensed-Regular.ttf'
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
|
|
58
|
-
@Entry
|
|
59
|
-
@Component
|
|
60
|
-
struct Index {
|
|
61
|
-
@StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
|
|
62
|
-
@State shouldShow: boolean = false
|
|
63
|
-
private logger!: RNOHLogger
|
|
64
|
-
bundlePath: string = 'bunlde.harmony.js'
|
|
65
|
-
@State hasBundle: boolean = false
|
|
66
|
-
|
|
67
|
-
aboutToAppear() {
|
|
68
|
-
this.logger = this.rnohCoreContext!.logger.clone("Index")
|
|
69
|
-
const stopTracing = this.logger.clone("aboutToAppear").startTracing()
|
|
70
|
-
for (const customFont of fonts) {
|
|
71
|
-
font.registerFont(customFont)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.shouldShow = true
|
|
75
|
-
stopTracing()
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
onBackPress(): boolean | undefined {
|
|
79
|
-
// NOTE: this is required since `Ability`'s `onBackPressed` function always
|
|
80
|
-
// terminates or puts the app in the background, but we want Ark to ignore it completely
|
|
81
|
-
// when handled by RN
|
|
82
|
-
this.rnohCoreContext!.dispatchBackPress()
|
|
83
|
-
return true
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
build() {
|
|
87
|
-
Column() {
|
|
88
|
-
if (this.rnohCoreContext && this.shouldShow) {
|
|
89
|
-
if (this.rnohCoreContext?.isDebugModeEnabled) {
|
|
90
|
-
RNOHErrorDialog({ ctx: this.rnohCoreContext })
|
|
91
|
-
}
|
|
92
|
-
RNApp({
|
|
93
|
-
rnInstanceConfig: {
|
|
94
|
-
createRNPackages,
|
|
95
|
-
enableNDKTextMeasuring: true,
|
|
96
|
-
enableBackgroundExecutor: false,
|
|
97
|
-
enableCAPIArchitecture: true,
|
|
98
|
-
arkTsComponentNames: arkTsComponentNames,
|
|
99
|
-
},
|
|
100
|
-
initialProps: { "foo": "bar" } as Record<string, string>,
|
|
101
|
-
appKey: "app_name",
|
|
102
|
-
wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
|
|
103
|
-
onSetUp: (rnInstance) => {
|
|
104
|
-
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
|
|
105
|
-
},
|
|
106
|
-
jsBundleProvider: new TraceJSBundleProviderDecorator(
|
|
107
|
-
new AnyJSBundleProvider([
|
|
108
|
-
new MetroJSBundleProvider(),
|
|
109
|
-
// NOTE: to load the bundle from file, place it in
|
|
110
|
-
// `/data/app/el2/100/base/com.rnoh.tester/files/bundle.harmony.js`
|
|
111
|
-
// on your device. The path mismatch is due to app sandboxing on HarmonyOS
|
|
112
|
-
new FileJSBundleProvider('/data/storage/el2/base/files/bundle.harmony.js'),
|
|
113
|
-
// new FileJSBundleProvider(context.filesDir + '/' + this.bundlePath),
|
|
114
|
-
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
|
|
115
|
-
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
|
|
116
|
-
]),
|
|
117
|
-
this.rnohCoreContext.logger),
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
Text("1233333333122 1212323")
|
|
121
|
-
}
|
|
122
|
-
.height('100%')
|
|
123
|
-
.width('100%')
|
|
124
|
-
}
|
|
125
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
AnyJSBundleProvider,
|
|
9
|
+
ComponentBuilderContext,
|
|
10
|
+
FileJSBundleProvider,
|
|
11
|
+
MetroJSBundleProvider,
|
|
12
|
+
ResourceJSBundleProvider,
|
|
13
|
+
RNApp,
|
|
14
|
+
RNOHErrorDialog,
|
|
15
|
+
RNOHLogger,
|
|
16
|
+
TraceJSBundleProviderDecorator,
|
|
17
|
+
RNOHCoreContext
|
|
18
|
+
} from '@rnoh/react-native-openharmony';
|
|
19
|
+
import font from '@ohos.font';
|
|
20
|
+
import { createRNPackages } from '../RNPackagesFactory';
|
|
21
|
+
import { RNCSlider, SLIDER_TYPE } from "@react-native-ohos/slider"
|
|
22
|
+
const arkTsComponentNames: Array<string> = [
|
|
23
|
+
SLIDER_TYPE
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
@Builder
|
|
27
|
+
export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
|
|
28
|
+
// There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
|
|
29
|
+
Stack() {
|
|
30
|
+
if (ctx.componentName === SLIDER_TYPE) {
|
|
31
|
+
RNCSlider({
|
|
32
|
+
ctx: ctx.rnComponentContext,
|
|
33
|
+
tag: ctx.tag,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
.position({ x: 0, y: 0 })
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* If you want to use custom fonts, you need to register them here.
|
|
45
|
+
* We should support react-native-asset to handle registering fonts automatically.
|
|
46
|
+
*/
|
|
47
|
+
const fonts: font.FontOptions[] = [
|
|
48
|
+
{
|
|
49
|
+
familyName: 'Pacifico-Regular',
|
|
50
|
+
familySrc: '/assets/fonts/Pacifico-Regular.ttf'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
familyName: 'StintUltraCondensed-Regular',
|
|
54
|
+
familySrc: '/assets/fonts/StintUltraCondensed-Regular.ttf'
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
@Entry
|
|
59
|
+
@Component
|
|
60
|
+
struct Index {
|
|
61
|
+
@StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
|
|
62
|
+
@State shouldShow: boolean = false
|
|
63
|
+
private logger!: RNOHLogger
|
|
64
|
+
bundlePath: string = 'bunlde.harmony.js'
|
|
65
|
+
@State hasBundle: boolean = false
|
|
66
|
+
|
|
67
|
+
aboutToAppear() {
|
|
68
|
+
this.logger = this.rnohCoreContext!.logger.clone("Index")
|
|
69
|
+
const stopTracing = this.logger.clone("aboutToAppear").startTracing()
|
|
70
|
+
for (const customFont of fonts) {
|
|
71
|
+
font.registerFont(customFont)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.shouldShow = true
|
|
75
|
+
stopTracing()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onBackPress(): boolean | undefined {
|
|
79
|
+
// NOTE: this is required since `Ability`'s `onBackPressed` function always
|
|
80
|
+
// terminates or puts the app in the background, but we want Ark to ignore it completely
|
|
81
|
+
// when handled by RN
|
|
82
|
+
this.rnohCoreContext!.dispatchBackPress()
|
|
83
|
+
return true
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
build() {
|
|
87
|
+
Column() {
|
|
88
|
+
if (this.rnohCoreContext && this.shouldShow) {
|
|
89
|
+
if (this.rnohCoreContext?.isDebugModeEnabled) {
|
|
90
|
+
RNOHErrorDialog({ ctx: this.rnohCoreContext })
|
|
91
|
+
}
|
|
92
|
+
RNApp({
|
|
93
|
+
rnInstanceConfig: {
|
|
94
|
+
createRNPackages,
|
|
95
|
+
enableNDKTextMeasuring: true,
|
|
96
|
+
enableBackgroundExecutor: false,
|
|
97
|
+
enableCAPIArchitecture: true,
|
|
98
|
+
arkTsComponentNames: arkTsComponentNames,
|
|
99
|
+
},
|
|
100
|
+
initialProps: { "foo": "bar" } as Record<string, string>,
|
|
101
|
+
appKey: "app_name",
|
|
102
|
+
wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
|
|
103
|
+
onSetUp: (rnInstance) => {
|
|
104
|
+
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
|
|
105
|
+
},
|
|
106
|
+
jsBundleProvider: new TraceJSBundleProviderDecorator(
|
|
107
|
+
new AnyJSBundleProvider([
|
|
108
|
+
new MetroJSBundleProvider(),
|
|
109
|
+
// NOTE: to load the bundle from file, place it in
|
|
110
|
+
// `/data/app/el2/100/base/com.rnoh.tester/files/bundle.harmony.js`
|
|
111
|
+
// on your device. The path mismatch is due to app sandboxing on HarmonyOS
|
|
112
|
+
new FileJSBundleProvider('/data/storage/el2/base/files/bundle.harmony.js'),
|
|
113
|
+
// new FileJSBundleProvider(context.filesDir + '/' + this.bundlePath),
|
|
114
|
+
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
|
|
115
|
+
new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
|
|
116
|
+
]),
|
|
117
|
+
this.rnohCoreContext.logger),
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
Text("1233333333122 1212323")
|
|
121
|
+
}
|
|
122
|
+
.height('100%')
|
|
123
|
+
.width('100%')
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
-
* Use of this source code is governed by a MIT license that can be
|
|
4
|
-
* found in the LICENSE file.
|
|
5
|
-
*/
|
|
6
|
-
import { RNInstance, JSBundleProvider, RNAbility, RNSurface } from '@rnoh/react-native-openharmony'
|
|
7
|
-
import { CustomComponentBuilder } from "@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage"
|
|
8
|
-
import { SurfaceConfig2 } from '@rnoh/react-native-openharmony/src/main/ets/RNSurface'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@Component
|
|
12
|
-
export struct SurfaceDeadlockTest {
|
|
13
|
-
public jsBundleProvider: JSBundleProvider | undefined = undefined
|
|
14
|
-
public appKeys: string[] = []
|
|
15
|
-
public numberOfIterations: number = 1
|
|
16
|
-
@BuilderParam public buildCustomComponent!: CustomComponentBuilder
|
|
17
|
-
// -------------------------------------------------------------------------------------------------------------------
|
|
18
|
-
@StorageLink('RNAbility') private rnAbility: RNAbility = {} as RNAbility
|
|
19
|
-
private rnInstance!: RNInstance
|
|
20
|
-
@State private shouldShow: boolean = false
|
|
21
|
-
private shouldDestroyRNInstance: boolean = false
|
|
22
|
-
private cleanUpCallbacks: (() => void)[] = []
|
|
23
|
-
|
|
24
|
-
aboutToAppear() {
|
|
25
|
-
this.getOrCreateRNInstance().then(rnInstance => {
|
|
26
|
-
this.rnInstance = rnInstance
|
|
27
|
-
const jsBundleExecutionStatus = this.rnInstance.getBundleExecutionStatus(this.jsBundleProvider?.getURL())
|
|
28
|
-
if (this.jsBundleProvider && jsBundleExecutionStatus === undefined) {
|
|
29
|
-
this.rnInstance.runJSBundle(this.jsBundleProvider).then(() => {
|
|
30
|
-
this.shouldShow = true
|
|
31
|
-
})
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
}).catch((reason: string | Error) => {
|
|
35
|
-
if (typeof reason === "string")
|
|
36
|
-
this.rnAbility.getLogger().error(reason)
|
|
37
|
-
else if (reason instanceof Error) {
|
|
38
|
-
this.rnAbility.getLogger().error(reason.message)
|
|
39
|
-
} else {
|
|
40
|
-
this.rnAbility.getLogger().error("Fatal exception")
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
aboutToDisappear() {
|
|
46
|
-
if (this.shouldDestroyRNInstance)
|
|
47
|
-
this.rnAbility.destroyAndUnregisterRNInstance(this.rnInstance)
|
|
48
|
-
this.cleanUpCallbacks.forEach(cleanUp => cleanUp())
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private getOrCreateRNInstance(): Promise<RNInstance> {
|
|
52
|
-
return this.rnAbility.createAndRegisterRNInstance({ createRNPackages: () => [] })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
build() {
|
|
56
|
-
Stack() {
|
|
57
|
-
if (this.shouldShow) {
|
|
58
|
-
ForEach(this.appKeys, (appKey: string, idx) => {
|
|
59
|
-
Stack() {
|
|
60
|
-
Blinker({
|
|
61
|
-
minDelayInMs: 1000,
|
|
62
|
-
maxDelayInMs: 2000,
|
|
63
|
-
blinksCount: this.numberOfIterations,
|
|
64
|
-
randomnessPrecisionInMs: 500
|
|
65
|
-
}) {
|
|
66
|
-
RNSurface({
|
|
67
|
-
ctx: this.rnAbility.createRNOHContext({ rnInstance: this.rnInstance }),
|
|
68
|
-
surfaceConfig: {
|
|
69
|
-
initialProps: {},
|
|
70
|
-
appKey: appKey,
|
|
71
|
-
} as SurfaceConfig2,
|
|
72
|
-
buildCustomComponent: this.buildCustomComponent,
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
}.height(`${100 / this.appKeys.length}%`)
|
|
76
|
-
.position({ x: 0, y: `${(idx / this.appKeys.length) * 100}%` })
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
}.width("100%")
|
|
80
|
-
.height("100%")
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
@Component
|
|
86
|
-
struct Blinker {
|
|
87
|
-
public minDelayInMs: number = 0
|
|
88
|
-
public maxDelayInMs: number = 1000
|
|
89
|
-
public blinksCount: number = 0
|
|
90
|
-
public randomnessPrecisionInMs: number = 250
|
|
91
|
-
@BuilderParam public renderChildren: () => void
|
|
92
|
-
private currentBlinksCount = 0
|
|
93
|
-
@State private isVisible: boolean = false
|
|
94
|
-
private timeout: number = 0
|
|
95
|
-
|
|
96
|
-
aboutToAppear() {
|
|
97
|
-
this.blink(this.minDelayInMs)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
aboutToDisappear() {
|
|
101
|
-
clearTimeout(this.timeout)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private blink(ms: number) {
|
|
105
|
-
this.isVisible = !this.isVisible
|
|
106
|
-
this.currentBlinksCount += 1
|
|
107
|
-
if (this.currentBlinksCount >= this.blinksCount) {
|
|
108
|
-
if (this.timeout) {
|
|
109
|
-
clearTimeout(this.timeout)
|
|
110
|
-
}
|
|
111
|
-
this.isVisible = true
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
this.timeout = setTimeout(() => {
|
|
115
|
-
this.blink(this.getNextDelay())
|
|
116
|
-
}, ms)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private getNextDelay(): number {
|
|
120
|
-
return ((Math.floor(Math.random() * (Number.MAX_VALUE / this.randomnessPrecisionInMs)) * this.randomnessPrecisionInMs) % this.maxDelayInMs) + this.minDelayInMs
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
build() {
|
|
124
|
-
Stack() {
|
|
125
|
-
if (this.isVisible) {
|
|
126
|
-
this.renderChildren()
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved
|
|
3
|
+
* Use of this source code is governed by a MIT license that can be
|
|
4
|
+
* found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
import { RNInstance, JSBundleProvider, RNAbility, RNSurface } from '@rnoh/react-native-openharmony'
|
|
7
|
+
import { CustomComponentBuilder } from "@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage"
|
|
8
|
+
import { SurfaceConfig2 } from '@rnoh/react-native-openharmony/src/main/ets/RNSurface'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@Component
|
|
12
|
+
export struct SurfaceDeadlockTest {
|
|
13
|
+
public jsBundleProvider: JSBundleProvider | undefined = undefined
|
|
14
|
+
public appKeys: string[] = []
|
|
15
|
+
public numberOfIterations: number = 1
|
|
16
|
+
@BuilderParam public buildCustomComponent!: CustomComponentBuilder
|
|
17
|
+
// -------------------------------------------------------------------------------------------------------------------
|
|
18
|
+
@StorageLink('RNAbility') private rnAbility: RNAbility = {} as RNAbility
|
|
19
|
+
private rnInstance!: RNInstance
|
|
20
|
+
@State private shouldShow: boolean = false
|
|
21
|
+
private shouldDestroyRNInstance: boolean = false
|
|
22
|
+
private cleanUpCallbacks: (() => void)[] = []
|
|
23
|
+
|
|
24
|
+
aboutToAppear() {
|
|
25
|
+
this.getOrCreateRNInstance().then(rnInstance => {
|
|
26
|
+
this.rnInstance = rnInstance
|
|
27
|
+
const jsBundleExecutionStatus = this.rnInstance.getBundleExecutionStatus(this.jsBundleProvider?.getURL())
|
|
28
|
+
if (this.jsBundleProvider && jsBundleExecutionStatus === undefined) {
|
|
29
|
+
this.rnInstance.runJSBundle(this.jsBundleProvider).then(() => {
|
|
30
|
+
this.shouldShow = true
|
|
31
|
+
})
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}).catch((reason: string | Error) => {
|
|
35
|
+
if (typeof reason === "string")
|
|
36
|
+
this.rnAbility.getLogger().error(reason)
|
|
37
|
+
else if (reason instanceof Error) {
|
|
38
|
+
this.rnAbility.getLogger().error(reason.message)
|
|
39
|
+
} else {
|
|
40
|
+
this.rnAbility.getLogger().error("Fatal exception")
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
aboutToDisappear() {
|
|
46
|
+
if (this.shouldDestroyRNInstance)
|
|
47
|
+
this.rnAbility.destroyAndUnregisterRNInstance(this.rnInstance)
|
|
48
|
+
this.cleanUpCallbacks.forEach(cleanUp => cleanUp())
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private getOrCreateRNInstance(): Promise<RNInstance> {
|
|
52
|
+
return this.rnAbility.createAndRegisterRNInstance({ createRNPackages: () => [] })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
build() {
|
|
56
|
+
Stack() {
|
|
57
|
+
if (this.shouldShow) {
|
|
58
|
+
ForEach(this.appKeys, (appKey: string, idx) => {
|
|
59
|
+
Stack() {
|
|
60
|
+
Blinker({
|
|
61
|
+
minDelayInMs: 1000,
|
|
62
|
+
maxDelayInMs: 2000,
|
|
63
|
+
blinksCount: this.numberOfIterations,
|
|
64
|
+
randomnessPrecisionInMs: 500
|
|
65
|
+
}) {
|
|
66
|
+
RNSurface({
|
|
67
|
+
ctx: this.rnAbility.createRNOHContext({ rnInstance: this.rnInstance }),
|
|
68
|
+
surfaceConfig: {
|
|
69
|
+
initialProps: {},
|
|
70
|
+
appKey: appKey,
|
|
71
|
+
} as SurfaceConfig2,
|
|
72
|
+
buildCustomComponent: this.buildCustomComponent,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
}.height(`${100 / this.appKeys.length}%`)
|
|
76
|
+
.position({ x: 0, y: `${(idx / this.appKeys.length) * 100}%` })
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
}.width("100%")
|
|
80
|
+
.height("100%")
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@Component
|
|
86
|
+
struct Blinker {
|
|
87
|
+
public minDelayInMs: number = 0
|
|
88
|
+
public maxDelayInMs: number = 1000
|
|
89
|
+
public blinksCount: number = 0
|
|
90
|
+
public randomnessPrecisionInMs: number = 250
|
|
91
|
+
@BuilderParam public renderChildren: () => void
|
|
92
|
+
private currentBlinksCount = 0
|
|
93
|
+
@State private isVisible: boolean = false
|
|
94
|
+
private timeout: number = 0
|
|
95
|
+
|
|
96
|
+
aboutToAppear() {
|
|
97
|
+
this.blink(this.minDelayInMs)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
aboutToDisappear() {
|
|
101
|
+
clearTimeout(this.timeout)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private blink(ms: number) {
|
|
105
|
+
this.isVisible = !this.isVisible
|
|
106
|
+
this.currentBlinksCount += 1
|
|
107
|
+
if (this.currentBlinksCount >= this.blinksCount) {
|
|
108
|
+
if (this.timeout) {
|
|
109
|
+
clearTimeout(this.timeout)
|
|
110
|
+
}
|
|
111
|
+
this.isVisible = true
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.timeout = setTimeout(() => {
|
|
115
|
+
this.blink(this.getNextDelay())
|
|
116
|
+
}, ms)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private getNextDelay(): number {
|
|
120
|
+
return ((Math.floor(Math.random() * (Number.MAX_VALUE / this.randomnessPrecisionInMs)) * this.randomnessPrecisionInMs) % this.maxDelayInMs) + this.minDelayInMs
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
build() {
|
|
124
|
+
Stack() {
|
|
125
|
+
if (this.isVisible) {
|
|
126
|
+
this.renderChildren()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|