@react-native-ohos/react-native-background-timer 2.4.2-rc.1 → 2.5.0-rc.1

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/COMMITTERS.md +0 -4
  3. package/OAT.xml +3 -1
  4. package/README.md +1 -1
  5. package/example/.eslintrc +18 -0
  6. package/example/.node-version +6 -0
  7. package/example/.prettierrc.js +12 -0
  8. package/example/.watchmanconfig +6 -0
  9. package/example/app.json +4 -0
  10. package/example/babel.config.js +10 -0
  11. package/example/contexts.ts +8 -0
  12. package/example/harmony/AppScope/app.json5 +10 -0
  13. package/example/harmony/AppScope/resources/base/element/string.json +8 -0
  14. package/example/harmony/AppScope/resources/base/media/app_icon.png +0 -0
  15. package/example/harmony/build-profile.template.json5 +40 -0
  16. package/example/harmony/codelinter.json +32 -0
  17. package/example/harmony/entry/build-profile.json5 +19 -0
  18. package/example/harmony/entry/hvigorfile.ts +9 -0
  19. package/example/harmony/entry/oh-package.json5 +11 -0
  20. package/example/harmony/entry/src/main/cpp/CMakeLists.txt +34 -0
  21. package/example/harmony/entry/src/main/cpp/PackageProvider.cpp +19 -0
  22. package/example/harmony/entry/src/main/ets/RNPackagesFactory.ets +15 -0
  23. package/example/harmony/entry/src/main/ets/assets/fonts/Pacifico-Regular.ttf +0 -0
  24. package/example/harmony/entry/src/main/ets/assets/fonts/StintUltraCondensed-Regular.ttf +0 -0
  25. package/example/harmony/entry/src/main/ets/entryability/EntryAbility.ets +19 -0
  26. package/example/harmony/entry/src/main/ets/pages/Index.ets +118 -0
  27. package/example/harmony/entry/src/main/ets/pages/SurfaceDeadlockTest.ets +135 -0
  28. package/example/harmony/entry/src/main/ets/pages/TouchDisplayer.ets +43 -0
  29. package/example/harmony/entry/src/main/module.json5 +52 -0
  30. package/example/harmony/entry/src/main/resources/base/element/color.json +8 -0
  31. package/example/harmony/entry/src/main/resources/base/element/string.json +16 -0
  32. package/example/harmony/entry/src/main/resources/base/media/icon.png +0 -0
  33. package/example/harmony/entry/src/main/resources/base/profile/main_pages.json +5 -0
  34. package/example/harmony/entry/src/main/resources/rawfile/1.txt +1 -0
  35. package/example/harmony/hvigor/hvigor-config.json5 +21 -0
  36. package/example/harmony/hvigorfile.ts +8 -0
  37. package/example/harmony/oh-package.json5 +12 -0
  38. package/example/index.js +10 -0
  39. package/example/jest.config.js +10 -0
  40. package/example/metro.config.js +29 -0
  41. package/example/package.json +66 -0
  42. package/example/react-native.config.js +10 -0
  43. package/example/src/BackgroundTimerDemo.tsx +166 -0
  44. package/harmony/background_timer/hvigorfile.ts +6 -6
  45. package/harmony/background_timer/oh-package.json5 +10 -10
  46. package/harmony/background_timer/src/main/cpp/CMakeLists.txt +13 -13
  47. package/harmony/background_timer/src/main/cpp/generated/RNOH/generated/turbo_modules/BackgroundTimerTurboModule.cpp +21 -21
  48. package/harmony/background_timer/src/main/cpp/generated/RNOH/generated/turbo_modules/BackgroundTimerTurboModule.h +16 -16
  49. package/harmony/background_timer/src/main/ets/generated/components/ts.ts +5 -5
  50. package/harmony/background_timer/src/main/ets/generated/index.ets +5 -5
  51. package/harmony/background_timer/src/main/ets/generated/ts.ts +6 -6
  52. package/harmony/background_timer/src/main/ets/generated/turboModules/BackgroundTimerTurboModule.ts +18 -18
  53. package/harmony/background_timer/src/main/ets/generated/turboModules/ts.ts +5 -5
  54. package/harmony/background_timer/src/main/resources/base/element/string.json +8 -8
  55. package/harmony/background_timer/src/main/resources/en_US/element/string.json +8 -8
  56. package/harmony/background_timer/src/main/resources/zh_CN/element/string.json +8 -8
  57. package/harmony/background_timer.har +0 -0
  58. package/index.js +111 -111
  59. package/package.json +6 -8
  60. package/react-native-background-timer.podspec +0 -24
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## v2.5.0-rc.1
4
+ - pre-release version 2.5.0-rc.1
5
+
6
+ ## 2.4.2-rc.3
7
+ - 更新组织名为 @react-native-ohos
8
+ - 移除 codegenConfig 依赖,并将代码生成逻辑集成到库内部
9
+
package/COMMITTERS.md CHANGED
@@ -3,8 +3,4 @@
3
3
  ### 以下是此项目的committer人员
