-
-> [!TIP] [GitHub address](https://github.com/react-native-oh-library/react-native-fs)
+This project is based on [react-native-fs@2.20.0](https://github.com/itinance/react-native-fs)。
-## Installation and Usage
+| Version | Package Name | Repository | Release |
+| --------------------------- | ------------------------------------ | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
+| <= 2.20.0-0.1.14@deprecated | @react-native-oh-tpl/react-native-fs | [Github(deprecated)](https://github.com/react-native-oh-library/react-native-fs) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-fs/releases) |
+| >= 2.20.1 | @react-native-ohos/react-native-fs | [Gitee](https://gitee.com/openharmony-sig/rntpc_react-native-fs) | [Gitee Releases](https://gitee.com/openharmony-sig/rntpc_react-native-fs/releases) |
-Find the matching version information in the release address of a third-party library: [@react-native-oh-library/react-native-fs Releases](https://github.com/react-native-oh-library/react-native-fs/releases).For older versions that are not published to npm, please refer to the [installation guide](/en/tgz-usage-en.md) to install the tgz package.
+## 1. Installation and Usage
Go to the project directory and execute the following instruction:
-
-
#### npm
```bash
-npm install @react-native-oh-tpl/react-native-fs
+npm install @react-native-ohos/react-native-fs
```
#### yarn
```bash
-yarn add @react-native-oh-tpl/react-native-fs
+yarn add @react-native-ohos/react-native-fs
```
@@ -45,18 +36,10 @@ The following code shows the basic use scenario of the repository:
```tsx
import React, { useState } from "react";
-import {
- SafeAreaView,
- StyleSheet,
- ScrollView,
- View,
- Text,
- StatusBar,
- TextInput,
- Button,
-} from "react-native";
+import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, TextInput, Button } from "react-native";
import FS from "react-native-fs";
import { Colors } from "react-native/Libraries/NewAppScreen";
+
function App(): React.JSX.Element {
const [mkdirParam, setMkdirParam] = useState("");
const mkdirExample = () => {
@@ -75,13 +58,8 @@ function App(): React.JSX.Element {
<>
-
-
- {"React Native File Harmony Demo App"}
-
+
+ {"React Native File Harmony Demo App"}{"mkdir"}
@@ -94,11 +72,7 @@ function App(): React.JSX.Element {
autoCapitalize="none"
/>
-
+
@@ -141,31 +115,34 @@ const styles = StyleSheet.create({
export default App;
```
-## Use Codegen
+## 2. Manual Link
-If this repository has been adapted to `Codegen`, generate the bridge code of the third-party library by using the `Codegen`. For details, see [Codegen Usage Guide](/en/codegen.md).
+This step provides guidance for manually configuring native dependencies.
-## Link
+Open the `harmony` directory of the HarmonyOS project in DevEco Studio.
-Currently, HarmonyOS does not support AutoLink. Therefore, you need to manually configure the linking.
+### 2.1 Overrides RN SDK
-Open the `harmony` directory of the HarmonyOS project in DevEco Studio.
+To ensure the project relies on the same version of the RN SDK, you need to add an `overrides` field in the project's root `oh-package.json5` file, specifying the RN SDK version to be used. The replacement version can be a specific version number, a semver range, or a locally available HAR package or source directory.
-### 1. Adding the overrides Field to oh-package.json5 File in the Root Directory of the Project
+For more information about the purpose of this field, please refer to the [official documentation](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#en-us_topic_0000001792256137_overrides).
```json
{
- ...
"overrides": {
- "@rnoh/react-native-openharmony" : "./react_native_openharmony"
+ "@rnoh/react-native-openharmony": "^0.72.38" // ohpm version
+ // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // a locally available HAR package
+ // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // source code directory
}
}
```
-### 2. Introducing Native Code
+### 2.2 Introducing Native Code
Currently, two methods are available:
+- Use the HAR file.
+- Directly link to the source code。
Method 1 (recommended): Use the HAR file.
@@ -176,7 +153,7 @@ Open `entry/oh-package.json5` file and add the following dependencies:
```json
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
- "@react-native-oh-tpl/react-native-fs": "file:../../node_modules/@react-native-oh-tpl/react-native-fs/harmony/fs.har"
+ "@react-native-ohos/react-native-fs": "file:../../node_modules/@react-native-ohos/react-native-fs/harmony/fs.har"
}
```
@@ -193,15 +170,65 @@ Method 2: Directly link to the source code.
> [!TIP] For details, see [Directly Linking Source Code](/en/link-source-code.md).
+### 2.3 Configuring CMakeLists and Introducing RNFSPackage
+
+> [!TIP] Required for version `v2.20.1` and above
+
+Open `entry/src/main/cpp/CMakeLists.txt` and add the following code:
-### 3.Introducing FsPackage to ArkTS
+```diff
+project(rnapp)
+cmake_minimum_required(VERSION 3.4.1)
+set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
+
+add_subdirectory("${RNOH_CPP_DIR}" ./rn)
+
+# RNOH_BEGIN: manual_package_linking_1
+add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-fs/src/main/cpp" ./fs)
+# RNOH_END: manual_package_linking_1
+
+add_library(rnoh_app SHARED
+ ${GENERATED_CPP_FILES}
+ "./PackageProvider.cpp"
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
+)
+
+target_link_libraries(rnoh_app PUBLIC rnoh)
+
+# RNOH_BEGIN: manual_package_linking_2
+target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
++ target_link_libraries(rnoh_app PUBLIC rnoh_fs)
+# RNOH_END: manual_package_linking_2
+```
+
+Open `entry/src/main/cpp/PackageProvider.cpp` and add the following code:
+
+```diff
+#include "RNOH/PackageProvider.h"
+#include "SamplePackage.h"
++ #include "RNFSPackage.h"
+
+using namespace rnoh;
+
+std::vector> PackageProvider::getPackages(Package::Context ctx) {
+ return {
+ std::make_shared(ctx),
++ std::make_shared(ctx)
+ };
+}
+```
+
+### 2.4. Introducing FsPackage to ArkTS
Open the `entry/src/main/ets/RNPackagesFactory.ts` file and add the following code:
```diff
import type { RNPackageContext, RNPackage } from 'rnoh/ts';
...
-+ import { FsPackage } from '@react-native-oh-tpl/react-native-fs/ts';
++ import { FsPackage } from '@react-native-ohos/react-native-fs/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
@@ -211,7 +238,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
}
```
-### 4.Running
+### 2.5. Running
Click the `sync` button in the upper right corner.
@@ -224,15 +251,13 @@ ohpm install
Then build and run the code.
-## Constraints
-
-### Compatibility
+## 3. Constraints
-To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
+### 3.1 Compatibility
-Check the release version information in the release address of the third-party library: [@react-native-oh-library/react-native-fs Releases](https://github.com/react-native-oh-library/react-native-fs/releases)
+Check the release version information in the release address of the third-party library:[@react-native-ohos/react-native-fs Releases](https://gitee.com/openharmony-sig/rntpc_react-native-fs/releases)
-## Static Methods
+## 4. Static Methods
> [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library.
@@ -240,70 +265,70 @@ Check the release version information in the release address of the third-party
| Name | Description | Type | Required | Platform | HarmonyOS Support | Remark |
| :--------------------------- | ----------- | ------ | -------- | --------------- | ----------------- | ------------------------ |
-| DocumentDirectoryPath | System Path | string | No | IOS/Android | yes | |
-| CachesDirectoryPath | System Path | string | No | IOS/Android | yes | |
-| MainBundlePath | System Path | string | No | IOS | yes | |
+| DocumentDirectoryPath | System Path | string | No | iOS/Android | yes | |
+| CachesDirectoryPath | System Path | string | No | iOS/Android | yes | |
+| MainBundlePath | System Path | string | No | iOS | yes | |
| ExternalCachesDirectoryPath | System Path | string | No | Android | No | Android only |
| DownloadDirectoryPath | System Path | string | No | Android/Windows | No | not available on Harmony |
-| TemporaryDirectoryPath | System Path | string | No | IOS/Android | yes | |
-| LibraryDirectoryPath | System Path | string | No | IOS | yes | |
+| TemporaryDirectoryPath | System Path | string | No | iOS/Android | yes | |
+| LibraryDirectoryPath | System Path | string | No | iOS | yes | |
| ExternalDirectoryPath | System Path | string | No | Android | No | Android only |
| ExternalStorageDirectoryPath | System Path | string | No | Android | No | Android only |
| PicturesDirectoryPath | System Path | string | No | Windows | No | Windows only |
| RoamingDirectoryPath | System Path | string | No | Windows | No | Windows only |
-## APIs
+## 5. APIs
> [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library.
> [!TIP] If the value of **HarmonyOS Support** is **yes**, it means that the HarmonyOS platform supports this property; **no** means the opposite; **partially** means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.
-| Name | Description | Type | Platform | Required | HarmonyOS Support | Remark |
-| ----------------------- | ------------------------------------------------------------ | -------- | ----------- | -------- | ----------------- | ----------------- |
-| mkdir | Create a directory at `filepath`. | function | Android | No | yes | |
-| exists | Check if the item exists at `filepath`. | function | IOS/Android | No | yes | |
-| readFile | Reads the file at `path` and return contents. | function | IOS/Android | No | yes | |
-| readFileAssets | Reads the file at `path` in the harmony app's assets folder and return contents. | function | Android | No | yes | |
-| writeFile | Write the `contents` to `filepath`. | function | IOS/Android | No | yes | |
-| appendFile | Append the `contents` to `filepath`. | function | IOS/Android | No | yes | |
-| copyFile | Copies the file located at `filepath` to `destPath`. | function | IOS | No | yes | |
-| unlink | Unlinks the item at `filepath`. | function | IOS/Android | No | yes | |
-| hash | Reads the file at `path` and returns its checksum as determined by `algorithm`, which can be one of `md5`, `sha1`, `sha256`. | function | IOS/Android | No | partially | |
-| moveFile | Moves the file located at `filepath` to `destPath`. | function | IOS/Android | No | yes | |
-| read | Reads `length` bytes from the given `position` of the file at `path` and returns contents. | function | IOS/Android | No | yes | |
-| write | Write the `contents` to `filepath` at the given random access position. | function | IOS/Android | No | yes | |
-| touch | Sets the modification timestamp `mtime`of the file at `filepath`. | function | IOS/Android | No | partially | |
-| stat | Stats an item at `filepath`. | function | IOS/Android | No | yes | |
-| readDir | Reads the contents of `path`. | function | IOS/Android | No | yes | |
-| readDirAssets | Reads the contents of `dirpath ` in the Android app's assets folder. | function | Android | No | No | Android only |
-| readdir | Node.js style version of `readDir` that returns only the names. | function | IOS/Android | No | No | No API on Harmony |
-| readFileRes | Reads the file named `filename` in the Android app's `res` folder and return contents. | function | Android | No | No | Android only |
-| copyFolder | Copies the contents located at `srcFolderPath` to `destFolderPath`. | function | Windows | No | No | Windows only |
-| copyFileAssets | Copies the file at `filepath` in the Android app's assets folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
-| copyFileRes | Copies the file named `filename` in the Android app's res folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
-| copyAssetsFileIOS | Reads an image file from Camera Roll and writes to `destPath`. | function | IOS | No | No | IOS only |
-| copyAssetsVideoIOS | Copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...' to a specific destination. | function | IOS | No | No | IOS only |
-| existsAssets | Check in the Android assets folder if the item exists. | function | Android | No | yes | |
-| existsRes | Check in the Android res folder if the item named `filename` exists. | function | Android | No | No | Android only |
-| downloadFile | Abort the current download job with this ID. | function | IOS/Android | No | yes | |
-| stopDownload | Abort the current download job with this ID. | function | IOS/Android | No | No | No API on Harmony |
-| resumeDownload | Resume the current download job with this ID. | function | IOS | No | No | IOS only |
-| isResumable | Check if the the download job with this ID is resumable with `resumeDownload()`. | function | IOS | No | No | IOS only |
-| completeHandlerIOS | For use when using background downloads, tell iOS you are done handling a completed download. | function | IOS | No | No | IOS only |
-| uploadFiles | Percentage can be computed easily by dividing `totalBytesSent` by `totalBytesExpectedToSend`. | function | IOS/Android | No | No | No API on Harmony |
-| stopUpload | Abort the current upload job with this ID. | function | IOS | No | No | IOS only |
-| getFSInfo | Returns an object with the following properties. | function | IOS/Android | No | No | No API on Harmony |
-| scanFile | Scan the file using [Media Scanner](https://developer.android.com/reference/android/media/MediaScannerConnection). | function | Android | No | No | Android only |
+| Name | Description | Type | Platform | Required | HarmonyOS Support | Remark |
+| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------- | -------- | ----------------- | ----------------- |
+| mkdir | Create a directory at `filepath`. | function | Android | No | yes | |
+| exists | Check if the item exists at `filepath`. | function | iOS/Android | No | yes | |
+| readFile | Reads the file at `path` and return contents. | function | iOS/Android | No | yes | |
+| readFileAssets | Reads the file at `path` in the harmony app's assets folder and return contents. | function | Android | No | yes | |
+| writeFile | Write the `contents` to `filepath`. | function | iOS/Android | No | yes | |
+| appendFile | Append the `contents` to `filepath`. | function | iOS/Android | No | yes | |
+| copyFile | Copies the file located at `filepath` to `destPath`. | function | iOS | No | yes | |
+| unlink | Unlinks the item at `filepath`. | function | iOS/Android | No | yes | |
+| hash | Reads the file at `path` and returns its checksum as determined by `algorithm`, which can be one of `md5`, `sha1`, `sha256`. | function | iOS/Android | No | partially | |
+| moveFile | Moves the file located at `filepath` to `destPath`. | function | iOS/Android | No | yes | |
+| read | Reads `length` bytes from the given `position` of the file at `path` and returns contents. | function | iOS/Android | No | yes | |
+| write | Write the `contents` to `filepath` at the given random access position. | function | iOS/Android | No | yes | |
+| touch | Sets the modification timestamp `mtime`of the file at `filepath`. | function | iOS/Android | No | partially | |
+| stat | Stats an item at `filepath`. | function | iOS/Android | No | yes | |
+| readDir | Reads the contents of `path`. | function | iOS/Android | No | yes | |
+| readDirAssets | Reads the contents of `dirpath ` in the Android app's assets folder. | function | Android | No | No | Android only |
+| readdir | Node.js style version of `readDir` that returns only the names. | function | iOS/Android | No | No | No API on Harmony |
+| readFileRes | Reads the file named `filename` in the Android app's `res` folder and return contents. | function | Android | No | No | Android only |
+| copyFolder | Copies the contents located at `srcFolderPath` to `destFolderPath`. | function | Windows | No | No | Windows only |
+| copyFileAssets | Copies the file at `filepath` in the Android app's assets folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
+| copyFileRes | Copies the file named `filename` in the Android app's res folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
+| copyAssetsFileIOS | Reads an image file from Camera Roll and writes to `destPath`. | function | iOS | No | No | iOS only |
+| copyAssetsVideoIOS | Copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...' to a specific destination. | function | iOS | No | No | iOS only |
+| existsAssets | Check in the Android assets folder if the item exists. | function | Android | No | yes | |
+| existsRes | Check in the Android res folder if the item named `filename` exists. | function | Android | No | No | Android only |
+| downloadFile | Abort the current download job with this ID. | function | iOS/Android | No | yes | |
+| stopDownload | Abort the current download job with this ID. | function | iOS/Android | No | No | No API on Harmony |
+| resumeDownload | Resume the current download job with this ID. | function | iOS | No | No | iOS only |
+| isResumable | Check if the the download job with this ID is resumable with `resumeDownload()`. | function | iOS | No | No | iOS only |
+| completeHandlerIOS | For use when using background downloads, tell iOS you are done handling a completed download. | function | iOS | No | No | iOS only |
+| uploadFiles | Percentage can be computed easily by dividing `totalBytesSent` by `totalBytesExpectedToSend`. | function | iOS/Android | No | No | No API on Harmony |
+| stopUpload | Abort the current upload job with this ID. | function | iOS | No | No | iOS only |
+| getFSInfo | Returns an object with the following properties. | function | iOS/Android | No | No | No API on Harmony |
+| scanFile | Scan the file using [Media Scanner](https://developer.android.com/reference/android/media/MediaScannerConnection). | function | Android | No | No | Android only |
| getAllExternalFilesDirs | Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns. | function | Android | No | No | Android only |
-| pathForGroup | Returns the absolute path to the directory shared for all applications with the same security group identifier. | function | IOS | No | No | IOS only |
+| pathForGroup | Returns the absolute path to the directory shared for all applications with the same security group identifier. | function | iOS | No | No | iOS only |
-## Known Issues
+## 6. Known Issues
-- [ ] HarmonyOS 的 hash 哈希 API 中关于算法参数 algorithm 目前仅支持"md5"、"sha1"、 "sha256",其他相关算法参数目前不支持,问题: [issue#1](https://github.com/react-native-oh-library/react-native-fs/issues/1)
-- [ ] 原库部分接口在 HarmonyOS 中没有对应文件路径常量及接口处理相关逻辑,问题: [issue#2](https://github.com/react-native-oh-library/react-native-fs/issues/2)
+- [ ] The algorithm parameter algorithm in the hash API of HarmonyOS currently only supports "md5", "sha1", and "sha256". Other related algorithm parameters are currently not supported. Problem: [issue#1](https://github.com/react-native-oh-library/react-native-fs/issues/1)
+- [ ] Some interfaces in the original library do not have corresponding file path constants and interface processing related logic in HarmonyOS. Problem:[issue#2](https://github.com/react-native-oh-library/react-native-fs/issues/2)
-## Others
+## 7. Others
-## License
+## 8. License
This project is licensed under [The MIT License (MIT)](https://github.com/itinance/react-native-fs/blob/master/LICENSE).
diff --git a/zh-cn/model-gitee.md b/zh-cn/model-gitee.md
index bb96defe..b219b842 100644
--- a/zh-cn/model-gitee.md
+++ b/zh-cn/model-gitee.md
@@ -72,7 +72,7 @@ export default App;
首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。
-### 2.1 Overrides RN SDK
+### 2.1. Overrides RN SDK
为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。
@@ -88,7 +88,7 @@ export default App;
}
```
-### 2.2 引入原生端代码
+### 2.2. 引入原生端代码
目前有两种方法:
@@ -121,7 +121,7 @@ ohpm install
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md)
-### 2.3 配置 CMakeLists 和引入 xxxPackge
+### 2.3. 配置 CMakeLists 和引入 xxxPackge
**若涉及接入 codegen-lib 导致的配置项新增,需要在配置项前明确声明:> [!TIP] 版本 vx.x.x 及以上需要**(删除)
@@ -158,7 +158,7 @@ std::vector> PackageProvider::getPackages(Package::Cont
**提示:ArkTs 侧引入 Fabric 组件**(删除)
-### 2.4 在 ArkTs 侧引入 xxx 组件(若本库已 CAPI 化则需要删除本段)
+### 2.4. 在 ArkTs 侧引入 xxx 组件(若本库已 CAPI 化则需要删除本段)
找到 `function buildCustomRNComponent()`,一般位于 `entry/src/main/ets/pages/index.ets` 或 `entry/src/main/ets/rn/LoadBundle.ets`,添加:
@@ -191,7 +191,7 @@ const arkTsComponentNames: Array = [
**提示:TurboModule**(删除)
-### 2.5 在 ArkTs 侧引入 xxx Package
+### 2.5. 在 ArkTs 侧引入 xxx Package
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
@@ -206,7 +206,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
}
```
-### 2.6 运行
+### 2.6. 运行
点击右上角的 `sync` 按钮
@@ -221,7 +221,7 @@ ohpm install
## 3. 约束与限制
-### 3.1 兼容性
+### 3.1. 兼容性
**修改了原库代码的库使用下述描述**(删除)
@@ -237,7 +237,7 @@ ohpm install
1. RNOH: 0.72.38; SDK: HarmonyOS-5.0.0(API12); IDE: DevEco Studio 5.0.3.906; ROM: NEXT.0.0.71;
-### 3.2 权限要求(如有)
+### 3.2. 权限要求(如有)
(填入相关权限配置)
diff --git a/zh-cn/react-native-fs.md b/zh-cn/react-native-fs.md
index 3e1c7996..6652a41f 100644
--- a/zh-cn/react-native-fs.md
+++ b/zh-cn/react-native-fs.md
@@ -1,23 +1,17 @@
-模板版本:v0.2.2
+> 模板版本:v0.3.0
-> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-fs)
+本项目基于 [react-native-fs@2.20.0](https://github.com/itinance/react-native-fs) 开发。
-## 安装与使用
+| Version | Package Name | Repository | Release |
+| --------------------------- | ------------------------------------ | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
+| <= 2.20.0-0.1.14@deprecated | @react-native-oh-tpl/react-native-fs | [Github(deprecated)](https://github.com/react-native-oh-library/react-native-fs) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-fs/releases) |
+| >= 2.20.1 | @react-native-ohos/react-native-fs | [Gitee](https://gitee.com/openharmony-sig/rntpc_react-native-fs) | [Gitee Releases](https://gitee.com/openharmony-sig/rntpc_react-native-fs/releases) |
-请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-library/react-native-fs Releases](https://github.com/react-native-oh-library/react-native-fs/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。
+## 1. 安装与使用
进入到工程目录并输入以下命令:
@@ -26,13 +20,13 @@
#### npm
```bash
-npm install @react-native-oh-tpl/react-native-fs
+npm install @react-native-ohos/react-native-fs
```
#### yarn
```bash
-yarn add @react-native-oh-tpl/react-native-fs
+yarn add @react-native-ohos/react-native-fs
```
@@ -43,18 +37,10 @@ yarn add @react-native-oh-tpl/react-native-fs
```tsx
import React, { useState } from "react";
-import {
- SafeAreaView,
- StyleSheet,
- ScrollView,
- View,
- Text,
- StatusBar,
- TextInput,
- Button,
-} from "react-native";
+import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, TextInput, Button } from "react-native";
import FS from "react-native-fs";
import { Colors } from "react-native/Libraries/NewAppScreen";
+
function App(): React.JSX.Element {
const [mkdirParam, setMkdirParam] = useState("");
const mkdirExample = () => {
@@ -73,13 +59,8 @@ function App(): React.JSX.Element {
<>
-
-
- {"React Native File Harmony Demo App"}
-
+
+ {"React Native File Harmony Demo App"}{"mkdir"}
@@ -92,11 +73,7 @@ function App(): React.JSX.Element {
autoCapitalize="none"
/>
-
+
@@ -139,33 +116,34 @@ const styles = StyleSheet.create({
export default App;
```
-## 使用 Codegen
+## 2. Manual Link
-本库已经适配了 `Codegen` ,在使用前需要主动执行生成三方库桥接代码,详细请参考[ Codegen 使用文档](/zh-cn/codegen.md)。
+此步骤为手动配置原生依赖项的指导。
-## Link
+首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`。
-目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。
+### 2.1. Overrides RN SDK
-首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
+为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。
-### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段
+关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides)
```json
{
- ...
"overrides": {
- "@rnoh/react-native-openharmony" : "./react_native_openharmony"
+ "@rnoh/react-native-openharmony": "^0.72.38" // ohpm 在线版本
+ // "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // 指向本地 har 包的路径
+ // "@rnoh/react-native-openharmony" : "./react_native_openharmony" // 指向源码路径
}
}
```
-### 2.引入原生端代码
+### 2.2. 引入原生端代码
目前有两种方法:
-1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
-2. 直接链接源码。
+- 通过 har 包引入;
+- 直接链接源码。
方法一:通过 har 包引入(推荐)
@@ -176,7 +154,7 @@ export default App;
```json
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
- "@react-native-oh-tpl/react-native-fs": "file:../../node_modules/@react-native-oh-tpl/react-native-fs/harmony/fs.har"
+ "@react-native-ohos/react-native-fs": "file:../../node_modules/@react-native-ohos/react-native-fs/harmony/fs.har"
}
```
@@ -193,15 +171,65 @@ ohpm install
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md)
+### 2.3. 配置 CMakeLists 和引入 RNFSPackage
+
+> [!TIP] 版本 v2.20.1 及以上需要
+
+打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
+
+```diff
+project(rnapp)
+cmake_minimum_required(VERSION 3.4.1)
+set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
+set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
+
+add_subdirectory("${RNOH_CPP_DIR}" ./rn)
+
+# RNOH_BEGIN: manual_package_linking_1
+add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-fs/src/main/cpp" ./fs)
+# RNOH_END: manual_package_linking_1
+
+add_library(rnoh_app SHARED
+ ${GENERATED_CPP_FILES}
+ "./PackageProvider.cpp"
+ "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
+)
+
+target_link_libraries(rnoh_app PUBLIC rnoh)
+
+# RNOH_BEGIN: manual_package_linking_2
+target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
++ target_link_libraries(rnoh_app PUBLIC rnoh_fs)
+# RNOH_END: manual_package_linking_2
+```
+
+打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
+
+```diff
+#include "RNOH/PackageProvider.h"
+#include "SamplePackage.h"
++ #include "RNFSPackage.h"
+
+using namespace rnoh;
+
+std::vector> PackageProvider::getPackages(Package::Context ctx) {
+ return {
+ std::make_shared(ctx),
++ std::make_shared(ctx)
+ };
+}
+```
-### 3.在 ArkTs 侧引入 FsPackage
+### 2.4. 在 ArkTs 侧引入 FsPackage
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
```diff
import type { RNPackageContext, RNPackage } from 'rnoh/ts';
...
-+ import { FsPackage } from '@react-native-oh-tpl/react-native-fs/ts';
++ import { FsPackage } from '@react-native-ohos/react-native-fs/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
@@ -211,7 +239,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
}
```
-### 4.运行
+### 2.5. 运行
点击右上角的 `sync` 按钮
@@ -224,15 +252,14 @@ ohpm install
然后编译、运行即可。
-## 约束与限制
+## 3. 约束与限制
-### 兼容性
+### 3.1. 兼容性
-要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
-请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-library/react-native-fs Releases](https://github.com/react-native-oh-library/react-native-fs/releases)
+请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-ohos/react-native-fs Releases](https://gitee.com/openharmony-sig/rntpc_react-native-fs/releases)
-## 静态方法
+## 4. 静态方法
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
@@ -240,70 +267,70 @@ ohpm install
| Name | Description | Type | Required | Platform | HarmonyOS Support | Remark |
| :--------------------------- | ----------- | ------ | -------- | --------------- | ----------------- | ------------------------ |
-| DocumentDirectoryPath | System Path | string | No | IOS/Android | yes | |
-| CachesDirectoryPath | System Path | string | No | IOS/Android | yes | |
-| MainBundlePath | System Path | string | No | IOS | yes | |
+| DocumentDirectoryPath | System Path | string | No | iOS/Android | yes | |
+| CachesDirectoryPath | System Path | string | No | iOS/Android | yes | |
+| MainBundlePath | System Path | string | No | iOS | yes | |
| ExternalCachesDirectoryPath | System Path | string | No | Android | No | Android only |
| DownloadDirectoryPath | System Path | string | No | Android/Windows | No | not available on Harmony |
-| TemporaryDirectoryPath | System Path | string | No | IOS/Android | yes | |
-| LibraryDirectoryPath | System Path | string | No | IOS | yes | |
+| TemporaryDirectoryPath | System Path | string | No | iOS/Android | yes | |
+| LibraryDirectoryPath | System Path | string | No | iOS | yes | |
| ExternalDirectoryPath | System Path | string | No | Android | No | Android only |
| ExternalStorageDirectoryPath | System Path | string | No | Android | No | Android only |
| PicturesDirectoryPath | System Path | string | No | Windows | No | Windows only |
| RoamingDirectoryPath | System Path | string | No | Windows | No | Windows only |
-## API
+## 5. API
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
-| Name | Description | Type | Platform | Required | HarmonyOS Support | Remark |
-| ----------------------- | ------------------------------------------------------------ | -------- | ----------- | -------- | ----------------- | ----------------- |
-| mkdir | Create a directory at `filepath`. | function | Android | No | yes | |
-| exists | Check if the item exists at `filepath`. | function | IOS/Android | No | yes | |
-| readFile | Reads the file at `path` and return contents. | function | IOS/Android | No | yes | |
-| readFileAssets | Reads the file at `path` in the harmony app's assets folder and return contents. | function | Android | No | yes | |
-| writeFile | Write the `contents` to `filepath`. | function | IOS/Android | No | yes | |
-| appendFile | Append the `contents` to `filepath`. | function | IOS/Android | No | yes | |
-| copyFile | Copies the file located at `filepath` to `destPath`. | function | IOS | No | yes | |
-| unlink | Unlinks the item at `filepath`. | function | IOS/Android | No | yes | |
-| hash | Reads the file at `path` and returns its checksum as determined by `algorithm`, which can be one of `md5`, `sha1`, `sha256`. | function | IOS/Android | No | partially | |
-| moveFile | Moves the file located at `filepath` to `destPath`. | function | IOS/Android | No | yes | |
-| read | Reads `length` bytes from the given `position` of the file at `path` and returns contents. | function | IOS/Android | No | yes | |
-| write | Write the `contents` to `filepath` at the given random access position. | function | IOS/Android | No | yes | |
-| touch | Sets the modification timestamp `mtime`of the file at `filepath`. | function | IOS/Android | No | partially | |
-| stat | Stats an item at `filepath`. | function | IOS/Android | No | yes | |
-| readDir | Reads the contents of `path`. | function | IOS/Android | No | yes | |
-| readDirAssets | Reads the contents of `dirpath ` in the Android app's assets folder. | function | Android | No | No | Android only |
-| readdir | Node.js style version of `readDir` that returns only the names. | function | IOS/Android | No | No | No API on Harmony |
-| readFileRes | Reads the file named `filename` in the Android app's `res` folder and return contents. | function | Android | No | No | Android only |
-| copyFolder | Copies the contents located at `srcFolderPath` to `destFolderPath`. | function | Windows | No | No | Windows only |
-| copyFileAssets | Copies the file at `filepath` in the Android app's assets folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
-| copyFileRes | Copies the file named `filename` in the Android app's res folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
-| copyAssetsFileIOS | Reads an image file from Camera Roll and writes to `destPath`. | function | IOS | No | No | IOS only |
-| copyAssetsVideoIOS | Copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...' to a specific destination. | function | IOS | No | No | IOS only |
-| existsAssets | Check in the Android assets folder if the item exists. | function | Android | No | yes | |
-| existsRes | Check in the Android res folder if the item named `filename` exists. | function | Android | No | No | Android only |
-| downloadFile | Abort the current download job with this ID. | function | IOS/Android | No | yes | |
-| stopDownload | Abort the current download job with this ID. | function | IOS/Android | No | No | No API on Harmony |
-| resumeDownload | Resume the current download job with this ID. | function | IOS | No | No | IOS only |
-| isResumable | Check if the the download job with this ID is resumable with `resumeDownload()`. | function | IOS | No | No | IOS only |
-| completeHandlerIOS | For use when using background downloads, tell iOS you are done handling a completed download. | function | IOS | No | No | IOS only |
-| uploadFiles | Percentage can be computed easily by dividing `totalBytesSent` by `totalBytesExpectedToSend`. | function | IOS/Android | No | No | No API on Harmony |
-| stopUpload | Abort the current upload job with this ID. | function | IOS | No | No | IOS only |
-| getFSInfo | Returns an object with the following properties. | function | IOS/Android | No | No | No API on Harmony |
-| scanFile | Scan the file using [Media Scanner](https://developer.android.com/reference/android/media/MediaScannerConnection). | function | Android | No | No | Android only |
+| Name | Description | Type | Platform | Required | HarmonyOS Support | Remark |
+| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ----------- | -------- | ----------------- | ----------------- |
+| mkdir | Create a directory at `filepath`. | function | Android | No | yes | |
+| exists | Check if the item exists at `filepath`. | function | iOS/Android | No | yes | |
+| readFile | Reads the file at `path` and return contents. | function | iOS/Android | No | yes | |
+| readFileAssets | Reads the file at `path` in the harmony app's assets folder and return contents. | function | Android | No | yes | |
+| writeFile | Write the `contents` to `filepath`. | function | iOS/Android | No | yes | |
+| appendFile | Append the `contents` to `filepath`. | function | iOS/Android | No | yes | |
+| copyFile | Copies the file located at `filepath` to `destPath`. | function | iOS | No | yes | |
+| unlink | Unlinks the item at `filepath`. | function | iOS/Android | No | yes | |
+| hash | Reads the file at `path` and returns its checksum as determined by `algorithm`, which can be one of `md5`, `sha1`, `sha256`. | function | iOS/Android | No | partially | |
+| moveFile | Moves the file located at `filepath` to `destPath`. | function | iOS/Android | No | yes | |
+| read | Reads `length` bytes from the given `position` of the file at `path` and returns contents. | function | iOS/Android | No | yes | |
+| write | Write the `contents` to `filepath` at the given random access position. | function | iOS/Android | No | yes | |
+| touch | Sets the modification timestamp `mtime`of the file at `filepath`. | function | iOS/Android | No | partially | |
+| stat | Stats an item at `filepath`. | function | iOS/Android | No | yes | |
+| readDir | Reads the contents of `path`. | function | iOS/Android | No | yes | |
+| readDirAssets | Reads the contents of `dirpath ` in the Android app's assets folder. | function | Android | No | No | Android only |
+| readdir | Node.js style version of `readDir` that returns only the names. | function | iOS/Android | No | No | No API on Harmony |
+| readFileRes | Reads the file named `filename` in the Android app's `res` folder and return contents. | function | Android | No | No | Android only |
+| copyFolder | Copies the contents located at `srcFolderPath` to `destFolderPath`. | function | Windows | No | No | Windows only |
+| copyFileAssets | Copies the file at `filepath` in the Android app's assets folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
+| copyFileRes | Copies the file named `filename` in the Android app's res folder and copies it to the given `destPath ` path. | function | Android | No | No | Android only |
+| copyAssetsFileIOS | Reads an image file from Camera Roll and writes to `destPath`. | function | iOS | No | No | iOS only |
+| copyAssetsVideoIOS | Copies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...' to a specific destination. | function | iOS | No | No | iOS only |
+| existsAssets | Check in the Android assets folder if the item exists. | function | Android | No | yes | |
+| existsRes | Check in the Android res folder if the item named `filename` exists. | function | Android | No | No | Android only |
+| downloadFile | Abort the current download job with this ID. | function | iOS/Android | No | yes | |
+| stopDownload | Abort the current download job with this ID. | function | iOS/Android | No | No | No API on Harmony |
+| resumeDownload | Resume the current download job with this ID. | function | iOS | No | No | iOS only |
+| isResumable | Check if the the download job with this ID is resumable with `resumeDownload()`. | function | iOS | No | No | iOS only |
+| completeHandlerIOS | For use when using background downloads, tell iOS you are done handling a completed download. | function | iOS | No | No | iOS only |
+| uploadFiles | Percentage can be computed easily by dividing `totalBytesSent` by `totalBytesExpectedToSend`. | function | iOS/Android | No | No | No API on Harmony |
+| stopUpload | Abort the current upload job with this ID. | function | iOS | No | No | iOS only |
+| getFSInfo | Returns an object with the following properties. | function | iOS/Android | No | No | No API on Harmony |
+| scanFile | Scan the file using [Media Scanner](https://developer.android.com/reference/android/media/MediaScannerConnection). | function | Android | No | No | Android only |
| getAllExternalFilesDirs | Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns. | function | Android | No | No | Android only |
-| pathForGroup | Returns the absolute path to the directory shared for all applications with the same security group identifier. | function | IOS | No | No | IOS only |
+| pathForGroup | Returns the absolute path to the directory shared for all applications with the same security group identifier. | function | iOS | No | No | iOS only |
-## 遗留问题
+## 6. 遗留问题
- [ ] HarmonyOS 的 hash 哈希 API 中关于算法参数 algorithm 目前仅支持"md5"、"sha1"、 "sha256",其他相关算法参数目前不支持,问题: [issue#1](https://github.com/react-native-oh-library/react-native-fs/issues/1)
- [ ] 原库部分接口在 HarmonyOS 中没有对应文件路径常量及接口处理相关逻辑,问题: [issue#2](https://github.com/react-native-oh-library/react-native-fs/issues/2)
-## 其他
+## 7. 其他
-## 开源协议
+## 8. 开源协议
本项目基于 [The MIT License (MIT)](https://github.com/itinance/react-native-fs/blob/master/LICENSE) ,请自由地享受和参与开源。
--
Gitee