| @@ -33,6 +33,10 @@ local.properties | |||
| 33 | node_modules/ | 33 | node_modules/ |
| 34 | npm-debug.log | 34 | npm-debug.log |
| 35 | 35 | ||
| 36 | +# jest / test artifacts | ||
| 37 | +jest/coverage/ | ||
| 38 | +coverage/ | ||
| 39 | + | ||
| 36 | # BUCK | 40 | # BUCK |
| 37 | buck-out/ | 41 | buck-out/ |
| 38 | \.buckd/ | 42 | \.buckd/ |
| @@ -48,3 +48,7 @@ ios/Pods | |||
| 48 | /example | 48 | /example |
| 49 | docs/ | 49 | docs/ |
| 50 | *.tgz | 50 | *.tgz |
| 51 | + | ||
| 52 | +# jest / test artifacts | ||
| 53 | +/jest | ||
| 54 | +/coverage | ||
| @@ -1,5 +1,9 @@ | |||
| 1 | # 鸿蒙化Log | 1 | # 鸿蒙化Log |
| 2 | 2 | ||
| 3 | +## v2.1.2-beta.2 | ||
| 4 | +### Fixed | ||
| 5 | +- Optimizing the stability of rotating HTTP downloads and reusing the same URL in network diagrams.add jest and update example [#31](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/pull/31) | ||
| 6 | + | ||
| 3 | ## v2.1.2-beta.1 | 7 | ## v2.1.2-beta.1 |
| 4 | ### Fixed | 8 | ### Fixed |
| 5 | - Modify rotateImage method to decode and rotate failed error callback,addd exapmle [#27](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/pull/27) | 9 | - Modify rotateImage method to decode and rotate failed error callback,addd exapmle [#27](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/pull/27) |
| @@ -28,21 +28,35 @@ | |||
| 28 | </policy> | 28 | </policy> |
| 29 | </policylist> | 29 | </policylist> |
| 30 | <filefilterlist> | 30 | <filefilterlist> |
| 31 | - <filefilter name="defaultFilter" desc="Files not to check"> | 31 | + <filefilter name="copyrightPolicyFilter" desc="Filters for compatibility,license header policies"> |
| 32 | - | 32 | + <filteritem type="filepath" name="harmony/imageRotate/hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/> |
| 33 | + <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/> | ||
| 34 | + <filteritem type="filename" name="LICENSE" desc="版权文件,不添加版权头"/> | ||
| 35 | + <filteritem type="filepath" name="index.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/> | ||
| 36 | + <filteritem type="filepath" name="src/NativeImageRotate.ts" desc="第三方开源软件源码,不添加许可证头"/> | ||
| 37 | + <filteritem type="filepath" name="harmony/imageRotate/src/main/cpp/generated/**/*" desc="codegen自动生成,不手动修改"/> | ||
| 38 | + <filteritem type="filepath" name="harmony/imageRotate/src/main/ets/generated/**/*" desc="codegen自动生成,不手动修改"/> | ||
| 39 | + <filteritem type="filename" name=".npmignore" desc="工程配置文件,不手动修改"/> | ||
| 40 | + <filteritem type="filepath" name="buildEnv.sh" desc="构建环境脚本,不添加版权头"/> | ||
| 41 | + <filteritem type="filepath" name="jest/**/*" desc="jest测试配置及测试用例,不添加版权头"/> | ||
| 33 | </filefilter> | 42 | </filefilter> |
| 34 | - <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies"> | 43 | + <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies"> |
| 35 | - <filteritem type="filename" name="LICENSE" desc="许可证说明文件,不添加版权头"/> | 44 | + <filteritem type="filepath" name="harmony/imageRotate/hvigorfile.ts" desc="hvigor构建脚本,DevEco Studio自动生成,不手动修改"/> |
| 36 | - <filteritem type="filepath" name="harmony/imageRotate/src/main/ets/Logger.ts" desc="工程配置文件,非业务代码,不添加许可证头"/> | 45 | + <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/> |
| 46 | + <filteritem type="filename" name="LICENSE" desc="版权文件,不添加许可证头"/> | ||
| 47 | + <filteritem type="filepath" name="index.*" desc="第三方开源软件源码,不修改版权头,以防有修改版权风险"/> | ||
| 48 | + <filteritem type="filepath" name="src/NativeImageRotate.ts" desc="第三方开源软件源码,不添版权头"/> | ||
| 49 | + <filteritem type="filepath" name="harmony/imageRotate/src/main/cpp/generated/**/*" desc="codegen自动生成,不手动修改"/> | ||
| 50 | + <filteritem type="filepath" name="harmony/imageRotate/src/main/ets/generated/**/*" desc="codegen自动生成,不手动修改"/> | ||
| 51 | + <filteritem type="filename" name=".npmignore" desc="工程配置文件,不手动修改"/> | ||
| 52 | + <filteritem type="filepath" name="buildEnv.sh" desc="构建环境脚本,不添加版权头"/> | ||
| 53 | + <filteritem type="filepath" name="jest/**/*" desc="jest测试配置及测试用例,不添加版权头"/> | ||
| 54 | + </filefilter> | ||
| 55 | + | ||
| 37 | </filefilter> | 56 | </filefilter> |
| 38 | <filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies"> | 57 | <filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies"> |
| 39 | <filteritem type="filepath" name="harmony/imageRotate.har" desc="项目打包文件"/> | 58 | <filteritem type="filepath" name="harmony/imageRotate.har" desc="项目打包文件"/> |
| 40 | </filefilter> | 59 | </filefilter> |
| 41 | - | ||
| 42 | - <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies"> | ||
| 43 | - <filteritem type="filename" name="LICENSE" desc="许可证说明文件,不添加版权头"/> | ||
| 44 | - <filteritem type="filepath" name="harmony/imageRotate/src/main/ets/Logger.ts" desc="工程配置文件,非业务代码,不添加许可证头"/> | ||
| 45 | - </filefilter> | ||
| 46 | </filefilterlist> | 60 | </filefilterlist> |
| 47 | </oatconfig> | 61 | </oatconfig> |
| 48 | </configuration> | 62 | </configuration> |
| @@ -4,13 +4,15 @@ | |||
| 4 | <h1 align="center"> <code>react-native-image-rotate</code> </h1> | 4 | <h1 align="center"> <code>react-native-image-rotate</code> </h1> |
| 5 | </p> | 5 | </p> |
| 6 | 6 | ||
| 7 | +[English](./README_en.md) | **简体中文** | ||
| 8 | + | ||
| 7 | 本项目基于 [react-native-image-rotate](https://github.com/dgladkov/react-native-image-rotate) 开发。 | 9 | 本项目基于 [react-native-image-rotate](https://github.com/dgladkov/react-native-image-rotate) 开发。 |
| 8 | 10 | ||
| 9 | -该第三方库的仓库已迁移至 GitCode,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-image-rotate`,版本所属关系如下: | 11 | +该第三方库的仓库已迁移至 AtomGit,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-image-rotate`,版本所属关系如下: |
| 10 | 12 | ||
| 11 | | 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 | | 13 | | 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 | |
| 12 | | ------------ | ------------ | ------------------------------ | ------------- | ------------- |------------------------ | ------------- | ------------- | | 14 | | ------------ | ------------ | ------------------------------ | ------------- | ------------- |------------------------ | ------------- | ------------- | |
| 13 | -| @react-native-ohos/react-native-image-rotate | [~2.1.1](https://www.npmjs.com/package/@react-native-ohos/react-native-image-rotate) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/releases) | 0.72.* | 是 | API12+ | 2.1.0 | [br_rnoh0.72](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/tree/br_rnoh0.72) | | 15 | +| @react-native-ohos/react-native-image-rotate | [~2.1.1](https://www.npmjs.com/package/@react-native-ohos/react-native-image-rotate) | [GitCode Releases](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/releases) | 0.72.* | 是 | API12+ | 2.1.0 | [br_rnoh0.72](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/tree/br_rnoh0.72) | |
| 14 | | @react-native-oh-tpl/react-native-image-rotate | [<= 2.1.0-0.0.3@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-image-rotate) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-image-rotate/releases) | 0.72.* | 否 | API12+ | 2.1.0 | [sig](https://github.com/react-native-oh-library/react-native-image-rotate) | | 16 | | @react-native-oh-tpl/react-native-image-rotate | [<= 2.1.0-0.0.3@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-image-rotate) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-image-rotate/releases) | 0.72.* | 否 | API12+ | 2.1.0 | [sig](https://github.com/react-native-oh-library/react-native-image-rotate) | |
| 15 | 17 | ||
| 16 | ## 简介 | 18 | ## 简介 |
| @@ -36,14 +38,15 @@ yarn add @react-native-ohos/react-native-image-rotate | |||
| 36 | 38 | ||
| 37 | ## Link | 39 | ## Link |
| 38 | 40 | ||
| 39 | -| 版本 | 是否支持autolink | RN框架版本 | | 41 | +| | 是否支持Autolink | RN框架版本 | |
| 40 | |--------------------------------------|----------------|-----------| | 42 | |--------------------------------------|----------------|-----------| |
| 41 | | ~2.1.1 | 是 | 0.72.* | | 43 | | ~2.1.1 | 是 | 0.72.* | |
| 42 | | <= 2.1.0-0.0.3@deprecated | 否 | 0.72.* | | 44 | | <= 2.1.0-0.0.3@deprecated | 否 | 0.72.* | |
| 43 | 45 | ||
| 44 | -使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/CPF-RN/ohos_react_native/blob/main/docs/zh-cn/02-开发/02-开发指南/Autolinking.md | 46 | +使用 Autolink 的工程需要根据该文档配置,Autolink 框架指导文档:https://atomgit.com/CPF-RN/ohos_react_native/blob/main/docs/zh-cn/02-开发/02-开发指南/Autolinking.md 。 |
| 47 | + | ||
| 48 | +如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过 ManualLink 配置。 | ||
| 45 | 49 | ||
| 46 | -如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。 | ||
| 47 | <details> | 50 | <details> |
| 48 | <summary>ManualLink: 此步骤为手动配置原生依赖项的指导</summary> | 51 | <summary>ManualLink: 此步骤为手动配置原生依赖项的指导</summary> |
| 49 | 52 | ||
| @@ -53,7 +56,7 @@ yarn add @react-native-ohos/react-native-image-rotate | |||
| 53 | 56 | ||
| 54 | 为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。 | 57 | 为了让工程依赖同一个版本的 RN SDK,需要在工程根目录的 `oh-package.json5` 添加 overrides 字段,指向工程需要使用的 RN SDK 版本。替换的版本既可以是一个具体的版本号,也可以是一个模糊版本,还可以是本地存在的 HAR 包或源码目录。 |
| 55 | 58 | ||
| 56 | -关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides) | 59 | +关于该字段的作用请阅读[官方说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-oh-package-json5-V5#zh-cn_topic_0000001792256137_overrides)。 |
| 57 | 60 | ||
| 58 | ```json | 61 | ```json |
| 59 | { | 62 | { |
| @@ -69,14 +72,14 @@ yarn add @react-native-ohos/react-native-image-rotate | |||
| 69 | 72 | ||
| 70 | 目前有两种方法: | 73 | 目前有两种方法: |
| 71 | 74 | ||
| 72 | -- 通过 har 包引入; | 75 | +- 通过 har 包引入。 |
| 73 | - 直接链接源码。 | 76 | - 直接链接源码。 |
| 74 | 77 | ||
| 75 | 方法一:通过 har 包引入(推荐) | 78 | 方法一:通过 har 包引入(推荐) |
| 76 | 79 | ||
| 77 | > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 | 80 | > [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 |
| 78 | 81 | ||
| 79 | -打开 `entry/oh-package.json5`,添加以下依赖 | 82 | +打开 `entry/oh-package.json5`,添加以下依赖: |
| 80 | 83 | ||
| 81 | ```json | 84 | ```json |
| 82 | "dependencies": { | 85 | "dependencies": { |
| @@ -95,7 +98,7 @@ ohpm install | |||
| 95 | 98 | ||
| 96 | 方法二:直接链接源码 | 99 | 方法二:直接链接源码 |
| 97 | 100 | ||
| 98 | -> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](https://gitcode.com/CPF-RN/usage-docs/blob/master/zh-cn/link-source-code.md) | 101 | +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](https://atomgit.com/CPF-RN/usage-docs/blob/master/zh-cn/link-source-code.md)。 |
| 99 | 102 | ||
| 100 | ### 3. 配置 CMakeLists 和引入 ImageRotatePackage | 103 | ### 3. 配置 CMakeLists 和引入 ImageRotatePackage |
| 101 | 104 | ||
| @@ -156,7 +159,7 @@ std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Cont | |||
| 156 | 159 | ||
| 157 | ### 4. 在 ArkTs 侧引入 RNImageRotatePackage | 160 | ### 4. 在 ArkTs 侧引入 RNImageRotatePackage |
| 158 | 161 | ||
| 159 | -打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: | 162 | +打开 `entry/src/main/ets/RNPackagesFactory.ets`,添加: |
| 160 | 163 | ||
| 161 | ```diff | 164 | ```diff |
| 162 | ... | 165 | ... |
| @@ -210,9 +213,10 @@ requestPermissions: [ | |||
| 210 | 213 | ||
| 211 | ### 编译运行API要求 | 214 | ### 编译运行API要求 |
| 212 | 215 | ||
| 213 | -> [!TIP] 当前三方库所有版本均已实现版本隔离,支持在 `API12+` 工程编译,及 `API12+` ROM运行。 | 216 | +> [!TIP] 当前三方库所有版本均已实现版本隔离,支持在 `API12+` 工程编译,及 `API12+` ROM 运行。 |
| 214 | 217 | ||
| 215 | ## 使用示例 | 218 | ## 使用示例 |
| 219 | + | ||
| 216 | 下面的代码展示了这个库的基本使用场景: | 220 | 下面的代码展示了这个库的基本使用场景: |
| 217 | 221 | ||
| 218 | > [!WARNING] 使用时 import 的库名不变。 | 222 | > [!WARNING] 使用时 import 的库名不变。 |
| @@ -331,21 +335,24 @@ ImageRotate.rotateImage( | |||
| 331 | 335 | ||
| 332 | ## 接口说明 | 336 | ## 接口说明 |
| 333 | 337 | ||
| 334 | -> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 | 338 | +> [!TIP] "平台"列表示该属性在原三方库上支持的平台。 |
| 335 | 339 | ||
| 336 | -> [!TIP] "OpenHarmony Support"列为 yes 表示 OpenHarmony平台支持 该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 | 340 | +> [!TIP] "OpenHarmony平台支持"列为 "是" 表示 OpenHarmony 平台支持该属性;"否" 则表示不支持;"部分支持" 表示仅实现了功能的一部分。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 |
| 337 | 341 | ||
| 338 | ### API | 342 | ### API |
| 343 | + | ||
| 339 | | 名称 | 类型 | 参数类型 | 返回值 | 必填 | 平台 | OpenHarmony平台支持 | 描述 | | 344 | | 名称 | 类型 | 参数类型 | 返回值 | 必填 | 平台 | OpenHarmony平台支持 | 描述 | |
| 340 | |--------|---------|-----|-------|-------|--------|-----|-----------------| | 345 | |--------|---------|-----|-------|-------|--------|-----|-----------------| |
| 341 | -| rotateImage | function | uri: string, angle: number, success: (uri: string) => void, failure: (error: Object) => void | void | no | iOS/Android | Yes | 旋转图片。仅支持 90 的倍数角度,负角度表示逆时针旋转;成功回调返回旋转后图片的 URI,失败回调返回错误信息。| | 346 | +| rotateImage | function | uri: string, angle: number, success: (uri: string) => void, failure: (error: Object) => void | void | no | iOS/Android | 是 | 旋转图片。仅支持 90 的倍数角度,负角度表示逆时针旋转;成功回调返回旋转后图片的 URI,失败回调返回错误信息。| |
| 342 | 347 | ||
| 343 | ## 遗留问题 | 348 | ## 遗留问题 |
| 344 | 349 | ||
| 345 | ## 其他 | 350 | ## 其他 |
| 351 | + | ||
| 346 | 无 | 352 | 无 |
| 347 | 353 | ||
| 348 | ## 目录结构 | 354 | ## 目录结构 |
| 355 | + | ||
| 349 | ``` | 356 | ``` |
| 350 | /rntpc_react-native-image-rotate # 项目根目录 | 357 | /rntpc_react-native-image-rotate # 项目根目录 |
| 351 | ├── harmony # 鸿蒙适配代码 | 358 | ├── harmony # 鸿蒙适配代码 |
| @@ -365,8 +372,8 @@ ImageRotate.rotateImage( | |||
| 365 | 372 | ||
| 366 | ## 贡献代码 | 373 | ## 贡献代码 |
| 367 | 374 | ||
| 368 | -使用过程中发现任何问题都可以提交 [Issue](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/issues),当然,也非常欢迎提交 [PR](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/pulls) 。 | 375 | +使用过程中发现任何问题都可以提交 [Issue](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/issues),当然,也非常欢迎提交 [PR](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/pulls)。 |
| 369 | 376 | ||
| 370 | ## 开源协议 | 377 | ## 开源协议 |
| 371 | 378 | ||
| 372 | -本项目基于 [The MIT License (MIT)](https://github.com/dgladkov/react-native-image-rotate/blob/master/LICENSE) ,请自由地享受和参与开源。 | 379 | +本项目基于 [The MIT License (MIT)](https://github.com/dgladkov/react-native-image-rotate/blob/master/LICENSE),请自由地享受和参与开源。 |
| @@ -4,13 +4,15 @@ | |||
| 4 | <h1 align="center"> <code>react-native-image-rotate</code> </h1> | 4 | <h1 align="center"> <code>react-native-image-rotate</code> </h1> |
| 5 | </p> | 5 | </p> |
| 6 | 6 | ||
| 7 | +**English** | [简体中文](./README.md) | ||
| 8 | + | ||
| 7 | This project is based on [react-native-image-rotate](https://github.com/dgladkov/react-native-image-rotate). | 9 | This project is based on [react-native-image-rotate](https://github.com/dgladkov/react-native-image-rotate). |
| 8 | 10 | ||
| 9 | -This third-party library has been migrated to GitCode and is now available for direct download from npm, the new package name is: `@react-native-ohos/react-native-image-rotate`, the version correspondence details are as follows: | 11 | +This third-party library has been migrated to AtomGit and is now available for direct download from npm, the new package name is: `@react-native-ohos/react-native-image-rotate`, the version correspondence details are as follows: |
| 10 | 12 | ||
| 11 | | Name | Version(Npm Address) | Release Information | Supported RN Version | Supported Autolink | Compile API Version | Community Baseline Version | Source code address | | 13 | | Name | Version(Npm Address) | Release Information | Supported RN Version | Supported Autolink | Compile API Version | Community Baseline Version | Source code address | |
| 12 | | --------------| -------------- | ------------------------------ | ------------- | ------------- |------------------------ | ------------ | ------------- | | 14 | | --------------| -------------- | ------------------------------ | ------------- | ------------- |------------------------ | ------------ | ------------- | |
| 13 | -| @react-native-ohos/react-native-image-rotate | [~2.1.1](https://www.npmjs.com/package/@react-native-ohos/react-native-image-rotate) | [GitCode Releases](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/releases) | 0.72.* | Yes | API12+ | 2.1.0 | [br_rnoh0.72](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/tree/br_rnoh0.72) | | 15 | +| @react-native-ohos/react-native-image-rotate | [~2.1.1](https://www.npmjs.com/package/@react-native-ohos/react-native-image-rotate) | [GitCode Releases](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/releases) | 0.72.* | Yes | API12+ | 2.1.0 | [br_rnoh0.72](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/tree/br_rnoh0.72) | |
| 14 | | @react-native-oh-tpl/react-native-image-rotate | [<= 2.1.0-0.0.3@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-image-rotate) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-image-rotate/releases) | 0.72.* | No | API12+ | 2.1.0 | [sig](https://github.com/react-native-oh-library/react-native-image-rotate) | | 16 | | @react-native-oh-tpl/react-native-image-rotate | [<= 2.1.0-0.0.3@deprecated](https://www.npmjs.com/package/@react-native-oh-tpl/react-native-image-rotate) | [Github Releases(deprecated)](https://github.com/react-native-oh-library/react-native-image-rotate/releases) | 0.72.* | No | API12+ | 2.1.0 | [sig](https://github.com/react-native-oh-library/react-native-image-rotate) | |
| 15 | 17 | ||
| 16 | ## Introduction | 18 | ## Introduction |
| @@ -36,12 +38,12 @@ yarn add @react-native-ohos/react-native-image-rotate | |||
| 36 | 38 | ||
| 37 | ## Link | 39 | ## Link |
| 38 | 40 | ||
| 39 | -| Version | Supported Autolink | Supported RN Version | | 41 | +| | Supported Autolink | Supported RN Version | |
| 40 | |--------------------------------------|--------------------|----------------------| | 42 | |--------------------------------------|--------------------|----------------------| |
| 41 | | ~2.1.1 | Yes | 0.72.* | | 43 | | ~2.1.1 | Yes | 0.72.* | |
| 42 | | <= 2.1.0-0.0.3@deprecated | No | 0.72.* | | 44 | | <= 2.1.0-0.0.3@deprecated | No | 0.72.* | |
| 43 | 45 | ||
| 44 | -Projects using AutoLink need to be configured according to this document, AutoLink framework guide: https://gitcode.com/CPF-RN/ohos_react_native/blob/main/docs/en/02-development/02-development-guide/autolinking.md | 46 | +Projects using AutoLink need to be configured according to this document, AutoLink framework guide: https://atomgit.com/CPF-RN/ohos_react_native/blob/main/docs/en/02-development/02-development-guide/autolinking.md |
| 45 | 47 | ||
| 46 | If the version you are using supports Autolink and the project has integrated Autolink, you can skip the ManualLink configuration. | 48 | If the version you are using supports Autolink and the project has integrated Autolink, you can skip the ManualLink configuration. |
| 47 | 49 | ||
| @@ -77,7 +79,7 @@ Method 1 (recommended): Use the HAR file. | |||
| 77 | 79 | ||
| 78 | > [!TIP] The HAR file is stored in the `harmony` directory in the installation path of the third-party library. | 80 | > [!TIP] The HAR file is stored in the `harmony` directory in the installation path of the third-party library. |
| 79 | 81 | ||
| 80 | -Open entry/oh-package.json5 file and add the following dependencies: | 82 | +Open `entry/oh-package.json5` file and add the following dependencies: |
| 81 | 83 | ||
| 82 | ```json | 84 | ```json |
| 83 | "dependencies": { | 85 | "dependencies": { |
| @@ -96,7 +98,7 @@ ohpm install | |||
| 96 | 98 | ||
| 97 | Method 2: Directly link to the source code. | 99 | Method 2: Directly link to the source code. |
| 98 | 100 | ||
| 99 | -> [!TIP] For details, see [Directly Linking Source Code](https://gitcode.com/CPF-RN/usage-docs/blob/master/en/link-source-code.md) | 101 | +> [!TIP] For details, see [Directly Linking Source Code](https://atomgit.com/CPF-RN/usage-docs/blob/master/en/link-source-code.md). |
| 100 | 102 | ||
| 101 | ### 3. Configuring CMakeLists and Introducing ImageRotatePackage | 103 | ### 3. Configuring CMakeLists and Introducing ImageRotatePackage |
| 102 | 104 | ||
| @@ -157,7 +159,7 @@ std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Cont | |||
| 157 | 159 | ||
| 158 | ### 4. Introducing RNImageRotatePackage to ArkTS | 160 | ### 4. Introducing RNImageRotatePackage to ArkTS |
| 159 | 161 | ||
| 160 | -Open the entry/src/main/ets/RNPackagesFactory.ts file and add the following code: | 162 | +Open `entry/src/main/ets/RNPackagesFactory.ets` and add: |
| 161 | 163 | ||
| 162 | ```diff | 164 | ```diff |
| 163 | ... | 165 | ... |
| @@ -333,11 +335,12 @@ ImageRotate.rotateImage( | |||
| 333 | 335 | ||
| 334 | ## Available APIs | 336 | ## Available APIs |
| 335 | 337 | ||
| 336 | -> [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library. | 338 | +> [!TIP] The "Platform" column indicates the platform where the properties are supported in the original third-party library. |
| 337 | 339 | ||
| 338 | -> [!TIP] If the value of **OpenHarmony Platform Support** is **yes**, it means that the OpenHarmony 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. | 340 | +> [!TIP] If the value of "OpenHarmony Platform Support" is "Yes", it means that the OpenHarmony 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. |
| 339 | 341 | ||
| 340 | ### API | 342 | ### API |
| 343 | + | ||
| 341 | | Name | Type | Parameter Type | Return Value | Required | Platform | OpenHarmony Platform Support | Description | | 344 | | Name | Type | Parameter Type | Return Value | Required | Platform | OpenHarmony Platform Support | Description | |
| 342 | |--------|---------|-----|-------|-------|--------|-----|-----------------| | 345 | |--------|---------|-----|-------|-------|--------|-----|-----------------| |
| 343 | | rotateImage | function | uri: string, angle: number, success: (uri: string) => void, failure: (error: Object) => void | void | no | iOS/Android | Yes | Rotates an image. Only angles that are multiples of 90 are supported, negative angles indicate counter-clockwise rotation; the success callback returns the URI of the rotated image, and the failure callback returns the error information.| | 346 | | rotateImage | function | uri: string, angle: number, success: (uri: string) => void, failure: (error: Object) => void | void | no | iOS/Android | Yes | Rotates an image. Only angles that are multiples of 90 are supported, negative angles indicate counter-clockwise rotation; the success callback returns the URI of the rotated image, and the failure callback returns the error information.| |
| @@ -345,9 +348,11 @@ ImageRotate.rotateImage( | |||
| 345 | ## Known Issues | 348 | ## Known Issues |
| 346 | 349 | ||
| 347 | ## Other | 350 | ## Other |
| 351 | + | ||
| 348 | None | 352 | None |
| 349 | 353 | ||
| 350 | ## Directory Structure | 354 | ## Directory Structure |
| 355 | + | ||
| 351 | ``` | 356 | ``` |
| 352 | /rntpc_react-native-image-rotate # Project root directory | 357 | /rntpc_react-native-image-rotate # Project root directory |
| 353 | ├── harmony # HarmonyOS adaptation code | 358 | ├── harmony # HarmonyOS adaptation code |
| @@ -367,7 +372,7 @@ None | |||
| 367 | 372 | ||
| 368 | ## How to Contribute | 373 | ## How to Contribute |
| 369 | 374 | ||
| 370 | -If you find any problem when using react-native-image-rotate, submit an [issue](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/issues) or a [PR](https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/pulls). | 375 | +If you find any problem when using react-native-image-rotate, submit an [issue](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/issues) or a [PR](https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/pulls). |
| 371 | 376 | ||
| 372 | ## License | 377 | ## License |
| 373 | 378 | ||
| @@ -1,190 +0,0 @@ | |||
| 1 | -import React, { Component } from 'react'; | ||
| 2 | -import { | ||
| 3 | - Image, | ||
| 4 | - StyleSheet, | ||
| 5 | - Text, | ||
| 6 | - View, | ||
| 7 | - TouchableOpacity, | ||
| 8 | - TextInput, | ||
| 9 | -} from 'react-native'; | ||
| 10 | -import{ | ||
| 11 | - Tester, | ||
| 12 | - TestSuite, | ||
| 13 | - TestCase, | ||
| 14 | -} from '@rnoh/testerino'; | ||
| 15 | - | ||
| 16 | -import ImageRotate from "react-native-image-rotate"; | ||
| 17 | - | ||
| 18 | -const SOURCE_IMAGE = 'https://filesamples.com/samples/image/jpg/sample_640×426.jpg'; | ||
| 19 | -const INVALID_IMAGE_URI = 'file:///invalid/path/not_a_real_image.jpg'; | ||
| 20 | - | ||
| 21 | -type ErrorTestState = { | ||
| 22 | - error: string | null; | ||
| 23 | -}; | ||
| 24 | - | ||
| 25 | -const waitForNativeCallback = (ms: number = 3000) => | ||
| 26 | - new Promise<void>((resolve) => setTimeout(resolve, ms)); | ||
| 27 | - | ||
| 28 | -class App extends Component { | ||
| 29 | - | ||
| 30 | - constructor() { | ||
| 31 | - super(); | ||
| 32 | - this.state = { | ||
| 33 | - image: SOURCE_IMAGE, | ||
| 34 | - currentAngle: 0, | ||
| 35 | - width: 150, | ||
| 36 | - height: 240, | ||
| 37 | - }; | ||
| 38 | - | ||
| 39 | - this.rotate = this.rotate.bind(this); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - rotate(angle) { | ||
| 43 | - const nextAngle = this.state.currentAngle + angle; | ||
| 44 | - ImageRotate.rotateImage( | ||
| 45 | - SOURCE_IMAGE, | ||
| 46 | - nextAngle, | ||
| 47 | - (uri) => { | ||
| 48 | - this.setState({ | ||
| 49 | - image: uri, | ||
| 50 | - currentAngle: nextAngle, | ||
| 51 | - width: this.state.height, | ||
| 52 | - height: this.state.width, | ||
| 53 | - }); | ||
| 54 | - }, | ||
| 55 | - (error) => { | ||
| 56 | - console.error(error); | ||
| 57 | - } | ||
| 58 | - ); | ||
| 59 | - } | ||
| 60 | - | ||
| 61 | - render() { | ||
| 62 | - return ( | ||
| 63 | - <Tester style = {styles.container}> | ||
| 64 | - <TestSuite name = "imageRotateTest"> | ||
| 65 | - <Text>{""}</Text> | ||
| 66 | - | ||
| 67 | - <TextInput> | ||
| 68 | - {} | ||
| 69 | - </TextInput> | ||
| 70 | - | ||
| 71 | - <TestCase | ||
| 72 | - itShould = "native rotate CW" | ||
| 73 | - tags = {['C_API']} | ||
| 74 | - initialState = {undefined as any} | ||
| 75 | - arrange = {({setState}) => { | ||
| 76 | - return ( | ||
| 77 | - <TouchableOpacity | ||
| 78 | - onPress = {() => { | ||
| 79 | - this.rotate(90); | ||
| 80 | - setState(true); | ||
| 81 | - }} | ||
| 82 | - style = {styles.btn}> | ||
| 83 | - <Text style = {styles.btnText} > 图片顺旋转 </Text> | ||
| 84 | - </TouchableOpacity> | ||
| 85 | - ); | ||
| 86 | - }} | ||
| 87 | - assert = {async ({expect, state}) => { | ||
| 88 | - expect((state as Buffer)).to.be.true; | ||
| 89 | - }} | ||
| 90 | - /> | ||
| 91 | - <TestCase | ||
| 92 | - itShould = "native rotate CCW" | ||
| 93 | - tags = {['C_API']} | ||
| 94 | - initialState = {undefined as any} | ||
| 95 | - arrange = {({setState}) => { | ||
| 96 | - return ( | ||
| 97 | - <TouchableOpacity | ||
| 98 | - onPress = {() => { | ||
| 99 | - this.rotate(-90); | ||
| 100 | - setState(true); | ||
| 101 | - }} | ||
| 102 | - style = {styles.btn}> | ||
| 103 | - <Text style = {styles.btnText} > 图片逆旋转 </Text> | ||
| 104 | - </TouchableOpacity> | ||
| 105 | - ); | ||
| 106 | - }} | ||
| 107 | - assert = {async ({expect, state}) => { | ||
| 108 | - expect((state as Buffer)).to.be.true; | ||
| 109 | - }} | ||
| 110 | - /> | ||
| 111 | - <TestCase | ||
| 112 | - itShould = "failure callback when PixelMap decode fails" | ||
| 113 | - tags = {['C_API']} | ||
| 114 | - initialState = {{ error: null } as ErrorTestState} | ||
| 115 | - arrange = {({setState}) => { | ||
| 116 | - return ( | ||
| 117 | - <TouchableOpacity | ||
| 118 | - onPress = {() => { | ||
| 119 | - ImageRotate.rotateImage( | ||
| 120 | - INVALID_IMAGE_URI, | ||
| 121 | - 90, | ||
| 122 | - () => { | ||
| 123 | - setState({ error: '__success_unexpected__' }); | ||
| 124 | - }, | ||
| 125 | - (error) => { | ||
| 126 | - setState({ error: String(error) }); | ||
| 127 | - }, | ||
| 128 | - ); | ||
| 129 | - }} | ||
| 130 | - style = {styles.btn}> | ||
| 131 | - <Text style = {styles.btnText}> 测试 PixelMap 解码失败 </Text> | ||
| 132 | - </TouchableOpacity> | ||
| 133 | - ); | ||
| 134 | - }} | ||
| 135 | - assert = {async ({expect, state}) => { | ||
| 136 | - await waitForNativeCallback(); | ||
| 137 | - const { error } = state as ErrorTestState; | ||
| 138 | - expect(error).to.not.be.null; | ||
| 139 | - expect(error).to.contain('Cannot open bitmap'); | ||
| 140 | - }} | ||
| 141 | - /> | ||
| 142 | - </TestSuite> | ||
| 143 | - <View style={styles.imageContainer}> | ||
| 144 | - <Image style={{width: this.state.width, height: this.state.height}} resizeMode="contain" source={{uri: this.state.image}} /> | ||
| 145 | - </View> | ||
| 146 | - </Tester> | ||
| 147 | - ); | ||
| 148 | - } | ||
| 149 | -} | ||
| 150 | - | ||
| 151 | -const styles = StyleSheet.create({ | ||
| 152 | - container: { | ||
| 153 | - flex: 1, | ||
| 154 | - justifyContent: 'center', | ||
| 155 | - alignItems: 'center', | ||
| 156 | - }, | ||
| 157 | - imageContainer: { | ||
| 158 | - height: 240, | ||
| 159 | - justifyContent: 'center', | ||
| 160 | - }, | ||
| 161 | - btn: { | ||
| 162 | - alignItems: 'center', | ||
| 163 | - justifyContent: 'center', | ||
| 164 | - backgroundColor: 'blue', | ||
| 165 | - padding: 10, | ||
| 166 | - borderRadius: 5, | ||
| 167 | - }, | ||
| 168 | - btnText: { | ||
| 169 | - color: 'white', | ||
| 170 | - fontSize: 16, | ||
| 171 | -}, | ||
| 172 | -}); | ||
| 173 | - | ||
| 174 | - | ||
| 175 | -export const displayName = 'react-native-image-rotate'; | ||
| 176 | -export const framework = 'React'; | ||
| 177 | -export const category = 'UI'; | ||
| 178 | -export const title = 'react-native-image-rotate'; | ||
| 179 | -export const documentationURL = 'https://github.com/react-native-oh-library/RNOHDCS/tree/main/react-native-image-rotate'; | ||
| 180 | -export const description = 'React Native image rotate'; | ||
| 181 | -export const examples = [ | ||
| 182 | - { | ||
| 183 | - title: 'React Native image rotate', | ||
| 184 | - render: function (): any { | ||
| 185 | - return <App />; | ||
| 186 | - }, | ||
| 187 | - }, | ||
| 188 | - ]; | ||
| 189 | - | ||
| 190 | -export default App; | ||
| @@ -6,6 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | import {AppRegistry} from 'react-native'; | 7 | import {AppRegistry} from 'react-native'; |
| 8 | import {name as appName} from './app.json'; | 8 | import {name as appName} from './app.json'; |
| 9 | -import App from './App'; | 9 | +import App from './src/Home'; |
| 10 | 10 | ||
| 11 | AppRegistry.registerComponent(appName, () => App); | 11 | AppRegistry.registerComponent(appName, () => App); |
| @@ -8,7 +8,7 @@ | |||
| 8 | "start": "hdc rport tcp:8081 tcp:8081 && react-native start", | 8 | "start": "hdc rport tcp:8081 tcp:8081 && react-native start", |
| 9 | "codegen": "react-native codegen-harmony --cpp-output-path ./harmony/entry/src/main/cpp/generated --rnoh-module-path ./harmony/entry/oh_modules/@rnoh/react-native-openharmony", | 9 | "codegen": "react-native codegen-harmony --cpp-output-path ./harmony/entry/src/main/cpp/generated --rnoh-module-path ./harmony/entry/oh_modules/@rnoh/react-native-openharmony", |
| 10 | "pack:pkg": "cd ../ && npm pack && cd ./example", | 10 | "pack:pkg": "cd ../ && npm pack && cd ./example", |
| 11 | - "install:pkg": "npm uninstall @react-native-ohos/react-native-image-rotate && npm run pack:pkg && npm i @react-native-ohos/react-native-image-rotate@file:../react-native-ohos-react-native-image-rotate-2.1.2-beta.1.tgz --legacy-peer-deps", | 11 | + "install:pkg": "npm uninstall @react-native-ohos/react-native-image-rotate && npm run pack:pkg && npm i @react-native-ohos/react-native-image-rotate@file:../react-native-ohos-react-native-image-rotate-2.1.2-beta.2.tgz --legacy-peer-deps", |
| 12 | "dev": "npm run codegen && react-native bundle-harmony --dev --minify=false", | 12 | "dev": "npm run codegen && react-native bundle-harmony --dev --minify=false", |
| 13 | "prod": "npm run codegen && react-native bundle-harmony --dev=false --minify=true", | 13 | "prod": "npm run codegen && react-native bundle-harmony --dev=false --minify=true", |
| 14 | "postinstall": "node ./scripts/create-build-profile", | 14 | "postinstall": "node ./scripts/create-build-profile", |
| @@ -17,7 +17,7 @@ | |||
| 17 | "dependencies": { | 17 | "dependencies": { |
| 18 | "@gorhom/portal": "^1.0.14", | 18 | "@gorhom/portal": "^1.0.14", |
| 19 | "@react-native-oh/react-native-harmony": "0.72.140", | 19 | "@react-native-oh/react-native-harmony": "0.72.140", |
| 20 | - "@react-native-ohos/react-native-image-rotate": "file:../react-native-ohos-react-native-image-rotate-2.1.2-beta.1.tgz", | 20 | + "@react-native-ohos/react-native-image-rotate": "file:../react-native-ohos-react-native-image-rotate-2.1.2-beta.2.tgz", |
| 21 | "@rnoh/testerino": "npm:@react-native-oh-tpl/testerino@0.0.9", | 21 | "@rnoh/testerino": "npm:@react-native-oh-tpl/testerino@0.0.9", |
| 22 | "react": "18.2.0", | 22 | "react": "18.2.0", |
| 23 | "react-native": "0.72.5", | 23 | "react-native": "0.72.5", |
| @@ -0,0 +1,95 @@ | |||
| 1 | +import React, {useState} from 'react'; | ||
| 2 | +import {StatusBar, StyleSheet, Text, TouchableOpacity, View} from 'react-native'; | ||
| 3 | +import UpstreamDemo from './index'; | ||
| 4 | +import HarmonyDemo from './harmonyTestDemo'; | ||
| 5 | + | ||
| 6 | +export default function Home() { | ||
| 7 | + const [screen, setScreen] = useState('home'); | ||
| 8 | + | ||
| 9 | + if (screen === 'upstream') { | ||
| 10 | + return ( | ||
| 11 | + <View style={styles.screen}> | ||
| 12 | + <TouchableOpacity | ||
| 13 | + style={styles.backButton} | ||
| 14 | + onPress={() => setScreen('home')}> | ||
| 15 | + <Text style={styles.backText}>返回首页</Text> | ||
| 16 | + </TouchableOpacity> | ||
| 17 | + <UpstreamDemo /> | ||
| 18 | + </View> | ||
| 19 | + ); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + if (screen === 'harmony') { | ||
| 23 | + return ( | ||
| 24 | + <View style={styles.screen}> | ||
| 25 | + <TouchableOpacity | ||
| 26 | + style={styles.backButton} | ||
| 27 | + onPress={() => setScreen('home')}> | ||
| 28 | + <Text style={styles.backText}>返回首页</Text> | ||
| 29 | + </TouchableOpacity> | ||
| 30 | + <HarmonyDemo /> | ||
| 31 | + </View> | ||
| 32 | + ); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + return ( | ||
| 36 | + <View style={styles.container}> | ||
| 37 | + <Text style={styles.title}>react-native-image-rotate Demo</Text> | ||
| 38 | + <TouchableOpacity | ||
| 39 | + style={styles.button} | ||
| 40 | + onPress={() => setScreen('upstream')}> | ||
| 41 | + <Text style={styles.buttonText}>上游demo</Text> | ||
| 42 | + </TouchableOpacity> | ||
| 43 | + <TouchableOpacity | ||
| 44 | + style={styles.button} | ||
| 45 | + onPress={() => setScreen('harmony')}> | ||
| 46 | + <Text style={styles.buttonText}>鸿蒙demo</Text> | ||
| 47 | + </TouchableOpacity> | ||
| 48 | + </View> | ||
| 49 | + ); | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +const styles = StyleSheet.create({ | ||
| 53 | + screen: { | ||
| 54 | + flex: 1, | ||
| 55 | + backgroundColor: '#F5FCFF', | ||
| 56 | + }, | ||
| 57 | + container: { | ||
| 58 | + flex: 1, | ||
| 59 | + justifyContent: 'center', | ||
| 60 | + alignItems: 'center', | ||
| 61 | + backgroundColor: '#F5FCFF', | ||
| 62 | + }, | ||
| 63 | + title: { | ||
| 64 | + fontSize: 20, | ||
| 65 | + textAlign: 'center', | ||
| 66 | + margin: 10, | ||
| 67 | + }, | ||
| 68 | + button: { | ||
| 69 | + padding: 10, | ||
| 70 | + margin: 10, | ||
| 71 | + minWidth: 160, | ||
| 72 | + borderWidth: 1, | ||
| 73 | + borderColor: 'white', | ||
| 74 | + borderRadius: 5, | ||
| 75 | + backgroundColor: 'grey', | ||
| 76 | + alignItems: 'center', | ||
| 77 | + }, | ||
| 78 | + buttonText: { | ||
| 79 | + color: '#ffffff', | ||
| 80 | + fontSize: 16, | ||
| 81 | + }, | ||
| 82 | + backButton: { | ||
| 83 | + padding: 8, | ||
| 84 | + margin: 8, | ||
| 85 | + marginTop: (StatusBar.currentHeight || 0) + 12, | ||
| 86 | + alignSelf: 'flex-start', | ||
| 87 | + borderWidth: 1, | ||
| 88 | + borderColor: 'white', | ||
| 89 | + borderRadius: 3, | ||
| 90 | + backgroundColor: 'grey', | ||
| 91 | + }, | ||
| 92 | + backText: { | ||
| 93 | + color: '#ffffff', | ||
| 94 | + }, | ||
| 95 | +}); | ||
| @@ -0,0 +1,389 @@ | |||
| 1 | +import React, { Component } from 'react'; | ||
| 2 | +import { | ||
| 3 | + Image, | ||
| 4 | + StyleSheet, | ||
| 5 | + Text, | ||
| 6 | + View, | ||
| 7 | + TouchableOpacity, | ||
| 8 | + ScrollView, | ||
| 9 | + SafeAreaView, | ||
| 10 | + StatusBar, | ||
| 11 | +} from 'react-native'; | ||
| 12 | +import{ | ||
| 13 | + Tester, | ||
| 14 | + TestSuite, | ||
| 15 | + TestCase, | ||
| 16 | +} from '@rnoh/testerino'; | ||
| 17 | + | ||
| 18 | +import ImageRotate from "react-native-image-rotate"; | ||
| 19 | + | ||
| 20 | +const SOURCE_IMAGE = 'https://filesamples.com/samples/image/jpg/sample_640×426.jpg'; | ||
| 21 | +const INVALID_IMAGE_URI = 'file:///invalid/path/not_a_real_image.jpg'; | ||
| 22 | +// 不存在的图片地址:HTTP 非 200 或传输失败都会走 failure 回调 | ||
| 23 | +const NETWORK_FAIL_URI = 'https://example.com/rn-image-rotate-not-exist-404.jpg'; | ||
| 24 | + | ||
| 25 | +// 正方形预览区:横图/竖图(±90°)都按最长边等比缩放,视觉大小一致 | ||
| 26 | +const PREVIEW_SIZE = 220; | ||
| 27 | +const BTN_WIDTH = 240; | ||
| 28 | + | ||
| 29 | +type UriTestState = { | ||
| 30 | + uri: string | null; | ||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +type ErrorTestState = { | ||
| 34 | + error: string | null; | ||
| 35 | +}; | ||
| 36 | + | ||
| 37 | +const waitForNativeCallback = (ms: number = 3000) => | ||
| 38 | + new Promise<void>((resolve) => setTimeout(resolve, ms)); | ||
| 39 | + | ||
| 40 | +class App extends Component { | ||
| 41 | + | ||
| 42 | + constructor() { | ||
| 43 | + super(); | ||
| 44 | + this.state = { | ||
| 45 | + image: SOURCE_IMAGE, | ||
| 46 | + currentAngle: 0, | ||
| 47 | + }; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + render() { | ||
| 51 | + return ( | ||
| 52 | + <SafeAreaView style={styles.safeArea}> | ||
| 53 | + <StatusBar barStyle="dark-content" translucent={false} /> | ||
| 54 | + <ScrollView | ||
| 55 | + style={styles.scroll} | ||
| 56 | + contentContainerStyle={styles.scrollContent} | ||
| 57 | + keyboardShouldPersistTaps="handled" | ||
| 58 | + > | ||
| 59 | + <Tester style = {styles.container}> | ||
| 60 | + <TestSuite name = "imageRotateTest"> | ||
| 61 | + <TestCase | ||
| 62 | + key = "rotateImage_cw" | ||
| 63 | + itShould = "native rotate CW" | ||
| 64 | + tags = {['C_API']} | ||
| 65 | + initialState = {{ uri: null } as UriTestState} | ||
| 66 | + arrange = {({setState}) => { | ||
| 67 | + return ( | ||
| 68 | + <View style={styles.caseWrap}> | ||
| 69 | + <TouchableOpacity | ||
| 70 | + onPress = {() => { | ||
| 71 | + ImageRotate.rotateImage( | ||
| 72 | + SOURCE_IMAGE, | ||
| 73 | + 90, | ||
| 74 | + (uri) => { | ||
| 75 | + this.setState({ | ||
| 76 | + image: uri, | ||
| 77 | + currentAngle: 90, | ||
| 78 | + }); | ||
| 79 | + setState({ uri }); | ||
| 80 | + }, | ||
| 81 | + (error) => { | ||
| 82 | + setState({ uri: '__failure__' }); | ||
| 83 | + console.error(error); | ||
| 84 | + }, | ||
| 85 | + ); | ||
| 86 | + }} | ||
| 87 | + style = {styles.btn}> | ||
| 88 | + <Text style = {styles.btnText} numberOfLines={1}> 图片顺旋转 </Text> | ||
| 89 | + </TouchableOpacity> | ||
| 90 | + </View> | ||
| 91 | + ); | ||
| 92 | + }} | ||
| 93 | + assert = {async ({expect, state}) => { | ||
| 94 | + await waitForNativeCallback(); | ||
| 95 | + const { uri } = state as UriTestState; | ||
| 96 | + expect(uri).to.not.be.null; | ||
| 97 | + expect(uri).to.be.a('string').that.is.not.empty; | ||
| 98 | + expect(uri).to.not.contain('__failure__'); | ||
| 99 | + }} | ||
| 100 | + /> | ||
| 101 | + <TestCase | ||
| 102 | + key = "rotateImage_ccw" | ||
| 103 | + itShould = "native rotate CCW" | ||
| 104 | + tags = {['C_API']} | ||
| 105 | + initialState = {{ uri: null } as UriTestState} | ||
| 106 | + arrange = {({setState}) => { | ||
| 107 | + return ( | ||
| 108 | + <View style={styles.caseWrap}> | ||
| 109 | + <TouchableOpacity | ||
| 110 | + onPress = {() => { | ||
| 111 | + ImageRotate.rotateImage( | ||
| 112 | + SOURCE_IMAGE, | ||
| 113 | + -90, | ||
| 114 | + (uri) => { | ||
| 115 | + this.setState({ | ||
| 116 | + image: uri, | ||
| 117 | + currentAngle: -90, | ||
| 118 | + }); | ||
| 119 | + setState({ uri }); | ||
| 120 | + }, | ||
| 121 | + (error) => { | ||
| 122 | + setState({ uri: '__failure__' }); | ||
| 123 | + console.error(error); | ||
| 124 | + }, | ||
| 125 | + ); | ||
| 126 | + }} | ||
| 127 | + style = {styles.btn}> | ||
| 128 | + <Text style = {styles.btnText} numberOfLines={1}> 图片逆旋转 </Text> | ||
| 129 | + </TouchableOpacity> | ||
| 130 | + </View> | ||
| 131 | + ); | ||
| 132 | + }} | ||
| 133 | + assert = {async ({expect, state}) => { | ||
| 134 | + await waitForNativeCallback(); | ||
| 135 | + const { uri } = state as UriTestState; | ||
| 136 | + expect(uri).to.not.be.null; | ||
| 137 | + expect(uri).to.be.a('string').that.is.not.empty; | ||
| 138 | + expect(uri).to.not.contain('__failure__'); | ||
| 139 | + }} | ||
| 140 | + /> | ||
| 141 | + <TestCase | ||
| 142 | + key = "rotateImage_decode_fail" | ||
| 143 | + itShould = "failure callback when PixelMap decode fails" | ||
| 144 | + tags = {['C_API']} | ||
| 145 | + initialState = {{ error: null } as ErrorTestState} | ||
| 146 | + arrange = {({setState}) => { | ||
| 147 | + return ( | ||
| 148 | + <View style={styles.caseWrap}> | ||
| 149 | + <TouchableOpacity | ||
| 150 | + onPress = {() => { | ||
| 151 | + ImageRotate.rotateImage( | ||
| 152 | + INVALID_IMAGE_URI, | ||
| 153 | + 90, | ||
| 154 | + () => { | ||
| 155 | + setState({ error: '__success_unexpected__' }); | ||
| 156 | + }, | ||
| 157 | + (error) => { | ||
| 158 | + setState({ error: String(error) }); | ||
| 159 | + }, | ||
| 160 | + ); | ||
| 161 | + }} | ||
| 162 | + style = {styles.btn}> | ||
| 163 | + <Text style = {styles.btnText} numberOfLines={1}> 测试 PixelMap 解码失败 </Text> | ||
| 164 | + </TouchableOpacity> | ||
| 165 | + </View> | ||
| 166 | + ); | ||
| 167 | + }} | ||
| 168 | + assert = {async ({expect, state}) => { | ||
| 169 | + await waitForNativeCallback(); | ||
| 170 | + const { error } = state as ErrorTestState; | ||
| 171 | + expect(error).to.not.be.null; | ||
| 172 | + expect(error).to.contain('Cannot open bitmap'); | ||
| 173 | + }} | ||
| 174 | + /> | ||
| 175 | + <TestCase | ||
| 176 | + key = "rotateImage_empty_uri" | ||
| 177 | + itShould = "throw when URI is empty string" | ||
| 178 | + tags = {['C_API']} | ||
| 179 | + initialState = {{ error: null } as ErrorTestState} | ||
| 180 | + arrange = {({setState}) => { | ||
| 181 | + return ( | ||
| 182 | + <View style={styles.caseWrap}> | ||
| 183 | + <TouchableOpacity | ||
| 184 | + onPress = {() => { | ||
| 185 | + try { | ||
| 186 | + ImageRotate.rotateImage( | ||
| 187 | + '', | ||
| 188 | + 90, | ||
| 189 | + () => { | ||
| 190 | + setState({ error: '__success_unexpected__' }); | ||
| 191 | + }, | ||
| 192 | + (error) => { | ||
| 193 | + setState({ error: String(error) }); | ||
| 194 | + }, | ||
| 195 | + ); | ||
| 196 | + } catch (e) { | ||
| 197 | + setState({ error: String(e) }); | ||
| 198 | + } | ||
| 199 | + }} | ||
| 200 | + style = {styles.btn}> | ||
| 201 | + <Text style = {styles.btnText} numberOfLines={1}> 测试空 URI </Text> | ||
| 202 | + </TouchableOpacity> | ||
| 203 | + </View> | ||
| 204 | + ); | ||
| 205 | + }} | ||
| 206 | + assert = {async ({expect, state}) => { | ||
| 207 | + await waitForNativeCallback(500); | ||
| 208 | + const { error } = state as ErrorTestState; | ||
| 209 | + expect(error).to.not.be.null; | ||
| 210 | + expect(error).to.contain('Please specify a URI'); | ||
| 211 | + }} | ||
| 212 | + /> | ||
| 213 | + <TestCase | ||
| 214 | + key = "rotateImage_null_uri" | ||
| 215 | + itShould = "throw when URI is null" | ||
| 216 | + tags = {['C_API']} | ||
| 217 | + initialState = {{ error: null } as ErrorTestState} | ||
| 218 | + arrange = {({setState}) => { | ||
| 219 | + return ( | ||
| 220 | + <View style={styles.caseWrap}> | ||
| 221 | + <TouchableOpacity | ||
| 222 | + onPress = {() => { | ||
| 223 | + try { | ||
| 224 | + ImageRotate.rotateImage( | ||
| 225 | + null as any, | ||
| 226 | + 90, | ||
| 227 | + () => { | ||
| 228 | + setState({ error: '__success_unexpected__' }); | ||
| 229 | + }, | ||
| 230 | + (error) => { | ||
| 231 | + setState({ error: String(error) }); | ||
| 232 | + }, | ||
| 233 | + ); | ||
| 234 | + } catch (e) { | ||
| 235 | + setState({ error: String(e) }); | ||
| 236 | + } | ||
| 237 | + }} | ||
| 238 | + style = {styles.btn}> | ||
| 239 | + <Text style = {styles.btnText} numberOfLines={1}> 测试 null URI </Text> | ||
| 240 | + </TouchableOpacity> | ||
| 241 | + </View> | ||
| 242 | + ); | ||
| 243 | + }} | ||
| 244 | + assert = {async ({expect, state}) => { | ||
| 245 | + await waitForNativeCallback(500); | ||
| 246 | + const { error } = state as ErrorTestState; | ||
| 247 | + expect(error).to.not.be.null; | ||
| 248 | + expect(error).to.contain('Please specify a URI'); | ||
| 249 | + }} | ||
| 250 | + /> | ||
| 251 | + <TestCase | ||
| 252 | + key = "rotateImage_angle_45" | ||
| 253 | + itShould = "native rotate with non-90 multiple angle (45)" | ||
| 254 | + tags = {['C_API']} | ||
| 255 | + initialState = {{ uri: null } as UriTestState} | ||
| 256 | + arrange = {({setState}) => { | ||
| 257 | + return ( | ||
| 258 | + <View style={styles.caseWrap}> | ||
| 259 | + <TouchableOpacity | ||
| 260 | + onPress = {() => { | ||
| 261 | + ImageRotate.rotateImage( | ||
| 262 | + SOURCE_IMAGE, | ||
| 263 | + 45, | ||
| 264 | + (uri) => { | ||
| 265 | + setState({ uri }); | ||
| 266 | + }, | ||
| 267 | + (error) => { | ||
| 268 | + setState({ uri: '__failure__' }); | ||
| 269 | + console.error(error); | ||
| 270 | + }, | ||
| 271 | + ); | ||
| 272 | + }} | ||
| 273 | + style = {styles.btn}> | ||
| 274 | + <Text style = {styles.btnText} numberOfLines={1}> 测试 45° 旋转 </Text> | ||
| 275 | + </TouchableOpacity> | ||
| 276 | + </View> | ||
| 277 | + ); | ||
| 278 | + }} | ||
| 279 | + assert = {async ({expect, state}) => { | ||
| 280 | + await waitForNativeCallback(); | ||
| 281 | + const { uri } = state as UriTestState; | ||
| 282 | + expect(uri).to.not.be.null; | ||
| 283 | + expect(uri).to.be.a('string').that.is.not.empty; | ||
| 284 | + expect(uri).to.not.contain('__failure__'); | ||
| 285 | + }} | ||
| 286 | + /> | ||
| 287 | + <TestCase | ||
| 288 | + key = "rotateImage_network_fail" | ||
| 289 | + itShould = "failure callback when remote image download fails" | ||
| 290 | + tags = {['C_API']} | ||
| 291 | + initialState = {{ error: null } as ErrorTestState} | ||
| 292 | + arrange = {({setState}) => { | ||
| 293 | + return ( | ||
| 294 | + <View style={styles.caseWrap}> | ||
| 295 | + <TouchableOpacity | ||
| 296 | + onPress = {() => { | ||
| 297 | + ImageRotate.rotateImage( | ||
| 298 | + NETWORK_FAIL_URI, | ||
| 299 | + 90, | ||
| 300 | + () => { | ||
| 301 | + setState({ error: '__success_unexpected__' }); | ||
| 302 | + }, | ||
| 303 | + (error) => { | ||
| 304 | + setState({ error: String(error) }); | ||
| 305 | + }, | ||
| 306 | + ); | ||
| 307 | + }} | ||
| 308 | + style = {styles.btn}> | ||
| 309 | + <Text style = {styles.btnText} numberOfLines={1}> 测试网络下载失败 </Text> | ||
| 310 | + </TouchableOpacity> | ||
| 311 | + </View> | ||
| 312 | + ); | ||
| 313 | + }} | ||
| 314 | + assert = {async ({expect, state}) => { | ||
| 315 | + await waitForNativeCallback(8000); | ||
| 316 | + const { error } = state as ErrorTestState; | ||
| 317 | + expect(error).to.not.be.null; | ||
| 318 | + expect(error).to.be.a('string').that.is.not.empty; | ||
| 319 | + // 排除误入 success;HTTP 非 200 / 传输失败都会走 failure | ||
| 320 | + expect(error).to.not.equal('__success_unexpected__'); | ||
| 321 | + }} | ||
| 322 | + /> | ||
| 323 | + </TestSuite> | ||
| 324 | + <View style={styles.imageContainer}> | ||
| 325 | + <Image | ||
| 326 | + style={styles.previewImage} | ||
| 327 | + resizeMode="contain" | ||
| 328 | + source={{uri: this.state.image}} | ||
| 329 | + /> | ||
| 330 | + </View> | ||
| 331 | + </Tester> | ||
| 332 | + </ScrollView> | ||
| 333 | + </SafeAreaView> | ||
| 334 | + ); | ||
| 335 | + } | ||
| 336 | +} | ||
| 337 | + | ||
| 338 | +const styles = StyleSheet.create({ | ||
| 339 | + safeArea: { | ||
| 340 | + flex: 1, | ||
| 341 | + backgroundColor: '#ffffff' | ||
| 342 | + }, | ||
| 343 | + scroll: { | ||
| 344 | + flex: 1, | ||
| 345 | + }, | ||
| 346 | + scrollContent: { | ||
| 347 | + flexGrow: 1, | ||
| 348 | + paddingBottom: 24, | ||
| 349 | + alignItems: 'center', | ||
| 350 | + }, | ||
| 351 | + container: { | ||
| 352 | + width: '100%', | ||
| 353 | + alignSelf: 'center', | ||
| 354 | + alignItems: 'center', | ||
| 355 | + overflow: 'hidden', | ||
| 356 | + }, | ||
| 357 | + caseWrap: { | ||
| 358 | + width: BTN_WIDTH, | ||
| 359 | + alignSelf: 'center', | ||
| 360 | + overflow: 'hidden', | ||
| 361 | + }, | ||
| 362 | + imageContainer: { | ||
| 363 | + width: PREVIEW_SIZE, | ||
| 364 | + height: PREVIEW_SIZE, | ||
| 365 | + justifyContent: 'center', | ||
| 366 | + alignItems: 'center', | ||
| 367 | + overflow: 'hidden', | ||
| 368 | + }, | ||
| 369 | + previewImage: { | ||
| 370 | + width: PREVIEW_SIZE, | ||
| 371 | + height: PREVIEW_SIZE, | ||
| 372 | + }, | ||
| 373 | + btn: { | ||
| 374 | + width: BTN_WIDTH, | ||
| 375 | + alignItems: 'center', | ||
| 376 | + justifyContent: 'center', | ||
| 377 | + backgroundColor: 'blue', | ||
| 378 | + paddingVertical: 10, | ||
| 379 | + paddingHorizontal: 12, | ||
| 380 | + borderRadius: 5, | ||
| 381 | + }, | ||
| 382 | + btnText: { | ||
| 383 | + color: 'white', | ||
| 384 | + fontSize: 16, | ||
| 385 | + textAlign: 'center', | ||
| 386 | + }, | ||
| 387 | +}); | ||
| 388 | + | ||
| 389 | +export default App; | ||
| @@ -0,0 +1,95 @@ | |||
| 1 | +/** | ||
| 2 | + * Upstream demo from: | ||
| 3 | + * https://github.com/dgladkov/react-native-image-rotate/blob/master/Example/src/index.js | ||
| 4 | + */ | ||
| 5 | +import React, { Component } from 'react'; | ||
| 6 | +import { | ||
| 7 | + Image, | ||
| 8 | + StyleSheet, | ||
| 9 | + Text, | ||
| 10 | + TouchableHighlight, | ||
| 11 | + View, | ||
| 12 | +} from 'react-native'; | ||
| 13 | + | ||
| 14 | +import ImageRotate from 'react-native-image-rotate'; | ||
| 15 | + | ||
| 16 | +const SOURCE_IMAGE = | ||
| 17 | + 'https://upload.wikimedia.org/wikipedia/en/5/56/Warcraft_Teaser_Poster.jpg'; | ||
| 18 | + | ||
| 19 | +export default class App extends Component { | ||
| 20 | + constructor() { | ||
| 21 | + super(); | ||
| 22 | + this.state = { | ||
| 23 | + image: SOURCE_IMAGE, | ||
| 24 | + currentAngle: 0, | ||
| 25 | + width: 150, | ||
| 26 | + height: 240, | ||
| 27 | + }; | ||
| 28 | + | ||
| 29 | + this.rotate = this.rotate.bind(this); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + rotate(angle) { | ||
| 33 | + const nextAngle = this.state.currentAngle + angle; | ||
| 34 | + ImageRotate.rotateImage( | ||
| 35 | + SOURCE_IMAGE, | ||
| 36 | + nextAngle, | ||
| 37 | + (uri) => { | ||
| 38 | + this.setState({ | ||
| 39 | + image: uri, | ||
| 40 | + currentAngle: nextAngle, | ||
| 41 | + width: this.state.height, | ||
| 42 | + height: this.state.width, | ||
| 43 | + }); | ||
| 44 | + }, | ||
| 45 | + (error) => { | ||
| 46 | + console.error(error); | ||
| 47 | + }, | ||
| 48 | + ); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + render() { | ||
| 52 | + return ( | ||
| 53 | + <View style={styles.container}> | ||
| 54 | + <View style={styles.imageContainer}> | ||
| 55 | + <Image | ||
| 56 | + style={{width: this.state.width, height: this.state.height}} | ||
| 57 | + source={{uri: this.state.image}} | ||
| 58 | + /> | ||
| 59 | + </View> | ||
| 60 | + <TouchableHighlight | ||
| 61 | + onPress={() => this.rotate(90)} | ||
| 62 | + style={styles.button}> | ||
| 63 | + <Text style={styles.text}>ROTATE CW</Text> | ||
| 64 | + </TouchableHighlight> | ||
| 65 | + | ||
| 66 | + <TouchableHighlight | ||
| 67 | + onPress={() => this.rotate(-90)} | ||
| 68 | + style={styles.button}> | ||
| 69 | + <Text style={styles.text}>ROTATE CCW</Text> | ||
| 70 | + </TouchableHighlight> | ||
| 71 | + </View> | ||
| 72 | + ); | ||
| 73 | + } | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +const styles = StyleSheet.create({ | ||
| 77 | + container: { | ||
| 78 | + flex: 1, | ||
| 79 | + justifyContent: 'center', | ||
| 80 | + alignItems: 'center', | ||
| 81 | + backgroundColor: '#F5FCFF', | ||
| 82 | + }, | ||
| 83 | + button: { | ||
| 84 | + backgroundColor: 'red', | ||
| 85 | + padding: 5, | ||
| 86 | + margin: 5, | ||
| 87 | + }, | ||
| 88 | + imageContainer: { | ||
| 89 | + height: 240, | ||
| 90 | + justifyContent: 'center', | ||
| 91 | + }, | ||
| 92 | + text: { | ||
| 93 | + color: 'white', | ||
| 94 | + }, | ||
| 95 | +}); | ||
| @@ -6,7 +6,7 @@ | |||
| 6 | "name": "@react-native-ohos/react-native-image-rotate", | 6 | "name": "@react-native-ohos/react-native-image-rotate", |
| 7 | "description": "Used for rotating images in React Native applications", | 7 | "description": "Used for rotating images in React Native applications", |
| 8 | "main": "Index.ets", | 8 | "main": "Index.ets", |
| 9 | - "version": "2.1.2-beta.1", | 9 | + "version": "2.1.2-beta.2", |
| 10 | "dependencies": { | 10 | "dependencies": { |
| 11 | "@rnoh/react-native-openharmony": "file:../react_native_openharmony" | 11 | "@rnoh/react-native-openharmony": "file:../react_native_openharmony" |
| 12 | } | 12 | } |
| @@ -35,20 +35,69 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 35 | 35 | ||
| 36 | private static TEMP_FILE_PREFIX: string = "ReactNative_rotated_image_"; | 36 | private static TEMP_FILE_PREFIX: string = "ReactNative_rotated_image_"; |
| 37 | private static COMPRESS_QUALITY: number = 90; | 37 | private static COMPRESS_QUALITY: number = 90; |
| 38 | + private static remoteImageBodyCache: Map<string, ArrayBuffer> = new Map(); | ||
| 39 | + private static readonly REMOTE_IMAGE_CACHE_MAX: number = 4; | ||
| 40 | + | ||
| 41 | + private static cacheRemoteImageBody(key: string, body: ArrayBuffer): void { | ||
| 42 | + if (RNImageRotateTurboModule.remoteImageBodyCache.has(key)) { | ||
| 43 | + RNImageRotateTurboModule.remoteImageBodyCache.delete(key); | ||
| 44 | + } | ||
| 45 | + RNImageRotateTurboModule.remoteImageBodyCache.set(key, body); | ||
| 46 | + while (RNImageRotateTurboModule.remoteImageBodyCache.size > RNImageRotateTurboModule.REMOTE_IMAGE_CACHE_MAX) { | ||
| 47 | + const oldest = RNImageRotateTurboModule.remoteImageBodyCache.keys().next().value; | ||
| 48 | + if (oldest === undefined) { | ||
| 49 | + break; | ||
| 50 | + } | ||
| 51 | + RNImageRotateTurboModule.remoteImageBodyCache.delete(oldest); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + private static normalizeRemoteRequestUrl(src: string): string { | ||
| 56 | + try { | ||
| 57 | + return encodeURI(decodeURI(src)); | ||
| 58 | + } catch (err) { | ||
| 59 | + return encodeURI(src); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + private static isRemoteUri(uri: string): boolean { | ||
| 64 | + return /^https?:\/\//i.test(uri); | ||
| 65 | + } | ||
| 66 | + | ||
| 38 | constructor(protected ctx: TurboModuleContext) { | 67 | constructor(protected ctx: TurboModuleContext) { |
| 39 | super(ctx); | 68 | super(ctx); |
| 40 | - const mcontext = this.ctx.uiAbilityContext; | 69 | + try { |
| 41 | - let cleanTask = new RNImageRotateTurboModule.CleanTask(mcontext); | 70 | + const mcontext = this.ctx.uiAbilityContext; |
| 42 | - cleanTask.cleanDirectory(); | 71 | + let cleanTask = new RNImageRotateTurboModule.CleanTask(mcontext); |
| 72 | + cleanTask.cleanDirectory(); | ||
| 73 | + } catch (err) { | ||
| 74 | + console.error("RNImageRotateTurboModule cleanDirectory on init failed: " + (err as BusinessError).message); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + __onDestroy__() { | ||
| 79 | + RNImageRotateTurboModule.remoteImageBodyCache.clear(); | ||
| 80 | + try { | ||
| 81 | + const mcontext = this.ctx.uiAbilityContext; | ||
| 82 | + let cleanTask = new RNImageRotateTurboModule.CleanTask(mcontext); | ||
| 83 | + cleanTask.cleanDirectory(); | ||
| 84 | + } catch (err) { | ||
| 85 | + console.error("RNImageRotateTurboModule cleanDirectory on destroy failed: " + (err as BusinessError).message); | ||
| 86 | + } | ||
| 43 | } | 87 | } |
| 44 | 88 | ||
| 45 | rotateImage(muri: string, mangle: number, success: (msuccess: string) => void, error: (merror: Object) => void) { | 89 | rotateImage(muri: string, mangle: number, success: (msuccess: string) => void, error: (merror: Object) => void) { |
| 46 | if (muri === null || muri === "") { | 90 | if (muri === null || muri === "") { |
| 47 | throw new Error("Please specify a URI"); | 91 | throw new Error("Please specify a URI"); |
| 48 | } | 92 | } |
| 93 | + if (typeof success !== 'function' || typeof error !== 'function') { | ||
| 94 | + throw new Error("Please specify success and error callbacks"); | ||
| 95 | + } | ||
| 96 | + if (!Number.isFinite(mangle)) { | ||
| 97 | + error("Invalid angle: " + mangle); | ||
| 98 | + return; | ||
| 99 | + } | ||
| 49 | const mcontext = this.ctx.uiAbilityContext; | 100 | const mcontext = this.ctx.uiAbilityContext; |
| 50 | - let cleanTask = new RNImageRotateTurboModule.CleanTask(mcontext); | ||
| 51 | - cleanTask.cleanDirectory(); | ||
| 52 | 101 | ||
| 53 | let rotateTask = new RNImageRotateTurboModule.RotateTask( | 102 | let rotateTask = new RNImageRotateTurboModule.RotateTask( |
| 54 | mcontext, | 103 | mcontext, |
| @@ -56,16 +105,23 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 56 | mangle, | 105 | mangle, |
| 57 | success, | 106 | success, |
| 58 | error); | 107 | error); |
| 59 | - rotateTask.openBitmapInputStream(rotateTask.mUri).then((imagePixelMap)=>{ | 108 | + rotateTask.openBitmapInputStream(rotateTask.mUri).then(async (imagePixelMap)=>{ |
| 60 | if (imagePixelMap === undefined) { | 109 | if (imagePixelMap === undefined) { |
| 61 | return; | 110 | return; |
| 62 | } | 111 | } |
| 63 | - imagePixelMap.rotate(rotateTask.mAngle).then(() => { | 112 | + try { |
| 64 | - rotateTask.doInBackgroundGuarded(imagePixelMap); | 113 | + await imagePixelMap.rotate(rotateTask.mAngle); |
| 65 | - }).catch((err: BusinessError) => { | 114 | + await rotateTask.doInBackgroundGuarded(imagePixelMap); |
【AI-Review】【一般】【基础代码问题】【代码逻辑错误】
● 问题: RNImageRotateTurboModule.ts 第 114 行将 ● 影响: 在 ● 建议: 将 ![]() ![]() | |||
| 66 | - console.error(`Failed to rotate pixelmap. code is ${err.code}, message is ${err.message}`); | 115 | + } catch (err) { |
| 67 | - rotateTask.mError(err.message); | 116 | + console.error(`Failed to rotate/pack pixelmap. code is ${(err as BusinessError).code}, message is ${(err as BusinessError).message}`); |
| 68 | - }); | 117 | + rotateTask.mError((err as BusinessError).message); |
| 118 | + } finally { | ||
| 119 | + try { | ||
| 120 | + await imagePixelMap.release(); | ||
| 121 | + } catch (releaseErr) { | ||
| 122 | + console.error("Failed to release pixelmap: " + (releaseErr as BusinessError).message); | ||
| 123 | + } | ||
| 124 | + } | ||
| 69 | }).catch((err: BusinessError) => { | 125 | }).catch((err: BusinessError) => { |
| 70 | console.error(`Failed to open bitmap input stream. code is ${err.code}, message is ${err.message}`); | 126 | console.error(`Failed to open bitmap input stream. code is ${err.code}, message is ${err.message}`); |
| 71 | rotateTask.mError(err.message); | 127 | rotateTask.mError(err.message); |
| @@ -118,33 +174,45 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 118 | 174 | ||
| 119 | // 网络图片转换为PixelMap | 175 | // 网络图片转换为PixelMap |
| 120 | private async getPixelMapFromURL(src: string): Promise<image.PixelMap> { | 176 | private async getPixelMapFromURL(src: string): Promise<image.PixelMap> { |
| 121 | - const httpRequest = http.createHttp(); | 177 | + let imageData: ArrayBuffer | undefined = RNImageRotateTurboModule.remoteImageBodyCache.get(src); |
| 122 | - try { | 178 | + if (imageData === undefined) { |
| 123 | - const data: http.HttpResponse = await httpRequest.request(src); | 179 | + const requestUrl = RNImageRotateTurboModule.normalizeRemoteRequestUrl(src); |
| 124 | - if (data.responseCode === http.ResponseCode.OK && data.result instanceof ArrayBuffer) { | 180 | + const httpRequest = http.createHttp(); |
| 125 | - if (data.header.hasOwnProperty('content-type')) { | 181 | + try { |
| 126 | - this.imageType = data.header['content-type']; | 182 | + const data: http.HttpResponse = await httpRequest.request(requestUrl, { |
| 127 | - } | 183 | + method: http.RequestMethod.GET, |
| 128 | - let imageData: ArrayBuffer = data.result; | 184 | + expectDataType: http.HttpDataType.ARRAY_BUFFER, |
| 129 | - const imageSource: image.ImageSource = image.createImageSource(imageData); | 185 | + usingProtocol: http.HttpProtocol.HTTP1_1, |
| 130 | - try { | 186 | + }); |
| 131 | - const imageInfo = await imageSource.getImageInfo(); | 187 | + if (data.responseCode === http.ResponseCode.OK && data.result instanceof ArrayBuffer) { |
| 132 | - const imageWidth = Math.round(imageInfo.size.width); | 188 | + if (data.header.hasOwnProperty('content-type')) { |
| 133 | - const imageHeight = Math.round(imageInfo.size.height); | 189 | + this.imageType = data.header['content-type']; |
| 134 | - const option: image.InitializationOptions = { | ||
| 135 | - 'alphaType': 0, | ||
| 136 | - 'editable': false, | ||
| 137 | - 'pixelFormat': 3, | ||
| 138 | - 'scaleMode': 1, | ||
| 139 | - 'size': { height: imageHeight, width: imageWidth }, | ||
| 140 | } | 190 | } |
| 141 | - return await imageSource.createPixelMap(option); | 191 | + imageData = data.result; |
| 142 | - } finally { | 192 | + RNImageRotateTurboModule.cacheRemoteImageBody(src, imageData); |
| 143 | - imageSource.release(); | ||
| 144 | } | 193 | } |
| 194 | + } finally { | ||
| 195 | + httpRequest.destroy(); | ||
| 145 | } | 196 | } |
| 197 | + } | ||
| 198 | + if (imageData === undefined) { | ||
| 199 | + return undefined; | ||
| 200 | + } | ||
| 201 | + const imageSource: image.ImageSource = image.createImageSource(imageData); | ||
| 202 | + try { | ||
| 203 | + const imageInfo = await imageSource.getImageInfo(); | ||
| 204 | + const imageWidth = Math.round(imageInfo.size.width); | ||
| 205 | + const imageHeight = Math.round(imageInfo.size.height); | ||
| 206 | + const option: image.InitializationOptions = { | ||
| 207 | + 'alphaType': 0, | ||
| 208 | + 'editable': false, | ||
| 209 | + 'pixelFormat': 3, | ||
| 210 | + 'scaleMode': 1, | ||
| 211 | + 'size': { height: imageHeight, width: imageWidth }, | ||
| 212 | + } | ||
| 213 | + return await imageSource.createPixelMap(option); | ||
| 146 | } finally { | 214 | } finally { |
| 147 | - httpRequest.destroy(); | 215 | + imageSource.release(); |
| 148 | } | 216 | } |
| 149 | } | 217 | } |
| 150 | 218 | ||
| @@ -156,7 +224,7 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 156 | let imagePackApi: image.ImagePacker | undefined = undefined; | 224 | let imagePackApi: image.ImagePacker | undefined = undefined; |
| 157 | let imageSourceFromBuffer: image.ImageSource | undefined = undefined; | 225 | let imageSourceFromBuffer: image.ImageSource | undefined = undefined; |
| 158 | try { | 226 | try { |
| 159 | - file = fs.openSync(src, fs.OpenMode.READ_WRITE); | 227 | + file = fs.openSync(src, fs.OpenMode.READ_ONLY); |
| 160 | imageSource = image.createImageSource(file.fd); | 228 | imageSource = image.createImageSource(file.fd); |
| 161 | imagePackApi = image.createImagePacker(); | 229 | imagePackApi = image.createImagePacker(); |
| 162 | const imageInfo = await imageSource.getImageInfo(); | 230 | const imageInfo = await imageSource.getImageInfo(); |
| @@ -184,7 +252,8 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 184 | if (file === undefined) { | 252 | if (file === undefined) { |
| 185 | throw new Error('Cannot open bitmap: ' + src); | 253 | throw new Error('Cannot open bitmap: ' + src); |
| 186 | } | 254 | } |
| 187 | - console.error("getPixelMapFromFile failed with error message: " + err.message + ", error code: " + err.code); | 255 | + console.error("getPixelMapFromFile failed with error message: " + (err as BusinessError).message + ", error code: " + (err as BusinessError).code); |
| 256 | + throw new Error('Cannot decode bitmap: ' + src); | ||
| 188 | } finally { | 257 | } finally { |
| 189 | if (imageSourceFromBuffer !== undefined) { | 258 | if (imageSourceFromBuffer !== undefined) { |
| 190 | imageSourceFromBuffer.release(); | 259 | imageSourceFromBuffer.release(); |
| @@ -204,7 +273,7 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 204 | async openBitmapInputStream(muri:string): Promise<image.PixelMap> { | 273 | async openBitmapInputStream(muri:string): Promise<image.PixelMap> { |
| 205 | try { | 274 | try { |
| 206 | let imagePixelMap: image.PixelMap | undefined = undefined; | 275 | let imagePixelMap: image.PixelMap | undefined = undefined; |
| 207 | - if (muri.includes('http')) { | 276 | + if (RNImageRotateTurboModule.isRemoteUri(muri)) { |
| 208 | imagePixelMap = await this.getPixelMapFromURL(muri); | 277 | imagePixelMap = await this.getPixelMapFromURL(muri); |
| 209 | } else { | 278 | } else { |
| 210 | imagePixelMap = await this.getPixelMapFromFile(muri); | 279 | imagePixelMap = await this.getPixelMapFromFile(muri); |
| @@ -215,8 +284,8 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 215 | } | 284 | } |
| 216 | return imagePixelMap; | 285 | return imagePixelMap; |
| 217 | } catch (err) { | 286 | } catch (err) { |
| 218 | - console.error('openBitmapInputStream failed: ' + err.message); | 287 | + console.error('openBitmapInputStream failed: ' + (err as BusinessError).message); |
| 219 | - this.mError(err.message); | 288 | + this.mError((err as BusinessError).message); |
| 220 | return undefined; | 289 | return undefined; |
| 221 | } | 290 | } |
| 222 | } | 291 | } |
| @@ -234,14 +303,22 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 234 | await fs.write(tempFile.fd, buf); | 303 | await fs.write(tempFile.fd, buf); |
| 235 | this.mSuccess(src); | 304 | this.mSuccess(src); |
| 236 | } catch (err) { | 305 | } catch (err) { |
| 237 | - console.info("生成路径失败 "+ err.message); | 306 | + console.info("生成路径失败 "+ (err as BusinessError).message); |
| 238 | - this.mError(err.message); | 307 | + this.mError((err as BusinessError).message); |
| 239 | } finally { | 308 | } finally { |
| 240 | - if (imagePackerApi !== undefined) { | 309 | + try { |
| 241 | - imagePackerApi.release(); | 310 | + if (imagePackerApi !== undefined) { |
| 311 | + imagePackerApi.release(); | ||
| 312 | + } | ||
| 313 | + } catch (releaseErr) { | ||
| 314 | + console.error("Failed to release imagePacker: " + (releaseErr as BusinessError).message); | ||
| 242 | } | 315 | } |
| 243 | - if (tempFile !== undefined) { | 316 | + try { |
| 244 | - fs.closeSync(tempFile.fd); | 317 | + if (tempFile !== undefined) { |
| 318 | + fs.closeSync(tempFile.fd); | ||
| 319 | + } | ||
| 320 | + } catch (closeErr) { | ||
| 321 | + console.error("Failed to close temp file: " + (closeErr as BusinessError).message); | ||
| 245 | } | 322 | } |
| 246 | } | 323 | } |
| 247 | } | 324 | } |
| @@ -260,4 +337,4 @@ export class RNImageRotateTurboModule extends TurboModule implements TM.ImageRot | |||
| 260 | return ".jpg"; | 337 | return ".jpg"; |
| 261 | } | 338 | } |
| 262 | } | 339 | } |
| 263 | -} | 340 | +} |
| @@ -0,0 +1,27 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * This source code is licensed under the MIT license found in the | ||
| 5 | + * LICENSE file in the root directory of this source tree. | ||
| 6 | + */ | ||
| 7 | +'use strict'; | ||
| 8 | + | ||
| 9 | +const { TurboModuleRegistry, __nativeModule } = require('react-native'); | ||
| 10 | +const NativeImageRotate = require('../../src/NativeImageRotate').default; | ||
| 11 | + | ||
| 12 | +describe('NativeImageRotate spec', () => { | ||
| 13 | + // TurboModuleRegistry.get runs while NativeImageRotate.ts is imported. | ||
| 14 | + const registryCalls = TurboModuleRegistry.get.mock.calls.slice(); | ||
| 15 | + | ||
| 16 | + it('resolves the ImageRotateNativeModule at import time', () => { | ||
| 17 | + expect(registryCalls).toEqual([['ImageRotateNativeModule']]); | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + it('exports the resolved turbo module as the default export', () => { | ||
| 21 | + expect(NativeImageRotate).toBe(__nativeModule); | ||
| 22 | + }); | ||
| 23 | + | ||
| 24 | + it('exposes the rotateImage method required by the spec', () => { | ||
| 25 | + expect(typeof NativeImageRotate.rotateImage).toBe('function'); | ||
| 26 | + }); | ||
| 27 | +}); | ||
| @@ -0,0 +1,96 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * This source code is licensed under the MIT license found in the | ||
| 5 | + * LICENSE file in the root directory of this source tree. | ||
| 6 | + */ | ||
| 7 | +'use strict'; | ||
| 8 | + | ||
| 9 | +const { TurboModuleRegistry, __nativeModule } = require('react-native'); | ||
| 10 | +const ImageRotate = require('../../index').default; | ||
| 11 | + | ||
| 12 | +describe('ImageRotate', () => { | ||
| 13 | + // TurboModuleRegistry.get runs while index.js is imported, before the tests. | ||
| 14 | + const registryCalls = TurboModuleRegistry.get.mock.calls.slice(); | ||
| 15 | + | ||
| 16 | + beforeEach(() => { | ||
| 17 | + __nativeModule.rotateImage.mockClear(); | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + it('resolves the native module once at import time', () => { | ||
| 21 | + expect(registryCalls).toEqual([['ImageRotateNativeModule']]); | ||
| 22 | + }); | ||
| 23 | + | ||
| 24 | + it('exposes rotateImage as a static method', () => { | ||
| 25 | + expect(typeof ImageRotate.rotateImage).toBe('function'); | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + it('forwards uri, angle and callbacks to the native module', () => { | ||
| 29 | + const success = jest.fn(); | ||
| 30 | + const failure = jest.fn(); | ||
| 31 | + | ||
| 32 | + ImageRotate.rotateImage('file:///tmp/photo.jpg', 90, success, failure); | ||
| 33 | + | ||
| 34 | + expect(__nativeModule.rotateImage).toHaveBeenCalledTimes(1); | ||
| 35 | + expect(__nativeModule.rotateImage).toHaveBeenCalledWith( | ||
| 36 | + 'file:///tmp/photo.jpg', | ||
| 37 | + 90, | ||
| 38 | + success, | ||
| 39 | + failure, | ||
| 40 | + ); | ||
| 41 | + }); | ||
| 42 | + | ||
| 43 | + it('forwards negative angles for counter-clockwise rotation', () => { | ||
| 44 | + const success = jest.fn(); | ||
| 45 | + const failure = jest.fn(); | ||
| 46 | + | ||
| 47 | + ImageRotate.rotateImage( | ||
| 48 | + 'https://example.com/photo.jpg', | ||
| 49 | + -180, | ||
| 50 | + success, | ||
| 51 | + failure, | ||
| 52 | + ); | ||
| 53 | + | ||
| 54 | + expect(__nativeModule.rotateImage).toHaveBeenCalledWith( | ||
| 55 | + 'https://example.com/photo.jpg', | ||
| 56 | + -180, | ||
| 57 | + success, | ||
| 58 | + failure, | ||
| 59 | + ); | ||
| 60 | + }); | ||
| 61 | + | ||
| 62 | + it('forwards a zero angle without invoking either callback', () => { | ||
| 63 | + const success = jest.fn(); | ||
| 64 | + const failure = jest.fn(); | ||
| 65 | + | ||
| 66 | + ImageRotate.rotateImage('file:///tmp/photo.jpg', 0, success, failure); | ||
| 67 | + | ||
| 68 | + expect(__nativeModule.rotateImage).toHaveBeenCalledWith( | ||
| 69 | + 'file:///tmp/photo.jpg', | ||
| 70 | + 0, | ||
| 71 | + success, | ||
| 72 | + failure, | ||
| 73 | + ); | ||
| 74 | + expect(success).not.toHaveBeenCalled(); | ||
| 75 | + expect(failure).not.toHaveBeenCalled(); | ||
| 76 | + }); | ||
| 77 | + | ||
| 78 | + it('forwards custom callbacks as-is so native code can report results', () => { | ||
| 79 | + const success = jest.fn((rotatedUri) => rotatedUri); | ||
| 80 | + const failure = jest.fn((error) => error); | ||
| 81 | + | ||
| 82 | + ImageRotate.rotateImage('file:///tmp/photo.jpg', 270, success, failure); | ||
| 83 | + | ||
| 84 | + const [, , forwardedSuccess, forwardedFailure] = | ||
| 85 | + __nativeModule.rotateImage.mock.calls[0]; | ||
| 86 | + | ||
| 87 | + expect(forwardedSuccess).toBe(success); | ||
| 88 | + expect(forwardedFailure).toBe(failure); | ||
| 89 | + | ||
| 90 | + forwardedSuccess('file:///tmp/rotated.jpg'); | ||
| 91 | + forwardedFailure({ code: 'E_FAILED' }); | ||
| 92 | + | ||
| 93 | + expect(success).toHaveBeenCalledWith('file:///tmp/rotated.jpg'); | ||
| 94 | + expect(failure).toHaveBeenCalledWith({ code: 'E_FAILED' }); | ||
| 95 | + }); | ||
| 96 | +}); | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * This source code is licensed under the MIT license found in the | ||
| 5 | + * LICENSE file in the root directory of this source tree. | ||
| 6 | + */ | ||
| 7 | +'use strict'; | ||
| 8 | + | ||
| 9 | +module.exports = { | ||
| 10 | + presets: [ | ||
| 11 | + ['@babel/preset-env', { targets: { node: 'current' }, modules: 'commonjs' }], | ||
| 12 | + '@babel/preset-flow', | ||
| 13 | + ], | ||
| 14 | +}; | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * This source code is licensed under the MIT license found in the | ||
| 5 | + * LICENSE file in the root directory of this source tree. | ||
| 6 | + */ | ||
| 7 | +'use strict'; | ||
| 8 | + | ||
| 9 | +const path = require('path'); | ||
| 10 | + | ||
| 11 | +module.exports = { | ||
| 12 | + rootDir: path.resolve(__dirname, '..'), | ||
| 13 | + roots: ['<rootDir>/jest'], | ||
| 14 | + testEnvironment: 'node', | ||
| 15 | + transform: { | ||
| 16 | + '^.+\\.tsx?$': [ | ||
| 17 | + 'ts-jest', | ||
| 18 | + { | ||
| 19 | + tsconfig: path.join(__dirname, 'tsconfig.json'), | ||
| 20 | + diagnostics: false, | ||
| 21 | + }, | ||
| 22 | + ], | ||
| 23 | + '^.+\\.jsx?$': [ | ||
| 24 | + 'babel-jest', | ||
| 25 | + { | ||
| 26 | + configFile: path.join(__dirname, 'babel.config.js'), | ||
| 27 | + }, | ||
| 28 | + ], | ||
| 29 | + }, | ||
| 30 | + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
| 31 | + moduleNameMapper: { | ||
| 32 | + '^react-native$': '<rootDir>/jest/mocks/react-native.js', | ||
| 33 | + }, | ||
| 34 | + testMatch: [ | ||
| 35 | + '<rootDir>/jest/__tests__/**/*.test.js', | ||
| 36 | + '<rootDir>/jest/__tests__/**/*.test.ts', | ||
| 37 | + ], | ||
| 38 | + testPathIgnorePatterns: ['/node_modules/'], | ||
| 39 | + setupFiles: ['<rootDir>/jest/setup.js'], | ||
| 40 | + globals: { | ||
| 41 | + __DEV__: true, | ||
| 42 | + }, | ||
| 43 | + transformIgnorePatterns: ['node_modules/'], | ||
| 44 | + collectCoverageFrom: ['index.js', 'src/**/*.{ts,tsx}'], | ||
| 45 | + coverageDirectory: '<rootDir>/jest/coverage', | ||
| 46 | + coverageReporters: ['text', 'text-summary', 'lcov', 'html'], | ||
| 47 | + coverageThreshold: { | ||
| 48 | + global: { | ||
| 49 | + statements: 100, | ||
| 50 | + branches: 100, | ||
| 51 | + functions: 100, | ||
| 52 | + lines: 100, | ||
| 53 | + }, | ||
| 54 | + }, | ||
| 55 | +}; | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * This source code is licensed under the MIT license found in the | ||
| 5 | + * LICENSE file in the root directory of this source tree. | ||
| 6 | + */ | ||
| 7 | +'use strict'; | ||
| 8 | + | ||
| 9 | +// Stand-in for the native ImageRotate TurboModule. The library resolves this | ||
| 10 | +// module at import time through TurboModuleRegistry.get. | ||
| 11 | +const nativeModule = { | ||
| 12 | + rotateImage: jest.fn(), | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +const TurboModuleRegistry = { | ||
| 16 | + get: jest.fn((name) => | ||
| 17 | + name === 'ImageRotateNativeModule' ? nativeModule : null, | ||
| 18 | + ), | ||
| 19 | + getEnforcing: jest.fn(() => nativeModule), | ||
| 20 | +}; | ||
| 21 | + | ||
| 22 | +module.exports = { | ||
| 23 | + TurboModuleRegistry, | ||
| 24 | + __nativeModule: nativeModule, | ||
| 25 | +}; | ||
| @@ -0,0 +1,10 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * This source code is licensed under the MIT license found in the | ||
| 5 | + * LICENSE file in the root directory of this source tree. | ||
| 6 | + */ | ||
| 7 | +'use strict'; | ||
| 8 | + | ||
| 9 | +// React Native sources reference the __DEV__ global at runtime. | ||
| 10 | +global.__DEV__ = true; | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | +{ | ||
| 2 | + "compilerOptions": { | ||
| 3 | + "target": "ES2019", | ||
| 4 | + "module": "CommonJS", | ||
| 5 | + "moduleResolution": "node", | ||
| 6 | + "esModuleInterop": true, | ||
| 7 | + "allowSyntheticDefaultImports": true, | ||
| 8 | + "resolveJsonModule": true, | ||
| 9 | + "isolatedModules": true, | ||
| 10 | + "skipLibCheck": true, | ||
| 11 | + "strict": false, | ||
| 12 | + "types": ["jest", "node"] | ||
| 13 | + }, | ||
| 14 | + "include": ["../index.js", "../src/**/*.ts", "__tests__/**/*.ts"] | ||
| 15 | +} | ||
| @@ -1,10 +1,12 @@ | |||
| 1 | { | 1 | { |
| 2 | "name": "@react-native-ohos/react-native-image-rotate", | 2 | "name": "@react-native-ohos/react-native-image-rotate", |
| 3 | - "version": "2.1.2-beta.1", | 3 | + "version": "2.1.2-beta.2", |
| 4 | "description": "Rotate images from your react-native JavaScript code", | 4 | "description": "Rotate images from your react-native JavaScript code", |
| 5 | "main": "index.js", | 5 | "main": "index.js", |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | - "test": "echo \"Error: no test specified\" && exit 1", | 7 | + "test": "jest --config jest/jest.config.js", |
| 8 | + "test:coverage": "jest --config jest/jest.config.js --coverage", | ||
| 9 | + "pack": "npm pack", | ||
| 8 | "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-image-rotate --cpp-output-path ./harmony/imageRotate/src/main/cpp/generated --ets-output-path ./harmony/imageRotate/src/main/ets/generated --turbo-modules-spec-paths ./src/NativeImageRotate.ts --arkts-components-spec-paths ./src" | 10 | "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-image-rotate --cpp-output-path ./harmony/imageRotate/src/main/cpp/generated --ets-output-path ./harmony/imageRotate/src/main/ets/generated --turbo-modules-spec-paths ./src/NativeImageRotate.ts --arkts-components-spec-paths ./src" |
| 9 | }, | 11 | }, |
| 10 | "files": [ | 12 | "files": [ |
| @@ -17,7 +19,7 @@ | |||
| 17 | ], | 19 | ], |
| 18 | "repository": { | 20 | "repository": { |
| 19 | "type": "git", | 21 | "type": "git", |
| 20 | - "url": "https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate.git" | 22 | + "url": "https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate.git" |
| 21 | }, | 23 | }, |
| 22 | "harmony": { | 24 | "harmony": { |
| 23 | "alias": "react-native-image-rotate", | 25 | "alias": "react-native-image-rotate", |
| @@ -44,7 +46,23 @@ | |||
| 44 | }, | 46 | }, |
| 45 | "license": "MIT", | 47 | "license": "MIT", |
| 46 | "bugs": { | 48 | "bugs": { |
| 47 | - "url": "https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/issues" | 49 | + "url": "https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/issues" |
| 48 | }, | 50 | }, |
| 49 | - "homepage": "https://gitcode.com/CPF-RN/rntpc_react-native-image-rotate/tree/br_rnoh0.72#readme" | 51 | + "homepage": "https://atomgit.com/CPF-RN/rntpc_react-native-image-rotate/tree/br_rnoh0.72#readme", |
| 52 | + "devDependencies": { | ||
| 53 | + "@babel/core": "^7.25.2", | ||
| 54 | + "@babel/preset-env": "^7.25.3", | ||
| 55 | + "@babel/preset-flow": "^7.24.7", | ||
| 56 | + "@types/jest": "^29.5.13", | ||
| 57 | + "babel-jest": "^29.7.0", | ||
| 58 | + "jest": "^29.7.0", | ||
| 59 | + "react-native": "0.72.2", | ||
| 60 | + "ts-jest": "^29.2.5", | ||
| 61 | + "typescript": "^5.5.4", | ||
| 62 | + "@rnoh/react-native-harmony-cli": "npm:@react-native-oh/react-native-harmony-cli@^0.0.27" | ||
| 63 | + }, | ||
| 64 | + "publishConfig": { | ||
| 65 | + "access": "public", | ||
| 66 | + "registry": "https://registry.npmjs.org" | ||
| 67 | + } | ||
| 50 | } | 68 | } |


【AI-Review】【严重】【基础代码问题】【字符串问题】 ● 问题: example/src/harmonyTestDemo.tsx 第 20 行的 SOURCE_IMAGE 常量 URL 为
'https://filesamples.com/samples/image/jpg/sample_640×426.jpg',其中640与426之间的分隔符是 Unicode 乘号×(U+00D7,UTF-8 字节c3 97),而非 ASCII 字母x(U+0078)。该 URL 被 PR 新增的normalizeRemoteRequestUrl处理后,encodeURI会将×编码为%C3%97,最终请求 URL 变为https://filesamples.com/samples/image/jpg/sample_640%C3%97426.jpg。filesamples.com 上的实际文件名使用 ASCIIx(即sample_640x426.jpg),编码后的 URL 将得到 404 响应。● 影响: 使用 SOURCE_IMAGE 的三个设备测试用例(rotateImage_cw、rotateImage_ccw、rotateImage_angle_45)在设备上运行时,HTTP 请求会返回 404,触发 failure 回调,setState 将 uri 设为
'__failure__',assert 中的expect(uri).to.not.contain('__failure__')断言失败。PR 声明"已通过本地完整测试",但"已在目标环境验证功能"未勾选,说明设备端测试未实际执行,此问题未被捕获,核心旋转功能的设备端验证实际上无效。● 建议: 将 URL 中的
×改为 ASCIIx:'https://filesamples.com/samples/image/jpg/sample_640x426.jpg'。修改后在设备上运行 rotateImage_cw / rotateImage_ccw / rotateImage_angle_45 三个用例确认通过。