# camera-roll
**Repository Path**: rn-mi/camera-roll
## Basic Information
- **Project Name**: camera-roll
- **Description**: TY项目camera-roll仓库
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-05-22
- **Last Updated**: 2025-08-29
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
> 模板版本:v0.2.2
react-native-cameraroll
本项目基于 [react-native-cameraroll@7.8.3](https://github.com/react-native-cameraroll/react-native-cameraroll) 开发。
## 安装与使用
请到三方库的 Releases 发布地址查看配套的版本信息:[@tuya-oh/react-native-cameraroll Releases](https://gitee.com/rn-mi/camera-roll/releases) 。对于未发布到npm的旧版本,请参考[安装指南](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/tgz-usage.md)安装tgz包。
进入到工程目录并输入以下命令:
#### **npm**
```bash
npm install @tuya-oh/react-native-camera-roll
```
#### **yarn**
```bash
yarn add @tuya-oh/react-native-camera-roll
```
下面的代码展示了这个库的基本使用场景:
> [!WARNING] 使用时 import 的库名不变。
```js
import { View, Button } from "react-native";
import {
CameraRoll
} from "@react-native-camera-roll/camera-roll";
export default function App() {
return (
);
}
```
## 使用 Codegen
本库已经适配了 `Codegen` ,在使用前需要主动执行生成三方库桥接代码,详细请参考[ Codegen 使用文档](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/codegen.md)。
## Link
目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。
首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段
```json
{
...
"overrides": {
"@rnoh/react-native-openharmony" : "./react_native_openharmony"
}
}
```
### 2.引入原生端代码
目前有两种方法:
1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
2. 直接链接源码。
方法一:通过 har 包引入(推荐)
> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
打开 `entry/oh-package.json5`,添加以下依赖
```json
"dependencies": {
"@rnoh/react-native-openharmony": "file:../react_native_openharmony",
"@tuya-oh/camera-roll": "file:../../node_modules/@tuya-oh/react-native-camera-roll/harmony/camera_roll.har"
}
```
点击右上角的 `sync` 按钮
或者在终端执行:
```bash
cd entry
ohpm install
```
方法二:直接链接源码
> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/link-source-code.md)
### 3.在 ArkTs 侧引入 CameraRollPackage
打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
```diff
...
+ import { CameraRollPackage } from '@tuya-oh/camera-roll/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
new SamplePackage(ctx),
+ new CameraRollPackage(ctx),
];
}
```
### 4.配置 CMakeLists 和引入 RNAmapGeolocationPackage
打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
```diff
project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
set(LOG_VERBOSITY_LEVEL 1)
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
add_compile_definitions(WITH_HITRACE_SYSTRACE)
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}/@tuya-oh/camera-roll/src/main/cpp" ./camera-roll)
# RNOH_END: manual_package_linking_1
file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
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_camera_roll)
# RNOH_END: manual_package_linking_2
```
打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
```diff
#include "RNOH/PackageProvider.h"
#include "generated/RNOHGeneratedPackage.h"
#include "SamplePackage.h"
+ #include "CameraRollPackage.h"
using namespace rnoh;
std::vector> PackageProvider::getPackages(Package::Context ctx) {
return {
std::make_shared(ctx),
std::make_shared(ctx),
+ std::make_shared(ctx),
};
}
```
### 4.运行
点击右上角的 `sync` 按钮
或者在终端执行:
```bash
cd entry
ohpm install
```
然后编译、运行即可。
### 5.release包使用
执行完'npm install @tuya-oh/camera-roll@x.x.x'命令后,在生成的node_modules/npm install @tuya-oh/camera-roll中即可获取release包。
打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
```diff
project(rnapp)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(NATIVERENDER_ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${OH_MODULE_DIR}/@rnoh/react-native-openharmony/include")
set(REACT_COMMON_PATCH_DIR "${RNOH_CPP_DIR}/patches/react_native_core")
set(CMAKE_CXX_STANDARD 17)
set(LOG_VERBOSITY_LEVEL 1)
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie -DNDEBUG")
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
add_compile_definitions(WITH_HITRACE_SYSTRACE)
# folly的编译选项
set(folly_compile_options
-DFOLLY_NO_CONFIG=1
-DFOLLY_MOBILE=1
-DFOLLY_USE_LIBCPP=1
-DFOLLY_HAVE_RECVMMSG=1
-DFOLLY_HAVE_PTHREAD=1
-Wno-comma
-Wno-shorten-64-to-32
-Wno-documentation
-faligned-new
)
add_compile_options("-Wno-unused-command-line-argument")
# 添加头文件目录
include_directories(${NATIVERENDER_ROOT_PATH}
${RNOH_CPP_DIR}
${REACT_COMMON_PATCH_DIR}
${RNOH_CPP_DIR}/third-party/folly
${RNOH_CPP_DIR}/third-party/rn/ReactCommon
${RNOH_CPP_DIR}/third-party/rn/ReactCommon/react/nativemodule/core
${RNOH_CPP_DIR}/third-party/rn/ReactCommon/jsi
${RNOH_CPP_DIR}/third-party/rn/ReactCommon/callinvoker
${RNOH_CPP_DIR}/third-party/boost/libs/utility/include
${RNOH_CPP_DIR}/third-party/boost/libs/stacktrace/include
${RNOH_CPP_DIR}/third-party/boost/libs/predef/include
${RNOH_CPP_DIR}/third-party/boost/libs/array/include
${RNOH_CPP_DIR}/third-party/boost/libs/throw_exception/include
${RNOH_CPP_DIR}/third-party/boost/libs/config/include
${RNOH_CPP_DIR}/third-party/boost/libs/core/include
${RNOH_CPP_DIR}/third-party/boost/libs/preprocessor/include
${RNOH_CPP_DIR}/third-party/double-conversion
${RNOH_CPP_DIR}/third-party/rn/ReactCommon/react/renderer/graphics/platform/cxx
${RNOH_CPP_DIR}/third-party/rn/ReactCommon/runtimeexecutor
${RNOH_CPP_DIR}/third-party/glog/src
${RNOH_CPP_DIR}/third-party/boost/libs/mpl/include
${RNOH_CPP_DIR}/third-party/boost/libs/type_traits/include
${RNOH_CPP_DIR}/third-party/rn/ReactCommon/yoga
${RNOH_CPP_DIR}/third-party/boost/libs/intrusive/include
${RNOH_CPP_DIR}/third-party/boost/libs/assert/include
${RNOH_CPP_DIR}/third-party/boost/libs/move/include
${RNOH_CPP_DIR}/third-party/boost/libs/static_assert/include
${RNOH_CPP_DIR}/third-party/boost/libs/container_hash/include
${RNOH_CPP_DIR}/third-party/boost/libs/describe/include
${RNOH_CPP_DIR}/third-party/boost/libs/mp11/include
${RNOH_CPP_DIR}/third-party/boost/libs/iterator/include
${RNOH_CPP_DIR}/third-party/boost/libs/detail/include
${RNOH_CPP_DIR}/patches/react_native_core/react/renderer/textlayoutmanager/platform/harmony
+ ${OH_MODULE_DIR}/@tuya-oh/camera-roll/include
)
configure_file(
${RNOH_CPP_DIR}/third-party/folly/CMake/folly-config.h.cmake
${RNOH_CPP_DIR}/third-party/folly/folly/folly-config.h
)
file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
# 添加rnoh动态共享包
add_library(rnoh SHARED
"${RNOH_CPP_DIR}/RNOHOther.cpp"
"${RNOH_CPP_DIR}/third-party/folly/folly/lang/SafeAssert.cpp"
)
# 链接其他so
target_link_directories(rnoh PUBLIC ${OH_MODULE_DIR}/@rnoh/react-native-openharmony/libs/arm64-v8a)
+ target_link_directories(rnoh PUBLIC ${OH_MODULE_DIR}/@tuya-oh/camera-roll/libs/arm64-v8a)
target_link_libraries(rnoh PUBLIC
rnoh_semi
libace_napi.z.so
libace_ndk.z.so
librawfile.z.so
libhilog_ndk.z.so
libnative_vsync.so
libnative_drawing.so
libc++_shared.so
libhitrace_ndk.z.so
react_render_scheduler
rrc_image
rrc_text
rrc_textinput
rrc_scrollview
react_nativemodule_core
react_render_animations
jsinspector
hermes
jsi
logger
react_config
react_debug
react_render_attributedstring
react_render_componentregistry
react_render_core
react_render_debug
react_render_graphics
react_render_imagemanager
react_render_mapbuffer
react_render_mounting
react_render_templateprocessor
react_render_textlayoutmanager
react_render_telemetry
react_render_uimanager
react_utils
rrc_root
rrc_view
react_render_leakchecker
react_render_runtimescheduler
runtimeexecutor
+ rnoh_camera_roll
)
if("$ENV{RNOH_C_API_ARCH}" STREQUAL "1")
message("Experimental C-API architecture enabled")
target_link_libraries(rnoh PUBLIC libqos.so)
target_compile_definitions(rnoh PUBLIC C_API_ARCH)
endif()
# 添加rnoh_app共享包
add_library(rnoh_app SHARED
${GENERATED_CPP_FILES}
"./PackageProvider.cpp"
"${RNOH_CPP_DIR}/RNOHOther.cpp"
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
)
+ target_include_directories(rnoh_app PUBLIC
+ "${OH_MODULE_DIR}/@tuya-oh/camera-roll/include"
+ "${OH_MODULE_DIR}/@tuya-oh/camera-roll/include/generated"
+ "${OH_MODULE_DIR}/@tuya-oh/camera-roll/include/generated/react"
+ )
target_link_libraries(rnoh_app PUBLIC rnoh)
# RNOH_END: link_packages
target_compile_options(rnoh_app PUBLIC ${folly_compile_options} -DRAW_PROPS_ENABLED -std=c++17)
```
### 6.字节码格式的release包使用
字节码格式的release包是指在release模式下编译出来、ets文件转换成了.abc、C++源码转换成.so的har包,其命名格式为 react_native_openharmony_abc-x.x.x.xxx.har。 字节码格式的release包使用方式跟release包使用大体上是一样的,主要有两点需要注意:
1. 使用字节码格式的release包需要将工程级的 build-profile.json5 文件中将 useNormalizedOHMUrl 设置为 true,如:
```diff
"products": [
{
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.1(13)",
"runtimeOS": "HarmonyOS",
+ "buildOption": {
+ "strictMode": {
+ "useNormalizedOHMUrl": true
+ }
+ }
}
],
```
## 约束与限制
### 兼容性
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@tuya-oh/camera-roll Releases](https://github.com/react-native-oh-library/react-native-cameraroll/releases)
## 静态方法
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 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 权限,需应用方自行申请后,才可以正常使用 |
## API
> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。
> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 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](https://github.com/react-native-oh-library/react-native-cameraroll/issues/5)
- [ ] harmonyRefreshGallerySelection,HarmonyOS 暂无对应图片列表刷新的接口:[issue#8](https://github.com/react-native-oh-library/react-native-cameraroll/issues/8)
- [ ] 部分接口由于Harmony OS安全策略调整无法使用: [issue#25](https://github.com/react-native-oh-library/react-native-cameraroll/issues/25)
- [ ] saveAsset接口未完全支持: [issue#26](https://github.com/react-native-oh-library/react-native-cameraroll/issues/26)
## 其他
## 开源协议
本项目基于 [The MIT License (MIT)](https://github.com/react-native-cameraroll/react-native-cameraroll/blob/master/LICENCE) ,请自由地享受和参与开源。