From bc2fd880cd6e04a98b06c74f6977aa9674d010e9 Mon Sep 17 00:00:00 2001 From: quguiren Date: Fri, 25 Jul 2025 19:32:17 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20[Issues:=20#ICOWXT]=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A00.77=E4=B8=89=E6=96=B9=E5=BA=93=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/lottie-react-native.md | 113 ++- zh-cn/react-native-community-blur.md | 890 +++++++++--------- .../react-native-community-datetimepicker.md | 656 +++++++------ zh-cn/react-native-gesture-handler.md | 48 +- zh-cn/react-native-pager-view.md | 535 ++++++----- zh-cn/react-native-picker-picker.md | 54 +- zh-cn/react-native-reanimated.md | 589 ++++++------ zh-cn/react-native-safe-area-context.md | 565 +++++------ zh-cn/react-native-spring-scrollview.md | 45 +- zh-cn/react-native-webview.md | 123 ++- zh-cn/shopify-flash-list.md | 44 +- 11 files changed, 2072 insertions(+), 1590 deletions(-) diff --git a/zh-cn/lottie-react-native.md b/zh-cn/lottie-react-native.md index 766a4add..ccd498e2 100644 --- a/zh-cn/lottie-react-native.md +++ b/zh-cn/lottie-react-native.md @@ -16,7 +16,14 @@ ## 安装与使用 -请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/lottie-react-native Releases](https://github.com/react-native-oh-library/lottie-react-native/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 +请到三方库的 Releases 发布地址查看配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 6.4.1 | [@react-native-oh-tpl/lottie-react-native Releases](https://github.com/react-native-oh-library/lottie-react-native/releases) | 0.72 | +| 7.2.2 | [@react-native-ohos/lottie-react-native Releases]() | 0.77 | + +对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 进入到工程目录并输入以下命令: @@ -25,13 +32,21 @@ #### **npm** ```bash +# V6.4.1 npm install @react-native-oh-tpl/lottie-react-native + +# V7.2.2 +npm install @react-native-ohos/lottie-react-native ``` #### **yarn** ```bash +# V6.4.1 yarn add @react-native-oh-tpl/lottie-react-native + +# V7.2.2 +yarn add @react-native-ohos/lottie-react-native ``` @@ -92,6 +107,8 @@ export default App; 打开 `entry/oh-package.json5`,添加以下依赖 +- V6.4.1 + ```json "dependencies": { "@rnoh/react-native-openharmony": "file:../react_native_openharmony", @@ -99,6 +116,15 @@ export default App; } ``` +- V7.2.2 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + "@react-native-ohos/lottie-react-native": "file:../../node_modules/@react-native-ohos/lottie-react-native/harmony/lottie.har" + } +``` + 点击右上角的 `sync` 按钮 或者在终端执行: @@ -134,7 +160,13 @@ add_subdirectory("${RNOH_CPP_DIR}" ./rn) # RNOH_BEGIN: manual_package_linking_1 add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) + +# V6.4.1 + add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/lottie-react-native/src/main/cpp" ./lottie) + +# V7.2.2 ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/lottie-react-native/src/main/cpp" ./lottie) + # RNOH_END: manual_package_linking_1 file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") @@ -174,8 +206,13 @@ std::vector> PackageProvider::getPackages(Package::Cont ```diff ... + +# V6.4.1 + import {LottieAnimationViewPackage} from '@react-native-oh-tpl/lottie-react-native/ts'; +# V7.2.2 ++ import {LottieAnimationViewPackage} from '@react-native-ohos/lottie-react-native/ts'; + export function createRNPackages(ctx: RNPackageContext): RNPackage[] { return [ + new LottieAnimationViewPackage(ctx) @@ -189,8 +226,12 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { ```diff ... +# V6.4.1 + import { LottieAnimationView, LOTTIE_TYPE } from "@react-native-oh-tpl/lottie-react-native" +# V7.2.2 ++ import { LottieAnimationView, LOTTIE_TYPE } from "@react-native-ohos/lottie-react-native" + @Builder export function buildCustomRNComponent(ctx: ComponentBuilderContext) { ... @@ -237,7 +278,12 @@ ohpm install 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 -请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/lottie-react-native Releases](https://github.com/react-native-oh-library/lottie-react-native/releases) +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 6.4.1 | [@react-native-oh-tpl/lottie-react-native Releases](https://github.com/react-native-oh-library/lottie-react-native/releases) | 0.72 | +| 7.2.2 | [@react-native-ohos/lottie-react-native Releases]() | 0.77 | ### 权限要求 @@ -263,30 +309,32 @@ rawfile 路径:`entry/src/main/resources/rawfile` > [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 -| Name | Description | Type | Default | Required | Platform | HarmonyOS Support | -| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | --------- | -------- | --------------------- |-------------------| -| source | Mandatory - The source of animation. Can be referenced as a local asset by a string, or remotely with an object with a uri property, or it can be an actual JS object of an animation, obtained (for example) with something like require('../path/to/animation.json') | string\| AnimationObject \| { uri: string } | None | Yes | All | Yes | -| progress | A number between 0 and 1. This number represents the normalized progress of the animation. If you update this prop, the animation will correspondingly update to the frame at that progress value. This prop is not required if you are using the imperative API. | number | 0 | No | iOS, Android, Windows | Yes | -| speed | The speed the animation will progress. Sending a negative value will reverse the animation | number | 1 | No | All | Yes | -| duration | The duration of the animation in ms. Takes precedence over speed when set. This only works when source is an actual JS object of an animation. | number | undefined | No | iOS, Android, Windows | Yes | -| loop | A boolean flag indicating whether or not the animation should loop. | boolean | true | No | All | Yes | -| autoPlay | A boolean flag indicating whether or not the animation should start automatically when mounted. This only affects the imperative API. | boolean | false | No | All | Yes | -| resizeMode | Determines how to resize the animated view when the frame doesn't match the raw image dimensions. Supports cover, contain and center. | 'cover'\| 'contain' \| 'center' | contain | No | iOS, Android, Windows | Yes | -| style | Style attributes for the view, as expected in a standard View, aside from border styling | StyleProp | None | No | iOS, Android, Windows | Yes | -| webStyle | Style attributes for the view, it uses CSSProperties. | CSSProperties | None | No | Web | No | -| imageAssetsFolder | Needed for Android and HarmonyOS to work properly with assets, iOS will ignore it. | string | None | No | Android | Yes | -| useNativeLooping | Only Windows. When enabled, uses platform-level looping to improve smoothness, but onAnimationLoop will not fire and changing the loop prop will reset playback rather than finishing gracefully. | boolean | false | No | Windows | No | -| onAnimationLoop | Only Windows and Web. A callback function invoked when the animation loops. | callback | None | No | Windows, Web | No | -| onAnimationFinish | A callback function which will be called when animation is finished. This callback is called with a boolean isCancelled argument, indicating if the animation actually completed playing, or if it was cancelled, for instance by calling play() or reset() while is was still playing. Note that this callback will be called only when loop is set to false. | callback | None | No | All | Yes | -| onAnimationFailure | A callback function which will be called if an error occurs while working with the animation (loading, running, etc). This callback is called with a string error argument, which contains the error message that occured. | callback | None | No | All | Yes | -| onAnimationLoaded | A callback function which will be called when animation is done loading. This callback is called with no parameters. | callback | None | No | All | Yes | -| renderMode | a String flag to set whether or not to render with HARDWARE or SOFTWARE acceleration | 'AUTOMATIC'\| 'HARDWARE' \| 'SOFTWARE' | AUTOMATIC | No | iOS, Android | No | -| cacheComposition | Only Android and HarmonyOS, a boolean flag indicating whether or not the animation should do caching. | boolean | true | No | Android | Yes | -| colorFilters | An array of objects denoting layers by KeyPath and a new color filter value (as hex string). | Array | [] | No | iOS, Android, Windows | Yes | -| textFiltersAndroid | Only Android, an array of objects denoting text values to find and replace. | Array | [] | No | Android | No | -| textFiltersIOS | Only iOS, an array of objects denoting text layers by KeyPath and a new string value. | Array | [] | No | iOS | No | -| hover | Only Web, a boolean denoting whether to play on mouse hover. | boolean | false | No | Web | No | -| direction | Only Web a number from 1 or -1 denoting playing direction. | 1\| -1 | 1 | No | Web | No | +| Name | Description | Type | Default | Required | Platform | HarmonyOS Support | +| -------------------------------------- | ------------------------------------------------------------ | ------------------------------------------- | --------- | -------- | --------------------- | ----------------- | +| source | Mandatory - The source of animation. Can be referenced as a local asset by a string, or remotely with an object with a uri property, or it can be an actual JS object of an animation, obtained (for example) with something like require('../path/to/animation.json') | string\| AnimationObject \| { uri: string } | None | Yes | All | Yes | +| progress | A number between 0 and 1. This number represents the normalized progress of the animation. If you update this prop, the animation will correspondingly update to the frame at that progress value. This prop is not required if you are using the imperative API. | number | 0 | No | iOS, Android, Windows | Yes | +| speed | The speed the animation will progress. Sending a negative value will reverse the animation | number | 1 | No | All | Yes | +| duration | The duration of the animation in ms. Takes precedence over speed when set. This only works when source is an actual JS object of an animation. | number | undefined | No | iOS, Android, Windows | Yes | +| loop | A boolean flag indicating whether or not the animation should loop. | boolean | true | No | All | Yes | +| autoPlay | A boolean flag indicating whether or not the animation should start automatically when mounted. This only affects the imperative API. | boolean | false | No | All | Yes | +| resizeMode | Determines how to resize the animated view when the frame doesn't match the raw image dimensions. Supports cover, contain and center. | 'cover'\| 'contain' \| 'center' | contain | No | iOS, Android, Windows | Yes | +| style | Style attributes for the view, as expected in a standard View, aside from border styling | StyleProp | None | No | iOS, Android, Windows | Yes | +| webStyle | Style attributes for the view, it uses CSSProperties. | CSSProperties | None | No | Web | No | +| imageAssetsFolder | Needed for Android and HarmonyOS to work properly with assets, iOS will ignore it. | string | None | No | Android | Yes | +| useNativeLooping | Only Windows. When enabled, uses platform-level looping to improve smoothness, but onAnimationLoop will not fire and changing the loop prop will reset playback rather than finishing gracefully. | boolean | false | No | Windows | No | +| onAnimationLoop | Only Windows and Web. A callback function invoked when the animation loops. | callback | None | No | Windows, Web | No | +| onAnimationFinish | A callback function which will be called when animation is finished. This callback is called with a boolean isCancelled argument, indicating if the animation actually completed playing, or if it was cancelled, for instance by calling play() or reset() while is was still playing. Note that this callback will be called only when loop is set to false. | callback | None | No | All | Yes | +| onAnimationFailure | A callback function which will be called if an error occurs while working with the animation (loading, running, etc). This callback is called with a string error argument, which contains the error message that occured. | callback | None | No | All | Yes | +| onAnimationLoaded | A callback function which will be called when animation is done loading. This callback is called with no parameters. | callback | None | No | All | Yes | +| renderMode | a String flag to set whether or not to render with HARDWARE or SOFTWARE acceleration | 'AUTOMATIC'\| 'HARDWARE' \| 'SOFTWARE' | AUTOMATIC | No | iOS, Android | No | +| enableSafeModeAndroid | A boolean flag to enable safe mode which wraps the draw call with a try catch on Android. | boolean | false | No | Android | NO | +| cacheComposition | Only Android and HarmonyOS, a boolean flag indicating whether or not the animation should do caching. | boolean | true | No | Android | Yes | +| colorFilters | An array of objects denoting layers by KeyPath and a new color filter value (as hex string). | Array | [] | No | iOS, Android, Windows | Yes | +| textFiltersAndroid | Only Android, an array of objects denoting text values to find and replace. | Array | [] | No | Android | No | +| textFiltersIOS | Only iOS, an array of objects denoting text layers by KeyPath and a new string value. | Array | [] | No | iOS | No | +| hover | Only Web, a boolean denoting whether to play on mouse hover. | boolean | false | No | Web | No | +| direction | Only Web a number from 1 or -1 denoting playing direction. | 1\| -1 | 1 | No | Web | No | +| enableSafeModeAndroid7.2.2+ | A boolean flag to enable safe mode which wraps the draw call with a try catch on Android | props | None | No | All | No | ## 静态方法 (Imperative API) @@ -294,12 +342,12 @@ rawfile 路径:`entry/src/main/resources/rawfile` > [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 -| Name | Description | Type | Required | Platform | HarmonyOS Support | -| ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- | -------- | ----------------- | +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ------ | ------------------------------------------------------------ | -------- | -------- | -------- | ----------------- | | play | Play the animation all the way through, at the speed specified as a prop. It can also play a section of the animation (not available on web) when called as play(startFrame, endFrame). | function | No | All | Yes | -| reset | Reset the animation back to 0 progress. | function | No | All | Yes | -| pause | Pauses the animation. | function | No | All | Yes | -| resume | Resumes the paused animation. | function | No | All | Yes | +| reset | Reset the animation back to 0 progress. | function | No | All | Yes | +| pause | Pauses the animation. | function | No | All | Yes | +| resume | Resumes the paused animation. | function | No | All | Yes | ## 遗留问题 @@ -309,5 +357,4 @@ rawfile 路径:`entry/src/main/resources/rawfile` ## 开源协议 -本项目基于 [Apache License 2.0](https://github.com/lottie-react-native/lottie-react-native/blob/master/LICENSE) ,请自由地享受和参与开源。 - +本项目基于 [Apache License 2.0](https://github.com/lottie-react-native/lottie-react-native/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file diff --git a/zh-cn/react-native-community-blur.md b/zh-cn/react-native-community-blur.md index 04ffb79c..467b225a 100644 --- a/zh-cn/react-native-community-blur.md +++ b/zh-cn/react-native-community-blur.md @@ -1,424 +1,466 @@ -> 模板版本:v0.2.2 - -

-

@react-native-community/blur

-

-

- - Supported platforms - - - License - -

- -> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-blur) - -## 安装与使用 - -本库已经适配`C-API版本`从版本`4.4.0-0.1.0`开始的版本为`C-API版本`,`C-API版本`在性能和速度上都优于`ArkTS版本`。 - -请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-community-blur Releases](https://github.com/react-native-oh-library/react-native-blur/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 - -进入到工程目录并输入以下命令: - - - -#### **npm** - -```bash -npm install @react-native-oh-tpl/blur -``` - -#### **yarn** - -```bash -yarn add @react-native-oh-tpl/blur -``` - - - -下面的代码展示了这个库的基本使用场景: - - -```js -import React, { useState} from 'react'; -import { - Image, - StyleSheet, - Platform, - Switch, - Text, - View, - SafeAreaView, - Dimensions, -} from 'react-native'; - -import { - BlurView, - BlurViewProps, -} from '@react-native-community/blur'; - -export const Blurs = () => { - const [blurBlurType, setBlurBlurType] = useState('dark'); - const [blurAmount, setBlurAmount] = useState(100); - useState('dark'); - const tintColor = blurBlurType === 'dark' ? 'white' : 'black'; - - return ( - - - - - Blur component ({Platform.OS}) - - - - { - setBlurBlurType('light') - }}>light - - { - setBlurBlurType('dark') - }}>dark - - { - setBlurBlurType('chromeMaterialLight') - }}>chromeMaterialLight click will crash - - - { - setBlurAmount(20) - }}>20 - - { - setBlurAmount(40) - }}>40 - - { - setBlurAmount(60) - }}>60 - { - setBlurAmount(80) - }}>80 - - { - setBlurAmount(100) - }}>100 - - - - ); -}; - -export const BlurDemo = () => { - const [showBlurs, setShowBlurs] = React.useState(false); - //'../assets/bgimage.jpeg' 此路径的图片为本地图片,在使用demo时将此图片的路径换为自己本地图片路径 - return ( - - - {showBlurs ? : null} - - - setShowBlurs(value)} - value={showBlurs} - /> - - - ); -}; - -const styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: 'transparent', - }, - blurContainer: { - flex: 1, - backgroundColor: 'transparent', - justifyContent: 'center', - alignItems: 'stretch', - }, - row: { - marginTop: 50, - flex: 1, - width: '100%', - flexDirection: 'row', - justifyContent: 'space-between', - alignItems: 'stretch', - }, - blurView: { - position: 'absolute', - left: 0, - right: 0, - top: 0, - bottom: 0, - width: Dimensions.get('window').width, - }, - - blurView2: { - position: 'absolute', - left: 0, - right: 0, - top: 0, - bottom: 0, - }, - img: { - position: 'absolute', - left: 0, - right: 0, - top: 0, - bottom: 0, - height: Dimensions.get('window').height, - width: Dimensions.get('window').width, - }, - text: { - fontSize: 20, - fontWeight: 'bold', - textAlign: 'center', - margin: 10, - color: 'white', - }, - blurToggle: { - position: 'absolute', - top: 30, - right: 10, - alignItems: 'flex-end', - }, -}); -``` - -## Link - -目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。 - -首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` - -### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段 - -```js - { - ... - "overrides": { - "@rnoh/react-native-openharmony" : "./react_native_openharmony" - } -} -``` - -### 2.引入原生端代码 - -目前有两种方法: - -1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); -2. 直接链接源码。 - -方法一:通过 har 包引入 - -> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 - -打开 `entry/oh-package.json5`,添加以下依赖 - -```json -"dependencies": { - "@rnoh/react-native-openharmony": "file:../react_native_openharmony", - - "@react-native-oh-tpl/blur": "file:../../node_modules/@react-native-oh-tpl/blur/harmony/blur.har" - } -``` - -点击右上角的 `sync` 按钮 - -或者在终端执行: - -```bash -cd entry -ohpm install -``` - -方法二:直接链接源码 - -> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) - -### 3.配置 CMakeLists 和引入 BlurPackage - -打开 `entry/src/main/cpp/CMakeLists.txt`,添加: - -```diff -project(rnapp) -cmake_minimum_required(VERSION 3.4.1) -set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") -+ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") -set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") - -add_subdirectory("${RNOH_CPP_DIR}" ./rn) - -# RNOH_BEGIN: add_package_subdirectories -add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) -+ add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/blur/src/main/cpp" ./blur) -# RNOH_END: add_package_subdirectories - -add_library(rnoh_app SHARED - "./PackageProvider.cpp" - "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" -) - -target_link_libraries(rnoh_app PUBLIC rnoh) - -# RNOH_BEGIN: link_packages -target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) -+ target_link_libraries(rnoh_app PUBLIC rnoh_blur) -# RNOH_END: link_packages -``` - -打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: - - -```diff -#include "RNOH/PackageProvider.h" -#include "SamplePackage.h" -+ #include "BlurPackage.h" - -using namespace rnoh; - -std::vector> PackageProvider::getPackages(Package::Context ctx) { - return { - std::make_shared(ctx), -+ std::make_shared(ctx) - }; -} -``` - -### 4.在 ArkTs 侧引入 BlurView 组件(使用4.4.0-0.1.0及之后的版本忽略这步配置) - -找到 `function buildCustomRNComponent()`,一般位于 `entry/src/main/ets/pages/index.ets` 或 `entry/src/main/ets/rn/LoadBundle.ets`,添加: - - -```diff -+ import { BlurView, BLUR_TYPE } from "@react-native-oh-tpl/blur" - -@Builder -function buildCustomRNComponent(ctx: ComponentBuilderContext) { - ... -+ if (ctx.componentName === BLUR_TYPE) { -+ BlurView({ -+ ctx: ctx.rnohContext, -+ tag: ctx.tag, -+ }) -+ } - ... -} -``` - - -在`entry/src/main/ets/pages/index.ets` 或 `entry/src/main/ets/rn/LoadBundle.ets` 找到常量 `arkTsComponentNames` 在其数组里添加组件名 - ->[!TIP] 本库使用了混合方案,需要添加组件名。 - - -```diff -const arkTsComponentNames: Array = [ - SampleView.NAME, - GeneratedSampleView.NAME, - PropsDisplayer.NAME, -+ BLUR_TYPE - ]; -``` - -### 5.运行 - -点击右上角的 `sync` 按钮 - -或者在终端执行: - -```bash -cd entry -ohpm install -```` - -然后编译、运行即可。 - -## 约束与限制 - -### 兼容性 - -要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 - -请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-community-blur Releases](https://github.com/react-native-oh-library/react-native-blur/releases) - -## 属性 - -> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 - -> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 - -| Name | Description | Type | Required | Platform | HarmonyOS Support | -| ----------------------------------- | ----------------------------------------------------------------------------------------- | --------- |----------| ------- | ----------------- | -| `blurType` | blur type | enum | yes | iOS,Android | yes | -| `blurAmount?` | 0 - 100 (The maximum blurAmount on Android is 32, so higher values will be clamped to 32) | number | no | iOS,Android | yes | -| `reducedTransparencyFallbackColor?` | Reduce transparency fallback color | Any color | no | iOS | no | -| `blurRadius?` | Matches iOS blurAmount | number | no | Android | no | -| `downsampleFactor?` | Matches iOS blurAmount | number | no | Android | no | -| `overlayColor?` | Default color based on iOS blurType | Any color | no | Android | no | - -#### blurType - -> [!TIP] 如果要使用自适应模糊效果需要配置深色模式[配置文档](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ui-dark-light-color-adaptation)如果不配置深色模式则自适应模糊效果将没有深色模式,只有浅色模式。 - -| Name | Description | Platform | HarmonyOS Support | -| ------------------------ | ------------------------------------------------------------------------------------------------------ |-----------------------| ----------------- | -| `xlight` | extra light blur type | iOS,Android | yes | -| `light` | light blur type | iOS,Android | yes | -| `dark` | dark blur type | iOS,Android | yes | -| `extraDark` | extra dark blur type (tvOS only) | iOS | yes | -| `regular` | regular blur type (iOS 10+ and tvOS only) | iOS | yes | -| `prominent` | prominent blur type (iOS 10+ and tvOS only) | iOS | yes | -| `chromeMaterial` | An adaptable blur effect that creates the appearance of a material with normal thickness | iOS 13 only | yes | -| `material` | An adaptable blur effect that creates the appearance of a material with normal thickness | iOS 13 only | yes | -| `thickMaterial` | An adaptable blur effect that creates the appearance of a material that is thicker than normal | iOS 13 only | yes | -| `thinMaterial` | An adaptable blur effect that creates the appearance of an ultra-thin material | iOS 13 only | yes | -| `ultraThinMaterial` | An adaptable blur effect that creates the appearance of an ultra-thin material | iOS 13 only | yes | -| `chromeMaterialDark` | A blur effect that creates the appearance of an ultra-thin material and is always dark | iOS 13 only | yes | -| `materialDark` | A blur effect that creates the appearance of a thin material and is always dark | iOS 13 only | yes | -| `thickMaterialDark` | A blur effect that creates the appearance of a material with normal thickness and is always dark | iOS 13 only | yes | -| `thinMaterialDark` | A blur effect that creates the appearance of a material that is thicker than normal and is always dark | iOS 13 only | yes | -| `ultraThinMaterialDark` | A blur effect that creates the appearance of the system chrome and is always dark | iOS 13 only | yes | -| `chromeMaterialLight` | An adaptable blur effect that creates the appearance of the system chrome | iOS 13 only | yes | -| `materialLight` | An adaptable blur effect that creates the appearance of a material with normal thickness | iOS 13 only | yes | -| `thickMaterialLight` | An adaptable blur effect that creates the appearance of a thin material | iOS 13 only | yes | -| `thinMaterialLight` | An adaptable blur effect that creates the appearance of a thin material | iOS 13 only | yes | -| `ultraThinMaterialLight` | An adaptable blur effect that creates the appearance of an ultra-thin material | iOS 13 only | yes | - -## API - -> [!TIP] "Platform"列表示该组件在原三方库上支持的平台。 - -> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该组件;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 - - -| Name | Description | Type | Required | Platform | HarmonyOS Support | -| -------------- | ------------------------------------------------------------------------------------------ | ---|------ |----------| ----------------- | -| `BlurView` | Preload images to display later. e.g. | component|no | iOS,Android | yes | -| `VibrancyView` | The vibrancy effect lets the content underneath a blurred view show through more vibrantly | component|no | iOS | no | - -## 遗留问题 - -- [ ] @react-native-community/blur的 VibrancyView组件未实现HarmonyOS化 [issue#7](https://github.com/react-native-oh-library/react-native-blur/issues/7) -- [ ] @react-native-community/blur的reducedTransparencyFallbackColor属性未实现 HarmonyOS化[issue#8](https://github.com/react-native-oh-library/react-native-blur/issues/8) - - -## 其他 - -## 开源协议 - -本项目基于 [The MIT License (MIT)](https://github.com/Kureev/react-native-blur/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file +> 模板版本:v0.2.2 + +

