From 3b8bdfe49028507a89bc39ad6057ca383aba9b33 Mon Sep 17 00:00:00 2001 From: qinjianqi Date: Fri, 8 Nov 2024 10:22:07 +0800 Subject: [PATCH] feat: add HarmonyOS support for react-native-splash-screen Signed-off-by: qinjianqi --- .gitignore | 5 + OAT.xml | 66 ++++ README.md | 335 +----------------- README.zh.md | 232 ------------ add-LaunchScreen-tutorial-for-ios.md | 34 -- harmony/splash_screen.har | Bin 0 -> 5274 bytes harmony/splash_screen/build-profile.json5 | 8 + harmony/splash_screen/hvigorfile.ts | 23 ++ harmony/splash_screen/index.ets | 23 ++ harmony/splash_screen/oh-package.json5 | 13 + .../splash_screen/src/main/cpp/CMakeLists.txt | 9 + .../src/main/cpp/SplashScreenPackage.h | 32 ++ ...NativeOhosReactNativeSplashScreenPackage.h | 65 ++++ .../generated/turbo_modules/SplashScreen.cpp | 16 + .../generated/turbo_modules/SplashScreen.h | 16 + harmony/splash_screen/src/main/ets/Logger.ts | 62 ++++ .../src/main/ets/SplashScreen.ts | 105 ++++++ .../src/main/ets/SplashScreenPackage.ts | 44 +++ .../src/main/ets/SplashScreenView.ets | 34 ++ .../src/main/ets/generated/components/ts.ts | 5 + .../src/main/ets/generated/index.ets | 5 + .../src/main/ets/generated/ts.ts | 6 + .../generated/turboModules/SplashScreen.ts | 14 + .../src/main/ets/generated/turboModules/ts.ts | 5 + harmony/splash_screen/src/main/module.json5 | 7 + harmony/splash_screen/ts.ts | 24 ++ index.d.ts | 35 +- index.js | 26 +- package.json | 22 +- src/RNSplashScreenModule.ts | 30 ++ 30 files changed, 699 insertions(+), 602 deletions(-) create mode 100644 OAT.xml delete mode 100644 README.zh.md delete mode 100644 add-LaunchScreen-tutorial-for-ios.md create mode 100644 harmony/splash_screen.har create mode 100644 harmony/splash_screen/build-profile.json5 create mode 100644 harmony/splash_screen/hvigorfile.ts create mode 100644 harmony/splash_screen/index.ets create mode 100644 harmony/splash_screen/oh-package.json5 create mode 100644 harmony/splash_screen/src/main/cpp/CMakeLists.txt create mode 100644 harmony/splash_screen/src/main/cpp/SplashScreenPackage.h create mode 100644 harmony/splash_screen/src/main/cpp/generated/RNOH/generated/BaseReactNativeOhosReactNativeSplashScreenPackage.h create mode 100644 harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.cpp create mode 100644 harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.h create mode 100644 harmony/splash_screen/src/main/ets/Logger.ts create mode 100644 harmony/splash_screen/src/main/ets/SplashScreen.ts create mode 100644 harmony/splash_screen/src/main/ets/SplashScreenPackage.ts create mode 100644 harmony/splash_screen/src/main/ets/SplashScreenView.ets create mode 100644 harmony/splash_screen/src/main/ets/generated/components/ts.ts create mode 100644 harmony/splash_screen/src/main/ets/generated/index.ets create mode 100644 harmony/splash_screen/src/main/ets/generated/ts.ts create mode 100644 harmony/splash_screen/src/main/ets/generated/turboModules/SplashScreen.ts create mode 100644 harmony/splash_screen/src/main/ets/generated/turboModules/ts.ts create mode 100644 harmony/splash_screen/src/main/module.json5 create mode 100644 harmony/splash_screen/ts.ts create mode 100644 src/RNSplashScreenModule.ts diff --git a/.gitignore b/.gitignore index 11485d9..b1cf507 100755 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,8 @@ jspm_packages # Optional REPL history .node_repl_history .idea + +# Dependency and build +harmony/splash_screen/oh_modules/ +package-lock.json +oh-package-lock.json5 \ No newline at end of file diff --git a/OAT.xml b/OAT.xml new file mode 100644 index 0000000..aeef29d --- /dev/null +++ b/OAT.xml @@ -0,0 +1,66 @@ + + + + LICENSE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 9eb674f..d00b83b 100644 --- a/README.md +++ b/README.md @@ -1,330 +1,9 @@ -# react-native-splash-screen +# @react-native-ohos/react-native-splash-screen +This project is based on [react-native-splash-screen](https://github.com/crazycodeboy/react-native-splash-screen) +## Documentation +[中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-splash-screen.md) +[English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-splash-screen.md) -[![Download](https://img.shields.io/badge/Download-v3.3.0-ff69b4.svg) ](https://www.npmjs.com/package/react-native-splash-screen) -[ ![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/crazycodeboy/react-native-splash-screen/pulls) -[ ![react-native-splash-screen release](https://img.shields.io/github/release/crazycodeboy/react-native-splash-screen.svg?maxAge=2592000?style=flat-square)](https://github.com/crazycodeboy/GitHubPopular/releases) -[ ![语言 中文](https://img.shields.io/badge/语言-中文-feb252.svg)](https://github.com/crazycodeboy/react-native-splash-screen/blob/master/README.zh.md) -[![License MIT](http://img.shields.io/badge/license-MIT-orange.svg?style=flat)](https://raw.githubusercontent.com/crazycodeboy/react-native-check-box/master/LICENSE) -[ ![原理 解析](https://img.shields.io/badge/原理-解析-brightgreen.svg)](https://github.com/crazycodeboy/RNStudyNotes/blob/master/React%20Native%20%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E5%90%88%E9%9B%86/React%20Native%20%E5%90%AF%E5%8A%A8%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%95%99%E7%A8%8B/React%20Native%20%E5%90%AF%E5%8A%A8%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%95%99%E7%A8%8B.md) -[ ![Flutter](https://img.shields.io/badge/Flutter-brightgreen.svg)](https://github.com/crazycodeboy/flutter_splash_screen) - -A splash screen API for react-native which can programatically hide and show the splash screen. Works on iOS and Android. - -## Content - -- [Changes](#changes) -- [Installation](#installation) -- [Examples](#examples) -- [Getting started](#getting-started) -- [API](#api) -- [Testing](#testing) -- [Troubleshooting](#troubleshooting) -- [Contribution](#contribution) - - -## Changes -For React Native >= 0.47.0 use [v3.+](https://github.com/crazycodeboy/react-native-splash-screen/releases), for React Native < 0.47.0 use [v2.1.0](https://github.com/crazycodeboy/react-native-splash-screen/releases/tag/v1.0.9) - -## Examples -* [Examples](https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples) - -![react-native-splash-screen-Android](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/v3.0.0/examples/Screenshots/react-native-splash-screen-Android.gif) -![react-native-splash-screen-iOS](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/v3.0.0/examples/Screenshots/react-native-splash-screen-iOS.gif) - - - -## Installation - -### First step(Download): -Run `npm i react-native-splash-screen --save` - -### Second step(Plugin Installation): - -#### Automatic installation - -`react-native link react-native-splash-screen` or `rnpm link react-native-splash-screen` - -#### Manual installation - -**Android:** - -1. In your `android/settings.gradle` file, make the following additions: -```java -include ':react-native-splash-screen' -project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') -``` - -2. In your android/app/build.gradle file, add the `:react-native-splash-screen` project as a compile-time dependency: - -```java -... -dependencies { - ... - implementation project(':react-native-splash-screen') -} -``` - -3. Update the MainApplication.java file to use `react-native-splash-screen` via the following changes: - -```java -// react-native-splash-screen >= 0.3.1 -import org.devio.rn.splashscreen.SplashScreenReactPackage; -// react-native-splash-screen < 0.3.1 -import com.cboy.rn.splashscreen.SplashScreenReactPackage; - -public class MainApplication extends Application implements ReactApplication { - - private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { - @Override - public boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } - - @Override - protected List getPackages() { - return Arrays.asList( - new MainReactPackage(), - new SplashScreenReactPackage() //here - ); - } - }; - - @Override - public ReactNativeHost getReactNativeHost() { - return mReactNativeHost; - } -} -``` - -**iOS:** - -1. `cd ios` -2. `run pod install` - ->OR - -1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's name]` -2. Go to `node_modules` ➜ `react-native-splash-screen` and add `SplashScreen.xcodeproj` -3. In XCode, in the project navigator, select your project. Add `libSplashScreen.a` to your project's `Build Phases` ➜ `Link Binary With Libraries` -4. To fix `'RNSplashScreen.h' file not found`, you have to select your project → Build Settings → Search Paths → Header Search Paths to add: - - `$(SRCROOT)/../node_modules/react-native-splash-screen/ios` - - - -### Third step(Plugin Configuration): - -**Android:** - -Update the `MainActivity.java` to use `react-native-splash-screen` via the following changes: - -```java -import android.os.Bundle; // here -import com.facebook.react.ReactActivity; -// react-native-splash-screen >= 0.3.1 -import org.devio.rn.splashscreen.SplashScreen; // here -// react-native-splash-screen < 0.3.1 -import com.cboy.rn.splashscreen.SplashScreen; // here - -public class MainActivity extends ReactActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - SplashScreen.show(this); // here - super.onCreate(savedInstanceState); - } - // ...other code -} -``` - -**iOS:** - -Update `AppDelegate.m` with the following additions: - - -```obj-c -#import "AppDelegate.h" - -#import -#import -#import "RNSplashScreen.h" // here - -@implementation AppDelegate - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ - // ...other code - - [RNSplashScreen show]; // here - // or - //[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView]; - return YES; -} - -@end - -``` - -## Getting started - -Import `react-native-splash-screen` in your JS file. - -`import SplashScreen from 'react-native-splash-screen'` - -### Android: - -Create a file called `launch_screen.xml` in `app/src/main/res/layout` (create the `layout`-folder if it doesn't exist). The contents of the file should be the following: - -```xml - - - - -``` - -Customize your launch screen by creating a `launch_screen.png`-file and placing it in an appropriate `drawable`-folder. Android automatically scales drawable, so you do not necessarily need to provide images for all phone densities. -You can create splash screens in the following folders: -* `drawable-ldpi` -* `drawable-mdpi` -* `drawable-hdpi` -* `drawable-xhdpi` -* `drawable-xxhdpi` -* `drawable-xxxhdpi` - -Add a color called `primary_dark` in `app/src/main/res/values/colors.xml` - -``` - - - #000000 - -``` - - -**Optional steps:** - -If you want the splash screen to be transparent, follow these steps. - -Open `android/app/src/main/res/values/styles.xml` and add `true` to the file. It should look like this: - -```xml - - - - -``` - -**To learn more see [examples](https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples)** - - -If you want to customize the color of the status bar when the splash screen is displayed: - -Create `android/app/src/main/res/values/colors.xml` and add -```xml - - - - -``` - -Create a style definition for this in `android/app/src/main/res/values/styles.xml`: -```xml - - - - -``` - -Change your `show` method to include your custom style: -```java -SplashScreen.show(this, R.style.SplashScreenTheme); -``` - -### iOS - -Customize your splash screen via `LaunchScreen.storyboard` or `LaunchScreen.xib`。 - -**Learn more to see [examples](https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples)** - -- [via LaunchScreen.storyboard Tutorial](https://github.com/crazycodeboy/react-native-splash-screen/blob/master/add-LaunchScreen-tutorial-for-ios.md) - - -## Usage - -Use like so: - -```javascript -import SplashScreen from 'react-native-splash-screen' - -export default class WelcomePage extends Component { - - componentDidMount() { - // do stuff while splash screen is shown - // After having done stuff (such as async tasks) hide the splash screen - SplashScreen.hide(); - } -} -``` - -## API - - -| Method | Type | Optional | Description | -|--------|----------|----------|-------------------------------------| -| show() | function | false | Open splash screen (Native Method ) | -| show(final Activity activity, final boolean fullScreen) | function | false | Open splash screen (Native Method ) | -| hide() | function | false | Close splash screen | - -## Testing - -### Jest - -For Jest to work you will need to mock this component. Here is an example: - -``` -// __mocks__/react-native-splash-screen.js -export default { - show: jest.fn().mockImplementation( () => { console.log('show splash screen'); } ), - hide: jest.fn().mockImplementation( () => { console.log('hide splash screen'); } ), -} -``` - -## Troubleshooting - -### Splash screen always appears stretched/distorted -Add the ImageView with a scaleType in the `launch_screen.xml`, e.g.: -``` - - - - - -``` - -## Contribution - -Issues are welcome. Please add a screenshot of you bug and a code snippet. Quickest way to solve issue is to reproduce it in one of the examples. - -Pull requests are welcome. If you want to change the API or do something big it is best to create an issue and discuss it first. - ---- - -**[MIT Licensed](https://github.com/crazycodeboy/react-native-splash-screen/blob/master/LICENSE)** +## License +This library is licensed under [The MIT License (MIT)](https://gitee.com/openharmony-sig/rntpc_react-native-splash-screen/blob/master/LICENSE). diff --git a/README.zh.md b/README.zh.md deleted file mode 100644 index f3a9beb..0000000 --- a/README.zh.md +++ /dev/null @@ -1,232 +0,0 @@ -# react-native-splash-screen - -[![Download](https://img.shields.io/badge/Download-v3.1.1-ff69b4.svg) ](https://www.npmjs.com/package/react-native-splash-screen) -[ ![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/crazycodeboy/react-native-splash-screen/pulls) -[ ![react-native-splash-screen release](https://img.shields.io/github/release/crazycodeboy/react-native-splash-screen.svg?maxAge=2592000?style=flat-square)](https://github.com/crazycodeboy/GitHubPopular/releases) -[ ![language English](https://img.shields.io/badge/language-English-feb252.svg)](https://github.com/crazycodeboy/GitHubPopular/) -[![License MIT](http://img.shields.io/badge/license-MIT-orange.svg?style=flat)](https://raw.githubusercontent.com/crazycodeboy/react-native-check-box/master/LICENSE) -[ ![原理 解析](https://img.shields.io/badge/原理-解析-brightgreen.svg)](https://github.com/crazycodeboy/RNStudyNotes/blob/master/React%20Native%20%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88%E5%90%88%E9%9B%86/React%20Native%20%E5%90%AF%E5%8A%A8%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%95%99%E7%A8%8B/React%20Native%20%E5%90%AF%E5%8A%A8%E7%99%BD%E5%B1%8F%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3%E6%95%99%E7%A8%8B.md) - - - -React Native启动屏,解决iOS,Android启动白屏问题,支持Android和iOS。 - -## 目录 - -- [安装说明](#安装说明) -- [演示](#演示) -- [使用说明](#使用说明) -- [API](#api) -- [贡献](#贡献) -- [改变](#改变) - -## 演示 -* [Examples](https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples) - -![react-native-splash-screen-Android](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/v3.0.0/examples/Screenshots/react-native-splash-screen-Android.gif) -![react-native-splash-screen-iOS](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/v3.0.0/examples/Screenshots/react-native-splash-screen-iOS.gif) - - -## 改变 - -如果你项目的React Native>=0.47.请使用[v3.+](https://github.com/crazycodeboy/react-native-splash-screen/releases), -如果<0.47.0请使用[v2.1.0](https://github.com/crazycodeboy/react-native-splash-screen/releases/tag/v1.0.9)。 - -## 安装说明 - -### 第一步(下载): -在项目根目录打开终端运行 `npm i react-native-splash-screen --save` - -### 第二步 (安装): - -大家可以通过自动或手动两种方式来安装`react-native-splash-screen`。 - - -#### 自动安装 - -终端运行: - - -`react-native link react-native-splash-screen` 或 `rnpm link react-native-splash-screen` - -#### 手动安装 - -**Android:** - -1.在你的 android/settings.gradle 文件中添加下列代码: -``` -include ':react-native-splash-screen' -project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') -``` - -2.在你的 android/app/build.gradle 文件中添加 `:react-native-splash-screen`: - -代码如下: - -``` -... -dependencies { - ... - implementation project(':react-native-splash-screen') -} -``` - -3.更新你的MainApplication.java 文件,如下: - -```java -public class MainApplication extends Application implements ReactApplication { - - private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { - @Override - protected boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } - - @Override - protected List getPackages() { - return Arrays.asList( - new MainReactPackage(), - new SplashScreenReactPackage() //添加这一句 - ); - } - }; - - @Override - public ReactNativeHost getReactNativeHost() { - return mReactNativeHost; - } -} -``` - -**iOS:** - -1. 在 XCode的项目导航视图中单击 `Libraries` ➜ `Add Files to [your project's name]` -2. 将 `SplashScreen.xcodeproj`添加到你的项目中,`node_modules` ➜ `react-native-splash-screen` ➜ `SplashScreen.xcodeproj` - -3. 在XCode中打开`Build Phases` ➜ `Link Binary With Libraries`将`libSplashScreen.a` 添加到你的项目中。 -4. 如果在使用过过程中出现 `'SplashScreen.h' file not found`问题,你可以下面的代码添加到Header Search Paths中,步骤如下: - - -选择你的项目,TARGET → Build Settings → Search Paths → Header Search Paths 添加: - - `$(SRCROOT)/../node_modules/react-native-splash-screen/ios` - - -### 第三步(配置): - -**Android:** - -更新你的 MainActivity.java 文件如下: -```java -public class MainActivity extends ReactActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - SplashScreen.show(this); // 添加这一句 - super.onCreate(savedInstanceState); - } - // ...other code -} -``` - -**iOS:** - -更新你的AppDelegate.m 文件如下: - - -```obj-c -#import "AppDelegate.h" - -#import -#import -#import "RNSplashScreen.h" // 添加这一句 - -@implementation AppDelegate - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ - // ...other code - - [RNSplashScreen show]; // 添加这一句,这一句一定要在最后 - return YES; -} - -@end - -``` - - -## 使用说明 - -将 `react-native-splash-screen` 导入你的JS 文件。 - - -`import SplashScreen from 'react-native-splash-screen'` - -**Android:** - -创建一个名为 launch_screen.xml 的布局文件来自定义你的启动屏幕。 - -``` - - - -``` - -**另外:** - -你也可以启用app主题透明选项来解决在APP启动时因主题原因导致的短暂白屏的问题,具体步骤如下: - -打开 `android/app/src/main/res/values/styles.xml`文件,添加 `true`,如下 : - -```xml - - - - -``` - - -**更详细的介绍,可以查看 [examples](https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples)** - -**iOS** - -iOS可以通过LaunchScreen.storyboard或LaunchScreen.xib来自定义你的启动屏幕。 - -**更详细的介绍,可以查看 [examples](https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples)** - -最后,你可以在适当的时候关闭启动屏幕(如:启动初始化完成后): - -```JavaScript -import SplashScreen from 'react-native-splash-screen' - -export default class WelcomePage extends Component { - - componentDidMount() { - // do anything while splash screen keeps, use await to wait for an async task. - SplashScreen.hide();//关闭启动屏幕 - } -} -``` - -## API - - -方法 | 类型 | 可选 | 描述 ------------------ | -------- | -------- | ----------- -show()   | function | false | 打开启动屏幕(原生方法) -hide() | function | false | 关闭启动屏幕 - -## 贡献 - -欢迎大家提问题,如果能给问题加上一个截图,则是极好的。另外欢迎`Pull requests`贡献你的代码。 - ---- - -**MIT Licensed** diff --git a/add-LaunchScreen-tutorial-for-ios.md b/add-LaunchScreen-tutorial-for-ios.md deleted file mode 100644 index b62ccca..0000000 --- a/add-LaunchScreen-tutorial-for-ios.md +++ /dev/null @@ -1,34 +0,0 @@ -在新版Xcode 中 而LaunchImage已经退出了历史的舞台,要为iOS APP添加启动屏可以通过LaunchScreen.storyboard 或 LaunchScreen.xib两种方式,两种方式思路相同,接下来就介绍下如何通过LaunchScreen.storyboard 来为RN应用添加启动屏。 - -## 步骤 - -1. 创建LaunchScreen.storyboard -2. 创建LaunchScreen Image Set -3. 在LaunchScreen.storyboard中添加ImageView并绑定LaunchScreen Image -4. 应用LaunchScreen.storyboard -5. 删除APP,重新运行 - -### 创建LaunchScreen.storyboard - -RN创建的项目默认是不带LaunchScreen.storyboard的,所以我们需要手动创建,用xcode打开项目下的iOS项目然后在左侧文件导航面板右键选择新建文件: - -![new-LaunchScreen-storyboard.jpg](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/master/screenshot/new-LaunchScreen-storyboard.jpg) - - -### 创建LaunchScreen Image Set - -打开`Images.xcassets`然后添加名为`LaunchScreen`的Image Set: - -![new-LaunchScreen-image-set.jpg](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/master/screenshot/new-LaunchScreen-image-set.jpg) - -### 在LaunchScreen.storyboard中添加ImageView并绑定LaunchScreen Image - -打开`LaunchScreen.storyboard`,然后添加一个ImageView,调整好大小与约束,在为其绑定LaunchScreen Image Set: - -![apply-image-set.jpg](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/master/screenshot/apply-image-set.jpg) - -### 应用LaunchScreen.storyboard - -然后不要忘记在TARGETS中设置`Launch Screen File`: - -![apply-Launchscreen.jpg](https://raw.githubusercontent.com/crazycodeboy/react-native-splash-screen/master/screenshot/apply-Launchscreen.jpg) \ No newline at end of file diff --git a/harmony/splash_screen.har b/harmony/splash_screen.har new file mode 100644 index 0000000000000000000000000000000000000000..fbadf968ae886331a7bb814f1363cfea55d9a2fb GIT binary patch literal 5274 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 literal 0 HcmV?d00001 diff --git a/harmony/splash_screen/build-profile.json5 b/harmony/splash_screen/build-profile.json5 new file mode 100644 index 0000000..14d5b83 --- /dev/null +++ b/harmony/splash_screen/build-profile.json5 @@ -0,0 +1,8 @@ +{ + "apiType": "stageMode", + "targets": [ + { + "name": "default" + } + ] +} \ No newline at end of file diff --git a/harmony/splash_screen/hvigorfile.ts b/harmony/splash_screen/hvigorfile.ts new file mode 100644 index 0000000..dcf8c98 --- /dev/null +++ b/harmony/splash_screen/hvigorfile.ts @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +export { harTasks } from '@ohos/hvigor-ohos-plugin'; \ No newline at end of file diff --git a/harmony/splash_screen/index.ets b/harmony/splash_screen/index.ets new file mode 100644 index 0000000..223be4d --- /dev/null +++ b/harmony/splash_screen/index.ets @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +export * from "./src/main/ets/SplashScreenView" diff --git a/harmony/splash_screen/oh-package.json5 b/harmony/splash_screen/oh-package.json5 new file mode 100644 index 0000000..8145a6c --- /dev/null +++ b/harmony/splash_screen/oh-package.json5 @@ -0,0 +1,13 @@ +{ + "license": "MIT", + "types": "", + "devDependencies": {}, + "name": "@react-native-ohos/react-native-splash-screen", + "description": "", + "main": "index.ets", + "type": "module", + "version": "3.3.0", + "dependencies": { + "@rnoh/react-native-openharmony": "^0.72.38", + } +} \ No newline at end of file diff --git a/harmony/splash_screen/src/main/cpp/CMakeLists.txt b/harmony/splash_screen/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000..cc09e0b --- /dev/null +++ b/harmony/splash_screen/src/main/cpp/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.13) +set(CMAKE_VERBOSE_MAKEFILE on) + +set(rnoh_splash_screen_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated") +file(GLOB_RECURSE rnoh_splash_screen_generated_SRC "${rnoh_splash_screen_generated_dir}/**/*.cpp") +file(GLOB rnoh_splash_screen_SRC CONFIGURE_DEPENDS *.cpp) +add_library(rnoh_splash_screen SHARED ${rnoh_splash_screen_SRC} ${rnoh_splash_screen_generated_SRC}) +target_include_directories(rnoh_splash_screen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rnoh_splash_screen_generated_dir}) +target_link_libraries(rnoh_splash_screen PUBLIC rnoh) \ No newline at end of file diff --git a/harmony/splash_screen/src/main/cpp/SplashScreenPackage.h b/harmony/splash_screen/src/main/cpp/SplashScreenPackage.h new file mode 100644 index 0000000..c997b05 --- /dev/null +++ b/harmony/splash_screen/src/main/cpp/SplashScreenPackage.h @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include "generated/RNOH/generated/BaseReactNativeOhosReactNativeSplashScreenPackage.h" + +namespace rnoh { +class SplashScreenPackage : public BaseReactNativeOhosReactNativeSplashScreenPackage { + using Super = BaseReactNativeOhosReactNativeSplashScreenPackage; + using Super::Super; + }; +} // namespace rnoh \ No newline at end of file diff --git a/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/BaseReactNativeOhosReactNativeSplashScreenPackage.h b/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/BaseReactNativeOhosReactNativeSplashScreenPackage.h new file mode 100644 index 0000000..6918086 --- /dev/null +++ b/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/BaseReactNativeOhosReactNativeSplashScreenPackage.h @@ -0,0 +1,65 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +#pragma once + +#include "RNOH/Package.h" +#include "RNOH/ArkTSTurboModule.h" +#include "RNOH/generated/turbo_modules/SplashScreen.h" + +namespace rnoh { + +class BaseReactNativeOhosReactNativeSplashScreenPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate { + public: + SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override { + if (name == "SplashScreen") { + return std::make_shared(ctx, name); + } + return nullptr; + }; +}; + +class BaseReactNativeOhosReactNativeSplashScreenPackageEventEmitRequestHandler : public EventEmitRequestHandler { + public: + void handleEvent(Context const &ctx) override { + auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter(ctx.tag); + if (eventEmitter == nullptr) { + return; + } + + std::vector supportedEventNames = { + }; + if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) { + eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload)); + } + } +}; + + +class BaseReactNativeOhosReactNativeSplashScreenPackage : public Package { + public: + BaseReactNativeOhosReactNativeSplashScreenPackage(Package::Context ctx) : Package(ctx){}; + + std::unique_ptr createTurboModuleFactoryDelegate() override { + return std::make_unique(); + } + + std::vector createComponentDescriptorProviders() override { + return { + }; + } + + ComponentJSIBinderByString createComponentJSIBinderByName() override { + return { + }; + }; + + EventEmitRequestHandlers createEventEmitRequestHandlers() override { + return { + std::make_shared(), + }; + } +}; + +} // namespace rnoh diff --git a/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.cpp b/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.cpp new file mode 100644 index 0000000..1cbae51 --- /dev/null +++ b/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.cpp @@ -0,0 +1,16 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +#include "SplashScreen.h" + +namespace rnoh { +using namespace facebook; + +SplashScreen::SplashScreen(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) { + methodMap_ = { + ARK_METHOD_METADATA(hide, 0), + }; +} + +} // namespace rnoh diff --git a/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.h b/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.h new file mode 100644 index 0000000..e97801b --- /dev/null +++ b/harmony/splash_screen/src/main/cpp/generated/RNOH/generated/turbo_modules/SplashScreen.h @@ -0,0 +1,16 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +#pragma once + +#include "RNOH/ArkTSTurboModule.h" + +namespace rnoh { + +class JSI_EXPORT SplashScreen : public ArkTSTurboModule { + public: + SplashScreen(const ArkTSTurboModule::Context ctx, const std::string name); +}; + +} // namespace rnoh diff --git a/harmony/splash_screen/src/main/ets/Logger.ts b/harmony/splash_screen/src/main/ets/Logger.ts new file mode 100644 index 0000000..af6b0df --- /dev/null +++ b/harmony/splash_screen/src/main/ets/Logger.ts @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import hilog from '@ohos.hilog'; + +class Logger { + private domain: number; + private prefix: string; + private format: string = '%{public}s, %{public}s'; + private isDebug: boolean; + + /** + * constructor. + * + * @param Prefix Identifies the log tag. + * @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF. + */ + constructor(prefix: string = 'SplashScreen', domain: number = 0xFF00, isDebug = false) { + this.prefix = prefix; + this.domain = domain; + this.isDebug = isDebug; + } + + debug(...args: string[]): void { + if (this.isDebug) { + hilog.debug(this.domain, this.prefix, this.format, args); + } + } + + info(...args: string[]): void { + hilog.info(this.domain, this.prefix, this.format, args); + } + + warn(...args: string[]): void { + hilog.warn(this.domain, this.prefix, this.format, args); + } + + error(...args: string[]): void { + hilog.error(this.domain, this.prefix, this.format, args); + } +} + +export default new Logger('SplashScreen', 0xFF00, false) \ No newline at end of file diff --git a/harmony/splash_screen/src/main/ets/SplashScreen.ts b/harmony/splash_screen/src/main/ets/SplashScreen.ts new file mode 100644 index 0000000..5a2b8c8 --- /dev/null +++ b/harmony/splash_screen/src/main/ets/SplashScreen.ts @@ -0,0 +1,105 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts'; +import { TM } from './generated/ts' +import window from '@ohos.window'; +import image from '@ohos.multimedia.image'; +import Logger from './Logger'; + +export class SplashScreen extends TurboModule implements TM.SplashScreen.Spec { + static NAME = "SplashScreen" + + // 启动图片 + public static startWindowIcon; + + // 子窗口 + private static splashWindow; + + constructor(ctx: TurboModuleContext) { + super(ctx) + } + + /** + * 显示启动屏 + * + */ + public static async show(abilityContext: any, + windowStage: window.WindowStage, + iconResource: any, + backgroundColor: string, + pageUrl: string) { + // 获取resourceManager资源管理 + const context = abilityContext; + const resourceMgr = context.resourceManager + // 获取rawfile文件夹下startIcon的ArrayBuffer + const fileData = await resourceMgr.getMediaContent(iconResource) + const buffer = fileData.buffer + // 创建imageSource + const imageSource = image.createImageSource(buffer) + // 创建PixelMap + const pixelMap = await imageSource.createPixelMap() + this.startWindowIcon = pixelMap; + + // 创建子窗口 + windowStage.createSubWindow("SplashScreenWindow", (err, data) => { + if (err.code) { + Logger.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err)); + return; + } + this.splashWindow = data; + + // 设置子窗口全屏 + this.splashWindow.setFullScreen(true); + + // 为子窗口加载对应的目标页面 + this.splashWindow.setUIContent(pageUrl, (err) => { + if (err.code) { + Logger.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + // 显示子窗口 + this.splashWindow.showWindow((err) => { + if (err.code) { + Logger.error('Failed to show the window. Cause: ' + JSON.stringify(err)); + return; + } + Logger.debug('Succeeded in showing the window.'); + }); + this.splashWindow.setWindowBackgroundColor(backgroundColor) + }); + }) + } + + /** + * 关闭启动屏 + */ + public hide() { + // 销毁子窗口 + SplashScreen.splashWindow.destroyWindow((err) => { + if (err.code) { + Logger.error('Failed to destroy the window. Cause: ' + JSON.stringify(err)); + return; + } + }); + } +} diff --git a/harmony/splash_screen/src/main/ets/SplashScreenPackage.ts b/harmony/splash_screen/src/main/ets/SplashScreenPackage.ts new file mode 100644 index 0000000..03bb0fe --- /dev/null +++ b/harmony/splash_screen/src/main/ets/SplashScreenPackage.ts @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import { RNPackage, TurboModuleContext, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts'; +import type { TurboModule } from '@rnoh/react-native-openharmony/ts'; +import { SplashScreen } from './SplashScreen'; + +class SplashScreenTurboModulesFactory extends TurboModulesFactory { + createTurboModule(name: string): TurboModule | null { + if (name === SplashScreen.NAME) { + return new SplashScreen(this.ctx); + } + return null; + } + + hasTurboModule(name: string): boolean { + return name === SplashScreen.NAME; + } +} + +export class SplashScreenPackage extends RNPackage { + createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory { + return new SplashScreenTurboModulesFactory(ctx); + } +} diff --git a/harmony/splash_screen/src/main/ets/SplashScreenView.ets b/harmony/splash_screen/src/main/ets/SplashScreenView.ets new file mode 100644 index 0000000..05a9a3e --- /dev/null +++ b/harmony/splash_screen/src/main/ets/SplashScreenView.ets @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import { SplashScreen } from './SplashScreen' + +@Component +export struct SplashScreenView { + build() { + Row() { + Image(SplashScreen.startWindowIcon).objectFit(ImageFit.Cover) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/harmony/splash_screen/src/main/ets/generated/components/ts.ts b/harmony/splash_screen/src/main/ets/generated/components/ts.ts new file mode 100644 index 0000000..d1dae56 --- /dev/null +++ b/harmony/splash_screen/src/main/ets/generated/components/ts.ts @@ -0,0 +1,5 @@ + +/** + */ + +export {} diff --git a/harmony/splash_screen/src/main/ets/generated/index.ets b/harmony/splash_screen/src/main/ets/generated/index.ets new file mode 100644 index 0000000..041b7ed --- /dev/null +++ b/harmony/splash_screen/src/main/ets/generated/index.ets @@ -0,0 +1,5 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +export * from "./ts" diff --git a/harmony/splash_screen/src/main/ets/generated/ts.ts b/harmony/splash_screen/src/main/ets/generated/ts.ts new file mode 100644 index 0000000..4c568a8 --- /dev/null +++ b/harmony/splash_screen/src/main/ets/generated/ts.ts @@ -0,0 +1,6 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +export * as RNC from "./components/ts" +export * as TM from "./turboModules/ts" diff --git a/harmony/splash_screen/src/main/ets/generated/turboModules/SplashScreen.ts b/harmony/splash_screen/src/main/ets/generated/turboModules/SplashScreen.ts new file mode 100644 index 0000000..0efb512 --- /dev/null +++ b/harmony/splash_screen/src/main/ets/generated/turboModules/SplashScreen.ts @@ -0,0 +1,14 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +import { Tag } from "@rnoh/react-native-openharmony/ts" + +export namespace SplashScreen { + export const NAME = 'SplashScreen' as const + + export interface Spec { + hide(): void; + + } +} diff --git a/harmony/splash_screen/src/main/ets/generated/turboModules/ts.ts b/harmony/splash_screen/src/main/ets/generated/turboModules/ts.ts new file mode 100644 index 0000000..40cae33 --- /dev/null +++ b/harmony/splash_screen/src/main/ets/generated/turboModules/ts.ts @@ -0,0 +1,5 @@ +/** + * This code was generated by "react-native codegen-lib-harmony" + */ + +export * from "./SplashScreen" diff --git a/harmony/splash_screen/src/main/module.json5 b/harmony/splash_screen/src/main/module.json5 new file mode 100644 index 0000000..1c72002 --- /dev/null +++ b/harmony/splash_screen/src/main/module.json5 @@ -0,0 +1,7 @@ +{ + "module": { + "name": "splash_screen", + type: 'har', + deviceTypes: ['default'] + } +} \ No newline at end of file diff --git a/harmony/splash_screen/ts.ts b/harmony/splash_screen/ts.ts new file mode 100644 index 0000000..fdf018d --- /dev/null +++ b/harmony/splash_screen/ts.ts @@ -0,0 +1,24 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +export * from "./src/main/ets/SplashScreenPackage" +export * from "./src/main/ets/SplashScreen" \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 70f23d2..9d742af 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,39 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import { Platform } from "react-native"; + declare module "react-native-splash-screen" { - export default class SplashScreen { + class SplashScreenCommon { static hide(): void; static show(): void; } + + class SplashScreenHarmony { + hide(): void; + show(): void; + } + + export default class SplashScreen extents ((Platform.OS === 'ios' || Platform === 'android') ? SplashScreenCommon : SplashScreenHarmony) { + + } } diff --git a/index.js b/index.js index c06993f..b767ee0 100755 --- a/index.js +++ b/index.js @@ -1,3 +1,25 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + /** * SplashScreen * 启动屏 @@ -9,6 +31,6 @@ */ 'use strict'; -import { NativeModules } from 'react-native'; -export default NativeModules.SplashScreen; +import NativeModules from './src/RNSplashScreenModule'; +export default NativeModules; diff --git a/package.json b/package.json index be143cd..3536486 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,23 @@ { - "name": "react-native-splash-screen", + "name": "@react-native-ohos/react-native-splash-screen", "version": "3.3.0", "description": "A splash screen for react-native, hide when application loaded ,it works on iOS and Android.", + "harmony": { + "alias": "react-native-splash-screen" + }, + "overrides": { + }, + "dependencies": { + "react-native-splash-screen": "3.3.0" + }, "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-splash-screen --cpp-output-path ./harmony/splash_screen/src/main/cpp/generated --ets-output-path ./harmony/splash_screen/src/main/ets/generated --turbo-modules-spec-paths ./src/RNSplashScreenModule.ts" }, "repository": { "type": "git", - "url": "git+https://github.com/crazycodeboy/react-native-splash-screen.git" + "url": "git+https://gitee.com/openharmony-sig/rntpc_react-native-splash-screen.git" }, "keywords": [ "react-native", @@ -25,10 +34,13 @@ "author": "crazycodeboy", "license": "MIT", "bugs": { - "url": "https://github.com/crazycodeboy/react-native-splash-screen/issues" + "url": "https://gitee.com/openharmony-sig/rntpc_react-native-splash-screen/issues" + }, + "devDependencies": { + "react-native-harmony-cli": "npm:@react-native-oh/react-native-harmony-cli@^0.0.27" }, "peerDependencies": { "react-native": ">=0.57.0" }, - "homepage": "https://github.com/crazycodeboy/react-native-splash-screen#readme" + "homepage": "https://gitee.com/openharmony-sig/rntpc_react-native-splash-screen#readme" } \ No newline at end of file diff --git a/src/RNSplashScreenModule.ts b/src/RNSplashScreenModule.ts new file mode 100644 index 0000000..466810c --- /dev/null +++ b/src/RNSplashScreenModule.ts @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2024 Huawei Device Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport' +import { TurboModuleRegistry } from 'react-native'; + +export interface Spec extends TurboModule { + hide: () => void; +} + +export default TurboModuleRegistry.getEnforcing('SplashScreen'); \ No newline at end of file -- Gitee