From 5f4b4f93316a09f3ad0dbdce204a526b729eacee Mon Sep 17 00:00:00 2001 From: liqi Date: Tue, 30 Apr 2024 17:28:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[Issues:=20#I9L0QD]=20=E6=96=B0=E5=A2=9Erea?= =?UTF-8?q?ct-native-localize=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-localize.md | 255 +++++++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 zh-cn/react-native-localize.md diff --git a/zh-cn/react-native-localize.md b/zh-cn/react-native-localize.md new file mode 100644 index 00000000..051820c7 --- /dev/null +++ b/zh-cn/react-native-localize.md @@ -0,0 +1,255 @@ +> 模板版本:v0.2.0 + +

+

react-native-localize

+

+

+ + Supported platforms + + + License + +

+ +> [!TIP] [Github 地址](https://github.com/zoontek/react-native-localize) + + +## 安装与使用 + +请到三方库的 Releases 发布地址查看配套的版本信息:[<@react-native-oh-tpl/react-native-localize> Releases] +(https://github.com/react-native-oh-library/react-native-localize/releases),并下载适用版本的 tgz 包。 + +进入到工程目录并输入以下命令: + +>[!TIP] # 处替换为 tgz 包的路径 + + + +#### **npm** + +```bash +npm install @react-native-oh-tpl/react-native-localize@file:# +``` + +#### **yarn** + +```bash +yarn add @react-native-oh-tpl/react-native-localize@file:# +``` + + + +下面的代码展示了这个库的基本使用场景: + +>[!WARNING] 使用时 import 的库名不变。 + +```js +import * as React from "react"; +import { + I18nManager, + Platform, + SafeAreaView, + ScrollView, + StyleSheet, + Text, + View, +} from "react-native"; +import * as RNLocalize from "react-native-localize"; + +const Line = ({ name, value }: { name: string; value: unknown }) => ( + + {name} + {JSON.stringify(value, null, 2)} + +); +function LocalizeDemo() { + return ( + + + + + + + + + + + + + + + + + + ); +} +export default LocalizeDemo; +``` + +## Link + +目前鸿蒙暂不支持 AutoLink,所以 Link 步骤需要手动配置。 + +首先需要使用 DevEco Studio 打开项目里的鸿蒙工程 `harmony` + +### 引入原生端代码 + +目前有两种方法: + +1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法); +2. 直接链接源码。 + +方法一:通过 har 包引入 + +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +```json +"dependencies": { + "rnoh": "file:../react_native_openharmony", + "rnoh-localize": "file:../../node_modules/@react-native-oh-tpl/react-native-localize/harmony/rn_localize.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 源码位于三方库安装路径的 `harmony` 文件夹下。 + +打开 `entry/oh-package.json5`,添加以下依赖 + +```json +"dependencies": { + "rnoh": "file:../react_native_openharmony", + "rnoh-localize": "file:../../node_modules/@react-native-oh-tpl/react-native-localize/harmony/rn_localize" + } +``` + +打开终端,执行: + +```bash +cd entry +ohpm install --no-link +``` + +### 配置 CMakeLists + +打开 `entry/src/main/cpp/CMakeLists.txt`,添加: + +```diff +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") +set(OH_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) ++ add_subdirectory("${OH_MODULE_DIR}/rnoh-localize/src/main/cpp" ./rn-localize) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") + +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) ++ target_link_libraries(rnoh_app PUBLIC rnoh_localize) +# RNOH_END: manual_package_linking_2 +``` + +### 在 ArkTs 侧引入 RNKeepAwakePackage + +打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: + +```diff +... ++ import { RNLocalizePackage } from "rnoh-localize/ts"; + +export function createRNPackages(ctx: RNPackageContext): RNPackage[] { + return [ + new SamplePackage(ctx), ++ new RNLocalizePackage(ctx) + ]; +} +``` + +### 运行 + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +然后编译、运行即可。 + +## 约束与限制 + +### 兼容性 +要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 电脑ROM。 + +本文档内容基于以下版本验证通过: + +1. RNOH:0.72.20; SDK:HarmonyOS NEXT Developer Preview2; IDE:DevEco Studio 5.0.3.200; ROM:205.0.0.18 + +## 方法 + +> [!tip] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + + +| Name | Description | Required | Platform | HarmonyOS Support | +| ---------------------- | ---------------------------------------------- | -------- |----------|-------------------| +| getLocales() | Returns the user preferred locales, in order. | No | All | yes | +| etNumberFormatSettings() | Returns number formatting settings. | No | All | yes | +| getCurrencies() | Returns the user preferred currency codes, in order. | No | All | yes | +| getCountry() | Returns the user current country code (based on its device locale, not on its position). | No | All | yes | +| getCalendar() | Returns the user preferred calendar format. | No | All | yes | +| getTemperatureUnit() | Returns the user preferred temperature unit. | No | All | No | +| getTimeZone() | Returns the user preferred timezone (based on its device settings, not on its position). | No | All | yes | +| uses24HourClock() | Returns true if the user prefers 24h clock format, false if they prefer 12h clock format. | No | All | yes | +| usesMetricSystem() | Returns true if the user prefers metric measure system, false if they prefer imperial. | No | All | No | +| usesAutoDateAndTime() | Tells if the automatic date & time setting is enabled on the phone. Android only | No | Android | No | +| usesAutoTimeZone() | Tells if the automatic time zone setting is enabled on the phone. Android only | No | Android | No | + + +## 遗留问题 +- [ ] 鸿蒙侧无法获取温度及长度单位[issue#2](https://github.com/react-native-oh-library/react-native-localize/issues/2) + +## 其他 + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/zoontek/react-native-localize/blob/main/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee From 73ab2447230423801ae079344b04df2e60e6449c Mon Sep 17 00:00:00 2001 From: liqi Date: Tue, 30 Apr 2024 17:37:46 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[Issues:=20#I9L0QD]=20=E4=BF=AE=E6=94=B9rea?= =?UTF-8?q?ct-native-localize=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-localize.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zh-cn/react-native-localize.md b/zh-cn/react-native-localize.md index 051820c7..5fa81b34 100644 --- a/zh-cn/react-native-localize.md +++ b/zh-cn/react-native-localize.md @@ -185,7 +185,7 @@ target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) # RNOH_END: manual_package_linking_2 ``` -### 在 ArkTs 侧引入 RNKeepAwakePackage +### 在 ArkTs 侧引入 RNLocalizePackage 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: -- Gitee From 9a54499bed26408dc220a08e1097037ca5dcf653 Mon Sep 17 00:00:00 2001 From: liqi Date: Tue, 30 Apr 2024 18:00:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[Issues:=20#I9L19F]=20=E6=96=B0=E5=A2=9Erea?= =?UTF-8?q?ct-native-simple-toast=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/react-native-simple-toast.md | 149 +++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 zh-cn/react-native-simple-toast.md diff --git a/zh-cn/react-native-simple-toast.md b/zh-cn/react-native-simple-toast.md new file mode 100644 index 00000000..d12a18bc --- /dev/null +++ b/zh-cn/react-native-simple-toast.md @@ -0,0 +1,149 @@ +> 模板版本:v0.2.0 + +

+

react-native-simple-toast

+

+

+ + Supported platforms + + + License + +

+ +> [!TIP] [Github 地址](https://github.com/vonovak/react-native-simple-toast) + + +## 安装与使用 + +请到三方库的 Releases 发布地址查看配套的版本信息:[<@react-native-oh-tpl/react-native-simple-toast> Releases] +(https://github.com/react-native-oh-library/react-native-simple-toast/releases),并下载适用版本的 tgz 包。 + +进入到工程目录并输入以下命令: + +>[!TIP] # 处替换为 tgz 包的路径 + + + +#### **npm** + +```bash +npm install @react-native-oh-tpl/react-native-simple-toast@file:# +``` + +#### **yarn** + +```bash +yarn add @react-native-oh-tpl/react-native-simple-toast@file:# +``` + + + +下面的代码展示了这个库的基本使用场景: + +>[!WARNING] 使用时 import 的库名不变。 + +```js +import * as React from 'react'; + +import { + StyleSheet, + View, + Button, + Alert, + TextInput, + ScrollView, + Pressable, + Modal, + Text, +} from 'react-native'; +import Toast from 'react-native-simple-toast'; +import { useState } from 'react'; + +export default function App() { + const [modalVisible, setModalVisible] = useState(false); + + return ( + <> + { + Alert.alert('Modal has been closed.'); + setModalVisible(!modalVisible); + }} + > + + + Hello World! + setModalVisible(!modalVisible)} + > + Hide Modal + + + + + + + +