+

@react-native-community/blur

+

+

+ + Supported platforms + + + License + +

+ +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-blur) + +## 安装与使用 + +本库已经适配`C-API版本`从版本`4.4.0-0.1.0`开始的版本为`C-API版本`,`C-API版本`在性能和速度上都优于`ArkTS版本`。 + +请到三方库的 Releases 发布地址查看配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 4.4.0 | [@react-native-oh-tpl/react-native-community-blur Releases](https://github.com/react-native-oh-library/react-native-blur/releases) | 0.72 | +| 4.4.1 | [@react-native-ohos/react-native-community-blur Releases]() | 0.77 | + +对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 + +进入到工程目录并输入以下命令: + + + +#### **npm** + +```bash +# V4.4.0 +npm install @react-native-oh-tpl/blur + +# V4.4.1 +npm install @react-native-ohos/blur +``` + +#### **yarn** + +```bash +# V4.4.0 +yarn add @react-native-oh-tpl/blur + +# V4.4.1 +yarn add @react-native-ohos/blur +``` + + + +下面的代码展示了这个库的基本使用场景: + + +```js +import React, { useState} from 'react'; +import { + Image, + StyleSheet, + Platform, + Switch, + Text, + View, + SafeAreaView, + Dimensions, +} from 'react-native'; + +import { + BlurView, + BlurViewProps, +} from '@react-native-community/blur'; + +export const Blurs = () => { + const [blurBlurType, setBlurBlurType] = useState('dark'); + const [blurAmount, setBlurAmount] = useState(100); + useState('dark'); + const tintColor = blurBlurType === 'dark' ? 'white' : 'black'; + + return ( + + + + + Blur component ({Platform.OS}) + + + + { + setBlurBlurType('light') + }}>light + + { + setBlurBlurType('dark') + }}>dark + + { + setBlurBlurType('chromeMaterialLight') + }}>chromeMaterialLight click will crash + + + { + setBlurAmount(20) + }}>20 + + { + setBlurAmount(40) + }}>40 + + { + setBlurAmount(60) + }}>60 + { + setBlurAmount(80) + }}>80 + + { + setBlurAmount(100) + }}>100 + + + + ); +}; + +export const BlurDemo = () => { + const [showBlurs, setShowBlurs] = React.useState(false); + //'../assets/bgimage.jpeg' 此路径的图片为本地图片,在使用demo时将此图片的路径换为自己本地图片路径 + return ( + + + {showBlurs ? : null} + + + setShowBlurs(value)} + value={showBlurs} + /> + + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: 'transparent', + }, + blurContainer: { + flex: 1, + backgroundColor: 'transparent', + justifyContent: 'center', + alignItems: 'stretch', + }, + row: { + marginTop: 50, + flex: 1, + width: '100%', + flexDirection: 'row', + justifyContent: 'space-between', + alignItems: 'stretch', + }, + blurView: { + position: 'absolute', + left: 0, + right: 0, + top: 0, + bottom: 0, + width: Dimensions.get('window').width, + }, + + blurView2: { + position: 'absolute', + left: 0, + right: 0, + top: 0, + bottom: 0, + }, + img: { + position: 'absolute', + left: 0, + right: 0, + top: 0, + bottom: 0, + height: Dimensions.get('window').height, + width: Dimensions.get('window').width, + }, + text: { + fontSize: 20, + fontWeight: 'bold', + textAlign: 'center', + margin: 10, + color: 'white', + }, + blurToggle: { + position: 'absolute', + top: 30, + right: 10, + alignItems: 'flex-end', + }, +}); +``` + +## Link + +目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` + +### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段 + +```js + { + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } +} +``` + +### 2.引入原生端代码 + +目前有两种方法: + +1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); +2. 直接链接源码。 + +方法一:通过 har 包引入 + +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +- V4.4.0 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + + "@react-native-oh-tpl/blur": "file:../../node_modules/@react-native-oh-tpl/blur/harmony/blur.har" + } +``` + +- V4.4.1 + +```json +"dependencies": { + "@rnoh/react-native-openharmony": "file:../react_native_openharmony", + + "@react-native-ohos/blur": "file:../../node_modules/@react-native-ohos/blur/harmony/blur.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) + +### 3.配置 CMakeLists 和引入 BlurPackage + +打开 `entry/src/main/cpp/CMakeLists.txt`,添加: + +```diff +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: add_package_subdirectories +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) + +# V4.4.0 ++ add_subdirectory("${OH_MODULES}/@react-native-oh-tpl/blur/src/main/cpp" ./blur) + +# V4.4.1 ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/blur/src/main/cpp" ./blur) + +# RNOH_END: add_package_subdirectories + +add_library(rnoh_app SHARED + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) + +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: link_packages +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) ++ target_link_libraries(rnoh_app PUBLIC rnoh_blur) +# RNOH_END: link_packages +``` + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + + +```diff +#include "RNOH/PackageProvider.h" +#include "SamplePackage.h" ++ #include "BlurPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), ++ std::make_shared(ctx) + }; +} +``` + +### 4.在 ArkTs 侧引入 BlurView 组件(使用4.4.0-0.1.0及之后的版本忽略这步配置) + +找到 `function buildCustomRNComponent()`,一般位于 `entry/src/main/ets/pages/index.ets` 或 `entry/src/main/ets/rn/LoadBundle.ets`,添加: + + +```diff +// V4.4.0 ++ import { BlurView, BLUR_TYPE } from "@react-native-oh-tpl/blur" + +// V4.4.1 ++ import { BlurView, BLUR_TYPE } from "@react-native-ohos/blur" + +@Builder +function buildCustomRNComponent(ctx: ComponentBuilderContext) { + ... ++ if (ctx.componentName === BLUR_TYPE) { ++ BlurView({ ++ ctx: ctx.rnohContext, ++ tag: ctx.tag, ++ }) ++ } + ... +} +``` + + +在`entry/src/main/ets/pages/index.ets` 或 `entry/src/main/ets/rn/LoadBundle.ets` 找到常量 `arkTsComponentNames` 在其数组里添加组件名 + +>[!TIP] 本库使用了混合方案,需要添加组件名。 + + +```diff +const arkTsComponentNames: Array = [ + SampleView.NAME, + GeneratedSampleView.NAME, + PropsDisplayer.NAME, ++ BLUR_TYPE + ]; +``` + +### 5.运行 + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +```` + +然后编译、运行即可。 + +## 约束与限制 + +### 兼容性 + +要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 + +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息: + +| 三方库版本 | 发布信息 | 支持RN版本 | +| ---------- | ------------------------------------------------------------ | ---------- | +| 4.4.0 | [@react-native-oh-tpl/react-native-community-blur Releases](https://github.com/react-native-oh-library/react-native-blur/releases) | 0.72 | +| 4.4.1 | [@react-native-ohos/react-native-community-blur Releases]() | 0.77 | + +## 属性 + +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----------------------------------- | ----------------------------------------------------------------------------------------- | --------- |----------| ------- | ----------------- | +| `blurType` | blur type | enum | yes | iOS,Android | yes | +| `blurAmount?` | 0 - 100 (The maximum blurAmount on Android is 32, so higher values will be clamped to 32) | number | no | iOS,Android | yes | +| `reducedTransparencyFallbackColor?` | Reduce transparency fallback color | Any color | no | iOS | no | +| `blurRadius?` | Matches iOS blurAmount | number | no | Android | no | +| `downsampleFactor?` | Matches iOS blurAmount | number | no | Android | no | +| `overlayColor?` | Default color based on iOS blurType | Any color | no | Android | no | + +#### blurType + +> [!TIP] 如果要使用自适应模糊效果需要配置深色模式[配置文档](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ui-dark-light-color-adaptation)如果不配置深色模式则自适应模糊效果将没有深色模式,只有浅色模式。 + +| Name | Description | Platform | HarmonyOS Support | +| ------------------------ | ------------------------------------------------------------------------------------------------------ |-----------------------| ----------------- | +| `xlight` | extra light blur type | iOS,Android | yes | +| `light` | light blur type | iOS,Android | yes | +| `dark` | dark blur type | iOS,Android | yes | +| `extraDark` | extra dark blur type (tvOS only) | iOS | yes | +| `regular` | regular blur type (iOS 10+ and tvOS only) | iOS | yes | +| `prominent` | prominent blur type (iOS 10+ and tvOS only) | iOS | yes | +| `chromeMaterial` | An adaptable blur effect that creates the appearance of a material with normal thickness | iOS 13 only | yes | +| `material` | An adaptable blur effect that creates the appearance of a material with normal thickness | iOS 13 only | yes | +| `thickMaterial` | An adaptable blur effect that creates the appearance of a material that is thicker than normal | iOS 13 only | yes | +| `thinMaterial` | An adaptable blur effect that creates the appearance of an ultra-thin material | iOS 13 only | yes | +| `ultraThinMaterial` | An adaptable blur effect that creates the appearance of an ultra-thin material | iOS 13 only | yes | +| `chromeMaterialDark` | A blur effect that creates the appearance of an ultra-thin material and is always dark | iOS 13 only | yes | +| `materialDark` | A blur effect that creates the appearance of a thin material and is always dark | iOS 13 only | yes | +| `thickMaterialDark` | A blur effect that creates the appearance of a material with normal thickness and is always dark | iOS 13 only | yes | +| `thinMaterialDark` | A blur effect that creates the appearance of a material that is thicker than normal and is always dark | iOS 13 only | yes | +| `ultraThinMaterialDark` | A blur effect that creates the appearance of the system chrome and is always dark | iOS 13 only | yes | +| `chromeMaterialLight` | An adaptable blur effect that creates the appearance of the system chrome | iOS 13 only | yes | +| `materialLight` | An adaptable blur effect that creates the appearance of a material with normal thickness | iOS 13 only | yes | +| `thickMaterialLight` | An adaptable blur effect that creates the appearance of a thin material | iOS 13 only | yes | +| `thinMaterialLight` | An adaptable blur effect that creates the appearance of a thin material | iOS 13 only | yes | +| `ultraThinMaterialLight` | An adaptable blur effect that creates the appearance of an ultra-thin material | iOS 13 only | yes | + +## API + +> [!TIP] "Platform"列表示该组件在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该组件;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| -------------- | ------------------------------------------------------------------------------------------ | ---|------ |----------| ----------------- | +| `BlurView` | Preload images to display later. e.g. | component|no | iOS,Android | yes | +| `VibrancyView` | The vibrancy effect lets the content underneath a blurred view show through more vibrantly | component|no | iOS | no | + +## 遗留问题 + +- [ ] @react-native-community/blur的 VibrancyView组件未实现HarmonyOS化 [issue#7](https://github.com/react-native-oh-library/react-native-blur/issues/7) +- [ ] @react-native-community/blur的reducedTransparencyFallbackColor属性未实现 HarmonyOS化[issue#8](https://github.com/react-native-oh-library/react-native-blur/issues/8) + + +## 其他 + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/Kureev/react-native-blur/blob/master/LICENSE) ,请自由地享受和参与开源。 diff --git a/zh-cn/react-native-community-datetimepicker.md b/zh-cn/react-native-community-datetimepicker.md index 08420df4..a589a136 100644 --- a/zh-cn/react-native-community-datetimepicker.md +++ b/zh-cn/react-native-community-datetimepicker.md @@ -1,308 +1,348 @@ -> 模板版本:v0.2.2 - -

