基于 react-native-clippathview 的 OpenHarmony 适配版,路径裁剪组件(按任意路径裁剪视图)
| Files | Last commit | Last update |
|---|---|---|
| 20 days ago | ||
| 20 days ago | ||
| 21 days ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 5 months ago | ||
| 20 days ago | ||
| 1 year ago | ||
| 4 years ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 13 days ago | ||
| 13 days ago | ||
| 21 days ago | ||
| 20 days ago | ||
| 1 month ago | ||
| 21 days ago | ||
| 20 days ago | ||
| 5 years ago |
Doc template: v0.4.2
react-native-clippath
This project is developed based on react-native-clippath.
The repository of this third-party library has been migrated to GitCode and can be downloaded directly from npm. The new package name is: @react-native-ohos/react-native-clippathview. The version mapping is as follows:
| Third-party library name | Third-party library version (npm address) | Release information | Supported RN version | Autolink | Compilation API version | Community baseline version | Source code address |
|---|---|---|---|---|---|---|---|
| @react-native-ohos/react-native-clippathview | ~1.3.0 | GitCode Releases | 0.82.*/0.84.*/0.86.* | Yes | API12+ | 1.1.8 | master |
| @react-native-ohos/react-native-clippathview | ~1.2.0 | GitCode Releases | 0.77.* | No | API12+ | 1.1.8 | br_rnoh0.77 |
| @react-native-ohos/react-native-clippathview | ~1.1.9 | GitCode Releases | 0.72.* | Yes | API12+ | 1.1.8 | br_rnoh0.72 |
| @react-native-oh-tpl/react-native-clippathview | <=1.1.8-0.1.6@deprecated | GitHub Releases(deprecated) | 0.72.* | No | API12+ | 1.1.8 | master |
Introduction
react-native-clippathview is an SVG Path based clipping component library that provides the ClipPathView component. It clips complex shapes on any view via svg path data, and supports viewBox, preserveAspectRatio, fill rules, strokes, transforms (translate/rotate/scale) and other capabilities.
Download and Installation
Enter the project directory and run the following command:
npm
npm install @react-native-ohos/react-native-clippathview
yarn
yarn add @react-native-ohos/react-native-clippathview
Link
| Version | Autolink supported | RN framework version |
|---|---|---|
| ~1.3.0 | Yes | 0.82.*/0.84.*/0.86.* |
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/zh-cn/02-开发/02-开发指南/Autolinking.md
If the version you are using supports Autolink and the project has integrated Autolink, you can skip the ManualLink configuration.
ManualLink: This step is a guide for manually configuring native dependencies
First, open the OpenHarmony project harmony in the project with DevEco Studio.
1. Overrides RN SDK
To make the project depend on the same version of the RN SDK, add the overrides field in the root oh-package.json5 of the project, pointing to the RN SDK version the project needs to use. The replaced version can be a specific version number, a fuzzy version, or a local HAR package or source directory.
For the function of this field, please read the official documentation
{
"overrides": {
"@rnoh/react-native-openharmony": "~0.82.7" // ohpm online version
// "@rnoh/react-native-openharmony" : "./react_native_openharmony.har" // path pointing to a local har package
// "@rnoh/react-native-openharmony" : "./react_native_openharmony" // path pointing to the source code
}
}
2. Import native code
There are currently two methods:
- Import via har package.
- Link the source code directly.
Method 1: Import via har package (recommended)
The har package is located in the `harmony` folder of the third-party library installation path.
Open entry/oh-package.json5 and add the following dependency
"dependencies": {
"@react-native-ohos/react-native-clippathview": "file:../../node_modules/@react-native-ohos/react-native-clippathview/harmony/clipPath.har"
}
Click the sync button in the upper right corner
Or execute in the command line terminal:
cd entry
ohpm install
Method 2: Link the source code directly
To link the source code directly, please refer to [link-source-code.md](https://atomgit.com/CPF-RN/usage-docs/blob/master/en/link-source-code.md)
3. Configure CMakeLists and import ClipPathViewPackage
Open entry/src/main/cpp/CMakeLists.txt and add:
+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
# RNOH_BEGIN: manual_package_linking_1
add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
+ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-clippathview/src/main/cpp" ./clippath)
# RNOH_END: manual_package_linking_1
# RNOH_BEGIN: manual_package_linking_2
target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
+ target_link_libraries(rnoh_app PUBLIC rnoh_clip_path )
# RNOH_END: manual_package_linking_2
Open entry/src/main/cpp/PackageProvider.cpp and add:
#include "RNOH/PackageProvider.h"
#include "generated/RNOHGeneratedPackage.h"
+ #include "ClipPathViewPackage.h"
using namespace rnoh;
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
return {
std::make_shared<RNOHGeneratedPackage>(ctx),
+ std::make_shared<ClipPathViewPackage>(ctx)
};
}
4. Import ClipPathPackage on the ArkTS side
Open entry/src/main/ets/RNPackagesFactory.ets and add:
...
+ import { ClipPathPackage } from '@react-native-ohos/react-native-clippathview/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
return [
+ new ClipPathPackage(ctx),
];
}
Run
Click the sync button in the upper right corner
Or execute in the command line terminal:
cd entry
ohpm install
Then compile and run.
Constraints and Limitations
Compatibility
The content of this document has been verified based on the following versions:
- RNOH: 0.86.1; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 26.0.0 Release; ROM: 6.0.0.120;
- RNOH: 0.84.2; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 26.0.0 Beta1; ROM: 6.0.0.120 SP7;
- RNOH: 0.82.1; SDK: HarmonyOS 6.0.1 Release SDK; IDE: DevEco Studio 6.0.1 Release; ROM: 6.0.0.120 SP7;
Permission Requirements
No special permission is required.
Usage Example
The following code demonstrates the basic usage scenarios of this library:
The library name in the import statement remains unchanged.
import { View, Text, ScrollView } from "react-native";
import React from "react";
import { ClipPathView } from "react-native-clippathview";
export default function index() {
const viewBox = [0, 0, 400, 400];
const path = "M 0 0 L 400 0 L 0 400 L 400 400 Z";
return (
<ScrollView style={{ width: "100%", height: "100%" }}>
<ClipPathView d={path} style={{ backgroundColor: "#ff0" }}>
<Text style={{ height: 800, fontSize: 26 }}>
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
</Text>
</ClipPathView>
</ScrollView>
);
}
API Description
The **Platform** column indicates the platform where the properties are supported in the original third-party library.
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.
Component
| Name | Parameter type | Required | Platform | OpenHarmony Platform Support | Description |
|---|---|---|---|---|---|
| ClipPathView | ClipPathViewProps | no | All | Yes | Clipping view component based on svg path. |
| ClipPathViewH | ClipPathViewProps | no | All | Yes | Clipping view component drawn based on Path. |
Properties
| Name | Parameter type | Default value | Required | Platform | OpenHarmony Platform Support | Description |
|---|---|---|---|---|---|---|
| svgKey | String | — | no | Web | No | Unique key (Web only). |
| d | String | — | no | All | Yes | The shape is defined by a series of commands (svg path data). |
| viewBox | Array<Number>(4) | — | no | All | Yes | Defines the position and dimension in the user space. |
| align | xMinYMin/xMidYMin/xMaxYMin/xMinYMid/xMidYMid/xMaxYMid/xMinYMax/xMidYMax/xMaxYMax/none | xMidYMid | no | All | Yes | The align of the preserveAspectRatio property. |
| aspect | meet/slice/none | meet | no | All | Yes | The meetOrSlice of the preserveAspectRatio property. |
| fillRule | nonzero/evenodd | nonzero | no | All | Yes | The fill rule of the path interior. |
| strokeWidth | Number | 1 | no | All | Yes | The stroke width of the path. |
| strokeCap | butt/round/square | butt | no | All | Yes | The shape at the two ends of an open path. |
| strokeJoin | bevel/miter/round | miter | no | All | Yes | The shape used at the corners of the path. |
| strokeMiter | Number | 4 | no | All | Yes | When strokeJoin is miter, sets the corner extension. |
| strokeStart | Number | 0 | no | All | Yes | The percentage of the total path where the stroke begins. |
| strokeEnd | Number | 1 | no | All | Yes | The percentage of the total path where the stroke ends; if it is less than or equal to strokeStart, nothing is drawn. |
| translateZ | Number | 0 | no | All | Yes | Sets the stacking level, equivalent to index. |
| transX | Number | 0 | no | All | Yes | Moves the element horizontally on the 2D plane. |
| transY | Number | 0 | no | All | Yes | Moves the element vertically on the 2D plane. |
| transPercentageValue | Boolean | false | no | All | Yes | transX and transY use percentages. |
| rot | Number | 0 | no | All | Yes | Rotates the element around a fixed point. |
| rotO | Number | 0 | no | All | Yes | Position of the rotation center point. |
| rotOx | Number | 0 | no | All | Yes | Horizontal position of the rotation center point. |
| rotOy | Number | 0 | no | All | Yes | Vertical position of the rotation center point. |
| rotPercentageValue | Boolean | false | no | All | Yes | rotOx and rotOy use percentages. |
| sc | Number | 1 | no | All | Yes | Scales the element up or down. |
| scX | Number | 1 | no | All | Yes | Horizontal scaling. |
| scY | Number | 1 | no | All | Yes | Vertical scaling. |
| scO | Number | 0 | no | All | Yes | Position of the scaling center point. |
| scOx | Number | 0 | no | All | Yes | Horizontal position of the scaling center point. |
| scOy | Number | 0 | no | All | Yes | Vertical position of the scaling center point. |
| scPercentageValue | Boolean | false | no | All | Yes | scO, scOx and scOy use percentages. |
Known Issues
Others
None.
Directory Structure
/react-native-clippath # Project root directory
├── src # JS-side component source code
├── harmony # native module (clipPath.har and CAPI implementation)
├── example # Example project (RN test demo)
├── index.js # Library entry
├── index.d.ts # TypeScript type declarations
├── react-native-clippath.podspec # iOS pod configuration
├── CHANGELOG.md # Change log
├── COMMITTERS.md # Committers list
├── LICENSE # Open source license file
├── OAT.xml # OAT self-check configuration
├── README.OpenSource # Open source information
├── README.md # Chinese installation and usage instructions
├── README_en.md # English installation and usage instructions
└── package.json # Package configuration
Contributing
If you encounter any problems during usage, you are welcome to submit an Issue. Of course, PRs are also highly welcomed.
Open Source License
This project is based on The MIT License (MIT). Please feel free to enjoy and participate in open source.