Template version: v0.2.2
[!TIP] GitHub address
Find the matching version information in the release address of a third-party library: @react-native-oh-tpl/react-native-cameraroll Releases.For older versions that are not published to npm, please refer to the installation guide to install the tgz package.
Go to the project directory and execute the following instruction:
npm install @react-native-oh-tpl/camera-rollyarn add @react-native-oh-tpl/camera-rollThe following code shows the basic use scenario of the repository:
[!WARNING] The name of the imported repository remains unchanged.
import { View, Button } from "react-native";
import {
CameraRoll
} from "@react-native-camera-roll/camera-roll";
export default function App() {
return (
<View>
<Button
title="savePhotos"
onPress={() => {
CameraRoll.saveAsset("https://res.vmallres.com/uomcdn/CN/cms/202408/5442d69d916d4bcf9ee740d595a164fb.jpg").then((res) => {
console.log('res-----',res);
});
}}
/>
</View>
);
}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.
Currently, HarmonyOS does not support AutoLink. Therefore, you need to manually configure the linking.
Open the harmony directory of the HarmonyOS project in DevEco Studio.
{
...
"overrides": {
"@rnoh/react-native-openharmony" : "./react_native_openharmony"
}
}Currently, two methods are available:
Method 1 (recommended): Use the HAR file.
[!TIP] The HAR file is stored in the
harmonydirectory in the installation path of the third-party library.
Open entry/oh-package.json5 file and add the following dependencies:
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
"@react-native-oh-tpl/camera-roll": "file:../../node_modules/@react-native-oh-tpl/camera-roll/harmony/camera_roll.har"
}Click the sync button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm installMethod 2: Directly link to the source code.
[!TIP] For details, see Directly Linking Source Code.
Open the entry/src/main/ets/RNPackagesFactory.ts file and add the following code:
...
+ import { CameraRollPackage } from '@react-native-oh-tpl/camera-roll/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
new SamplePackage(ctx),
+ new CameraRollPackage(ctx),
];
}Click the sync button in the upper right corner.
Alternatively, run the following instruction on the terminal:
cd entry
ohpm installThen build and run the code.
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.
Check the release version information in the release address of the third-party library: @react-native-oh-tpl/camera-roll Releases
[!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.
[!TIP] HarmonyOS受限权限官方说明:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/restricted-permissions-V5#section397164718158
CameraRoll
| Name | Description | Type | Required | Platform | HarmonyOS Support | Remarks |
|---|---|---|---|---|---|---|
| save | 保存图片/视频 | function | no | iOS/Android | partially | 由于原库版本升级,该方法已弃用,可用saveAsset接口代替。 |
| saveAsset | 保存图片/视频 | function | no | iOS/Android | partially | |
| saveToCameraRoll | 保存图片/视频 | function | no | iOS/Android | partially | 由于原库版本升级,该方法已弃用,调用会弹出警告,可用saveAsset接口代替。 |
| getPhotos | 查找图片/视频 | function | no | iOS/Android | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
| getAlbums | 查找相册 | function | no | iOS/Android | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
| deletePhotos | 删除图片/视频 | function | no | iOS/Android | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
| iosGetImageDataById | 获取图片数据 | function | no | iOS | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
| getPhotoThumbnail | 获取缩略图 | function | no | iOS | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
[!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 | Required | Platform | HarmonyOS Support | Remarks |
|---|---|---|---|---|---|---|
iosReadGalleryPermission |
权限验证 | function | no | iOS | no | |
iosRequestReadWriteGalleryPermission |
读写权限申请 | function | no | iOS | no | |
iosRequestAddOnlyGalleryPermission |
添加权限申请 | function | no | iOS | no | |
iosRefreshGallerySelection |
图片列表刷新 | function | no | iOS | no | |
harmonyReadGalleryPermission |
权限验证 | function | no | harmony | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
harmonyRequestReadWriteGalleryPermission |
读写权限申请 | function | no | harmony | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
harmonyRequestAddOnlyGalleryPermission |
添加权限申请 | function | no | harmony | no | 由于 HarmonyOS 安全策略要求,该接口需要使用 ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.WRITE_IMAGEVIDEO 权限,需应用方自行申请后,才可以正常使用 |
harmonyRefreshGallerySelection |
图片列表刷新 | function | no | harmony | no |
- deletePhotos删除图片/视频,未实现 HarmonyOS 化: issue#5
- harmonyRefreshGallerySelection,HarmonyOS 暂无对应图片列表刷新的接口:issue#8
- 部分接口由于Harmony OS安全策略调整无法使用: issue#25
- saveAsset接口未完全支持: issue#26
This project is licensed under The MIT License (MIT).