-

@react-native-community/datetimepicker

-

-

- - Supported platforms - - - License - -

- -> [!TIP] [Github 地址](https://github.com/react-native-oh-library/datetimepicker) - -## 安装与使用 - -请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/datetimepicker Releases](https://github.com/react-native-oh-library/datetimepicker/releases) 。对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 - -进入到工程目录并输入以下命令: - - - -#### **npm** - -```bash -npm install @react-native-oh-tpl/datetimepicker -``` - -#### **yarn** - -```bash -yarn add @react-native-oh-tpl/datetimepicker -``` - - - -下面的代码展示了这个库的基本使用场景: - -> [!WARNING] 使用时 import 的库名不变。 - -```js -import React, { useState } from 'react' -import DateTimePicker from '@react-native-community/datetimepicker'; -import { SafeAreaView, Button, Text } from 'react-native' - -export const MDatetimepicker = () => { - const [date, setDate] = useState(new Date(new Date())); - const [mode, setMode] = useState('date'); - const [show, setShow] = useState(false); - - const onChange = (event: any, selectedDate: any) => { - const currentDate = selectedDate; - setShow(false); - setDate(currentDate); - }; - - const showMode = (currentMode: React.SetStateAction) => { - setShow(true); - setMode(currentMode); - }; - - const showDatepicker = () => { - showMode('date'); - }; - - const showTimepicker = () => { - showMode('time'); - }; - - return ( - -