Skip to content
This repository was archived by the owner on Dec 13, 2024. It is now read-only.

Commit f8a882f

Browse files
author
xiawenqiang
committed
feat: 适配harmony平台
1 parent 3730711 commit f8a882f

17 files changed

+370
-3
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ jspm_packages
4141
# Optional REPL history
4242
.node_repl_history
4343
.idea
44+
45+
# Dependency and build
46+
harmony/splash_screen/oh_modules/
47+
package-lock.json
48+
oh-package-lock.json5

harmony/splash_screen.har

5.2 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default class BuildProfile {
2+
static readonly HAR_VERSION = '3.3.0-0.0.1';
3+
static readonly BUILD_MODE_NAME = 'debug';
4+
static readonly DEBUG = true;
5+
}

harmony/splash_screen/Index.ets

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2024 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
export * from "./ts"
26+
export * from "./src/main/ets/SplashScreenView"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"apiType": "stageMode",
3+
"targets": [
4+
{
5+
"name": "default"
6+
}
7+
]
8+
}

harmony/splash_screen/hvigorfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { harTasks } from '@ohos/hvigor-ohos-plugin';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Define project specific obfuscation rules here.
2+
# You can include the obfuscation configuration files in the current module's build-profile.json5.
3+
#
4+
# For more details, see
5+
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
6+
7+
# Obfuscation options:
8+
# -disable-obfuscation: disable all obfuscations
9+
# -enable-property-obfuscation: obfuscate the property names
10+
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
11+
# -compact: remove unnecessary blank spaces and all line feeds
12+
# -remove-log: remove all console.* statements
13+
# -print-namecache: print the name cache that contains the mapping from the old names to new names
14+
# -apply-namecache: reuse the given cache file
15+
16+
# Keep options:
17+
# -keep-property-name: specifies property names that you want to keep
18+
# -keep-global-name: specifies names that you want to keep in the global scope
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"license": "MIT",
3+
"types": "",
4+
"devDependencies": {},
5+
"name": "@react-native-oh-tpl/react-native-splash-screen",
6+
"description": "",
7+
"main": "ts.ts",
8+
"type": "module",
9+
"version": "3.3.0-0.0.1",
10+
"dependencies": {
11+
"@rnoh/react-native-openharmony": "file:../../../react_native_openharmony",
12+
}
13+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2023 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import hilog from '@ohos.hilog';
26+
27+
class Logger {
28+
private domain: number;
29+
private prefix: string;
30+
private format: string = '%{public}s, %{public}s';
31+
private isDebug: boolean;
32+
33+
/**
34+
* constructor.
35+
*
36+
* @param Prefix Identifies the log tag.
37+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
38+
*/
39+
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
40+
this.prefix = prefix;
41+
this.domain = domain;
42+
this.isDebug = isDebug;
43+
}
44+
45+
debug(...args: string[]): void {
46+
if (this.isDebug) {
47+
hilog.debug(this.domain, this.prefix, this.format, args);
48+
}
49+
}
50+
51+
info(...args: string[]): void {
52+
hilog.info(this.domain, this.prefix, this.format, args);
53+
}
54+
55+
warn(...args: string[]): void {
56+
hilog.warn(this.domain, this.prefix, this.format, args);
57+
}
58+
59+
error(...args: string[]): void {
60+
hilog.error(this.domain, this.prefix, this.format, args);
61+
}
62+
}
63+
64+
export default new Logger('SplashScreen', 0xFF00, false)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2024 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
26+
import window from '@ohos.window';
27+
import image from '@ohos.multimedia.image';
28+
import Logger from './Logger';
29+
30+
export class SplashScreen extends TurboModule {
31+
static NAME = "SplashScreen"
32+
33+
// 启动图片
34+
public static startWindowIcon;
35+
36+
// 子窗口
37+
private static splashWindow;
38+
39+
constructor(ctx: TurboModuleContext) {
40+
super(ctx)
41+
}
42+
43+
/**
44+
* 显示启动屏
45+
*
46+
*/
47+
public static async show(abilityContext: any,
48+
windowStage: window.WindowStage,
49+
iconResource: any,
50+
backgroundColor: string,
51+
pageUrl: string) {
52+
// 获取resourceManager资源管理
53+
const context = abilityContext;
54+
const resourceMgr = context.resourceManager
55+
// 获取rawfile文件夹下startIcon的ArrayBuffer
56+
const fileData = await resourceMgr.getMediaContent(iconResource)
57+
const buffer = fileData.buffer
58+
// 创建imageSource
59+
const imageSource = image.createImageSource(buffer)
60+
// 创建PixelMap
61+
const pixelMap = await imageSource.createPixelMap()
62+
this.startWindowIcon = pixelMap;
63+
64+
// 创建子窗口
65+
windowStage.createSubWindow("hiSubWindow", (err, data) => {
66+
if (err.code) {
67+
Logger.debug('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
68+
return;
69+
}
70+
this.splashWindow = data;
71+
72+
// 设置子窗口全屏
73+
this.splashWindow.setFullScreen(true);
74+
75+
// 为子窗口加载对应的目标页面
76+
this.splashWindow.setUIContent(pageUrl, (err) => {
77+
if (err.code) {
78+
Logger.debug('Failed to load the content. Cause:' + JSON.stringify(err));
79+
return;
80+
}
81+
// 显示子窗口
82+
this.splashWindow.showWindow((err) => {
83+
if (err.code) {
84+
Logger.debug('Failed to show the window. Cause: ' + JSON.stringify(err));
85+
return;
86+
}
87+
Logger.debug('Succeeded in showing the window.');
88+
});
89+
this.splashWindow.setWindowBackgroundColor(backgroundColor)
90+
});
91+
})
92+
}
93+
94+
/**
95+
* 关闭启动屏
96+
*/
97+
public hide() {
98+
// 销毁子窗口
99+
SplashScreen.splashWindow.destroyWindow((err) => {
100+
if (err.code) {
101+
Logger.debug('Failed to destroy the window. Cause: ' + JSON.stringify(err));
102+
return;
103+
}
104+
});
105+
}
106+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2024 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import {RNPackage, TurboModuleContext, TurboModulesFactory} from '@rnoh/react-native-openharmony/ts';
26+
import type {TurboModule} from '@rnoh/react-native-openharmony/ts';
27+
import {SplashScreen} from './SplashScreen';
28+
29+
class SplashScreenTurboModulesFactory extends TurboModulesFactory {
30+
createTurboModule(name: string): TurboModule | null {
31+
if (name === SplashScreen.NAME) {
32+
return new SplashScreen(this.ctx);
33+
}
34+
return null;
35+
}
36+
37+
hasTurboModule(name: string): boolean {
38+
return name === SplashScreen.NAME;
39+
}
40+
}
41+
42+
export class SplashScreenPackage extends RNPackage {
43+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
44+
return new SplashScreenTurboModulesFactory(ctx);
45+
}
46+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { SplashScreen } from './SplashScreen'
2+
3+
@Component
4+
export struct SplashScreenView {
5+
build() {
6+
Row() {
7+
Column() {
8+
Row() {
9+
Image(SplashScreen.startWindowIcon).objectFit(ImageFit.ScaleDown)
10+
}
11+
}
12+
.width('100%')
13+
}
14+
.height('100%')
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"module": {
3+
"name": "splash_screen",
4+
type: 'har',
5+
deviceTypes: ['default']
6+
}
7+
}

harmony/splash_screen/ts.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (C) 2024 Huawei Device Co., Ltd.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
export * from "./src/main/ets/SplashScreenPackage"
26+
export * from "./src/main/ets/SplashScreen"

package.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
{
2-
"name": "react-native-splash-screen",
3-
"version": "3.3.0",
2+
"name": "@react-native-oh-tpl/react-native-splash-screen",
3+
"version": "3.3.0-0.0.1",
44
"description": "A splash screen for react-native, hide when application loaded ,it works on iOS and Android.",
5+
"harmony": {
6+
"alias": "react-native-splash-screen",
7+
"codegenConfig": {
8+
"specPaths": [
9+
"./src/specs"
10+
]
11+
}
12+
},
13+
"overrides": {
14+
"@react-native/codegen": "0.74.0"
15+
},
16+
"dependencies": {
17+
"react-native-splash-screen": "3.3.0"
18+
},
519
"main": "index.js",
620
"scripts": {
721
"test": "echo \"Error: no test specified\" && exit 1"
822
},
923
"repository": {
1024
"type": "git",
11-
"url": "git+https://github.com/crazycodeboy/react-native-splash-screen.git"
25+
"url": "git+https://github.com/react-native-oh-library/react-native-splash-screen.git"
1226
},
1327
"keywords": [
1428
"react-native",

0 commit comments

Comments
 (0)