4
4
  不区分先后顺序
5
5
 
6
- - [MaDiXin](https://gitee.com/MaDiXin)
7
6
  - [xiafeng_xf_admin](https://gitee.com/xiafeng_xf_admin)
8
- - [ChenLixi](https://gitee.com/Louis-C7)
9
- - [LinJiacheng](https://gitee.com/LLLLLLin)
10
- - [ZhengJinshou](https://gitee.com/longziz)
package/OAT.xml CHANGED
@@ -50,8 +50,10 @@
50
50
 
51
51
  <filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies">
52
52
  <filteritem type="filename" name="icon.png" desc="项目工程默认图片文件"/>
53
- <filteritem type="filepath" name="AppScope/resources/base/media/app_icon.png" desc="项目工程默认图片文件"/>
53
+ <filteritem type="filepath" name="example/harmony/AppScope/resources/base/media/app_icon.png" desc="项目工程默认图片文件"/>
54
54
  <filteritem type="filepath" name="harmony/background_timer.har" desc="项目打包文件"/>
55
+ <filteritem type="filepath" name="example/harmony/entry/src/main/ets/assets/fonts/Pacifico-Regular.ttf" desc="用于示例工程展现出独特的艺术风格"/>
56
+ <filteritem type="filepath" name="example/harmony/entry/src/main/ets/assets/fonts/StintUltraCondensed-Regular.ttf" desc="用于示例工程展现出独特的艺术风格"/>
55
57
  </filefilter>
56
58
  </filefilterlist>
57
59
  </oatconfig>
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @react-native-ohos/react-native-background-timer
2
2
 
3
- This project is based on [react-native-background-timer](https://github.com/ocetnik/react-native-background-timer)
3
+ This project is based on [react-native-background-timer@2.4.1](https://github.com/ocetnik/react-native-background-timer/tree/v2.4.1)
4
4
 
5
5
  ## Documentation
6
6
 
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ "extends": "@react-native",
8
+ "rules": {
9
+ "react-native/no-inline-styles": "off",
10
+ "react/no-unstable-nested-components": "off",
11
+ "react/react-in-jsx-scope": "off",
12
+ "@typescript-eslint/no-unused-vars": "warn",
13
+ "react-hooks/exhaustive-deps": "off",
14
+ "radix": "off",
15
+ "prettier/prettier": "warn",
16
+ "max-lines": "off"
17
+ }
18
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ 18
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ module.exports = {
7
+ arrowParens: 'avoid',
8
+ bracketSameLine: true,
9
+ bracketSpacing: true,
10
+ singleQuote: true,
11
+ trailingComma: 'all',
12
+ };
@@ -0,0 +1,6 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ {}
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "app_name",
3
+ "displayName": "tester"
4
+ }
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ module.exports = {
7
+ presets: ['module:metro-react-native-babel-preset'],
8
+ plugins: [
9
+ ],
10
+ };
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2024 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 React from 'react';
7
+
8
+ export const AppParamsContext = React.createContext(undefined);
@@ -0,0 +1,10 @@
1
+ {
2
+ "app": {
3
+ "bundleName": "com.harmony.wechat.lib.demo",
4
+ "vendor": "example",
5
+ "versionCode": 1000000,
6
+ "versionName": "1.0.0",
7
+ "icon": "$media:app_icon",
8
+ "label": "$string:app_name"
9
+ }
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "app_name",
5
+ "value": "RN Tester"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "app": {
3
+ "products": [
4
+ {
5
+ "name": 'default',
6
+ "signingConfig": 'default',
7
+ "compileSdkVersion": '5.0.1(13)',
8
+ "compatibleSdkVersion": '5.0.0(12)',
9
+ "runtimeOS": 'HarmonyOS'
10
+ },
11
+ ],
12
+ "buildModeSet": [
13
+ {
14
+ "name": 'debug',
15
+ },
16
+ {
17
+ "name": 'release',
18
+ },
19
+ ],
20
+ "signingConfigs": []
21
+ },
22
+ "modules": [
23
+ {
24
+ "name": 'entry',
25
+ "srcPath": './entry',
26
+ "targets": [
27
+ {
28
+ "name": 'default',
29
+ "applyToProducts": [
30
+ 'default'
31
+ ],
32
+ },
33
+ ],
34
+ },
35
+ {
36
+ "name": "background_timer",
37
+ "srcPath": '../../harmony/background_timer'
38
+ }
39
+ ],
40
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "files": ["**/*.ts", "**/*.ets"],
3
+ "ignore": [
4
+ "**/ohosTest/**/*",
5
+ "**/node_modules/**/*",
6
+ "**/hvigorfile.ts",
7
+ "**/node_modules/**/*",
8
+ "**/oh_modules/**/*",
9
+ "**/build/**/*",
10
+ "**/.preview/**/*"
11
+ ],
12
+ "plugins": ["@typescript-eslint"],
13
+ "ruleSet": [],
14
+ "rules": {
15
+ "@typescript-eslint/await-thenable": "warn",
16
+ "@typescript-eslint/consistent-type-imports": "warn",
17
+ "@typescript-eslint/explicit-function-return-type": "warn",
18
+ "@typescript-eslint/explicit-module-boundary-types": "warn",
19
+ "@typescript-eslint/no-dynamic-delete": "warn",
20
+ "@typescript-eslint/no-explicit-any": "warn",
21
+ "@typescript-eslint/no-for-in-array": "warn",
22
+ "@typescript-eslint/no-this-alias": "warn",
23
+ "@typescript-eslint/no-unnecessary-type-constraint": "warn",
24
+ "@typescript-eslint/no-unsafe-argument": "warn",
25
+ "@typescript-eslint/no-unsafe-assignment": "warn",
26
+ "@typescript-eslint/no-unsafe-call": "warn",
27
+ "@typescript-eslint/no-unsafe-member-access": "warn",
28
+ "@typescript-eslint/no-unsafe-return": "warn",
29
+ "@typescript-eslint/prefer-literal-enum-member": "warn"
30
+ },
31
+ "overrides": []
32
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "apiType": 'stageMode',
3
+ "buildOption": {
4
+ "externalNativeOptions": {
5
+ "path": "./src/main/cpp/CMakeLists.txt",
6
+ "arguments": "",
7
+ "cppFlags": "-s",
8
+ },
9
+ },
10
+ "targets": [
11
+ {
12
+ "name": "default",
13
+ "runtimeOS": "HarmonyOS"
14
+ },
15
+ {
16
+ "name": "ohosTest",
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
9
+ export { hapTasks } from '@ohos/hvigor-ohos-plugin';
@@ -0,0 +1,11 @@
1
+ {
2
+ "license": "ISC",
3
+ "devDependencies": {},
4
+ "name": "entry",
5
+ "description": "example description",
6
+ "version": "1.0.0",
7
+ "dependencies": {
8
+ "@rnoh/react-native-openharmony": "0.72.38",
9
+ "@react-native-ohos/react-native-background-timer": "file:../../node_modules/@react-native-ohos/react-native-background-timer/harmony/background_timer.har",
10
+ }
11
+ }
@@ -0,0 +1,34 @@
1
+ project(rnapp)
2
+ cmake_minimum_required(VERSION 3.4.1)
3
+ set(CMAKE_SKIP_BUILD_RPATH TRUE)
4
+ set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
5
+ set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
6
+ set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
7
+ set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
8
+ set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
9
+ set(LOG_VERBOSITY_LEVEL 1)
10
+ set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
11
+ set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
12
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
13
+
14
+ set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
15
+ add_compile_definitions(WITH_HITRACE_SYSTRACE)
16
+
17
+ add_subdirectory("${RNOH_CPP_DIR}" ./rn)
18
+
19
+ # RNOH_BEGIN: manual_package_linking_1
20
+ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-background-timer/src/main/cpp" ./background_timer)
21
+ # RNOH_END: manual_package_linking_1
22
+
23
+ file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1
24
+
25
+ add_library(rnoh_app SHARED
26
+ ${GENERATED_CPP_FILES}
27
+ "./PackageProvider.cpp"
28
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
29
+ )
30
+ target_link_libraries(rnoh_app PUBLIC rnoh)
31
+
32
+ # RNOH_BEGIN: manual_package_linking_2
33
+ target_link_libraries(rnoh_app PUBLIC rnoh_background_timer)
34
+ # RNOH_END: manual_package_linking_2
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ #include "RNOH/PackageProvider.h"
8
+ #include "generated/RNOHGeneratedPackage.h"
9
+ #include "BackgroundTimerPackage.h"
10
+
11
+ using namespace rnoh;
12
+
13
+ std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx)
14
+ {
15
+ return {
16
+ std::make_shared<RNOHGeneratedPackage>(ctx), // generated by codegen v1
17
+ std::make_shared<BackgroundTimerPackage>(ctx),
18
+ };
19
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ import { BackgroundTimerTurboModulePackage } from '@react-native-ohos/react-native-background-timer/ts';
10
+
11
+ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
12
+ return [
13
+ new BackgroundTimerTurboModulePackage(ctx)
14
+ ];
15
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ }
15
+
16
+ getPagePath() {
17
+ return 'pages/Index';
18
+ }
19
+ }
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+
22
+ const arkTsComponentNames: Array<string> = [
23
+ ];
24
+
25
+ @Builder
26
+ export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
27
+ // There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
28
+ Stack() {
29
+ }
30
+ .position({ x: 0, y: 0 })
31
+
32
+ }
33
+
34
+ const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
35
+
36
+ /**
37
+ * If you want to use custom fonts, you need to register them here.
38
+ * We should support react-native-asset to handle registering fonts automatically.
39
+ */
40
+ const fonts: font.FontOptions[] = [
41
+ {
42
+ familyName: 'Pacifico-Regular',
43
+ familySrc: '/assets/fonts/Pacifico-Regular.ttf'
44
+ },
45
+ {
46
+ familyName: 'StintUltraCondensed-Regular',
47
+ familySrc: '/assets/fonts/StintUltraCondensed-Regular.ttf'
48
+ }
49
+ ]
50
+
51
+ @Entry
52
+ @Component
53
+ struct Index {
54
+ @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
55
+ @State shouldShow: boolean = false
56
+ private logger!: RNOHLogger
57
+ bundlePath: string = 'bunlde.harmony.js'
58
+ @State hasBundle: boolean = false
59
+
60
+ aboutToAppear() {
61
+ this.logger = this.rnohCoreContext!.logger.clone("Index")
62
+ const stopTracing = this.logger.clone("aboutToAppear").startTracing()
63
+ for (const customFont of fonts) {
64
+ font.registerFont(customFont)
65
+ }
66
+
67
+ this.shouldShow = true
68
+ stopTracing()
69
+ }
70
+
71
+ onBackPress(): boolean | undefined {
72
+ // NOTE: this is required since `Ability`'s `onBackPressed` function always
73
+ // terminates or puts the app in the background, but we want Ark to ignore it completely
74
+ // when handled by RN
75
+ this.rnohCoreContext!.dispatchBackPress()
76
+ return true
77
+ }
78
+
79
+ build() {
80
+ Column() {
81
+ if (this.rnohCoreContext && this.shouldShow) {
82
+ if (this.rnohCoreContext?.isDebugModeEnabled) {
83
+ RNOHErrorDialog({ ctx: this.rnohCoreContext })
84
+ }
85
+ RNApp({
86
+ rnInstanceConfig: {
87
+ createRNPackages,
88
+ enableNDKTextMeasuring: true,
89
+ enableBackgroundExecutor: false,
90
+ enableCAPIArchitecture: true,
91
+ arkTsComponentNames: arkTsComponentNames,
92
+ },
93
+ initialProps: { "foo": "bar" } as Record<string, string>,
94
+ appKey: "app_name",
95
+ wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
96
+ onSetUp: (rnInstance) => {
97
+ rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
98
+ },
99
+ jsBundleProvider: new TraceJSBundleProviderDecorator(
100
+ new AnyJSBundleProvider([
101
+ new MetroJSBundleProvider(),
102
+ // NOTE: to load the bundle from file, place it in
103
+ // `/data/app/el2/100/base/com.rnoh.tester/files/bundle.harmony.js`
104
+ // on your device. The path mismatch is due to app sandboxing on HarmonyOS
105
+ new FileJSBundleProvider('/data/storage/el2/base/files/bundle.harmony.js'),
106
+ // new FileJSBundleProvider(context.filesDir + '/' + this.bundlePath),
107
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
108
+ new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
109
+ ]),
110
+ this.rnohCoreContext.logger),
111
+ })
112
+ }
113
+ Text("1233333333122 1212323")
114
+ }
115
+ .height('100%')
116
+ .width('100%')
117
+ }
118
+ }
@@ -0,0 +1,135 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) 2024 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
+ @Component
8
+ export struct TouchDisplayer {
9
+ @State currentTouches: TouchObject[] = []
10
+ @State touchIndicatorOpacity: number = 0
11
+ @BuilderParam buildChildren: () => void
12
+ build() {
13
+ Stack() {
14
+ this.buildChildren()
15
+ ForEach(this.currentTouches, (activeTouch: TouchObject) => {
16
+ Stack() {
17
+ }
18
+ .width(64)
19
+ .height(64)
20
+ .backgroundColor("blue")
21
+ .borderWidth(2)
22
+ .borderColor("white")
23
+ .opacity(this.touchIndicatorOpacity)
24
+ .position({ x: activeTouch.x - 32, y: activeTouch.y - 32 })
25
+ .borderRadius(1000)
26
+ .hitTestBehavior(HitTestMode.Transparent)
27
+ })
28
+ }
29
+ .width("100%")
30
+ .height("100%")
31
+ .hitTestBehavior(HitTestMode.Transparent)
32
+ .onTouch(e => {
33
+ this.currentTouches = e.touches
34
+ this.touchIndicatorOpacity = 0.5
35
+ animateTo({
36
+ duration: 500,
37
+ curve: Curve.Linear,
38
+ }, () => {
39
+ this.touchIndicatorOpacity = 0
40
+ })
41
+ })
42
+ }
43
+ }