diff --git a/zh-cn/react-native-compass-heading.md b/zh-cn/react-native-compass-heading.md new file mode 100644 index 0000000000000000000000000000000000000000..526b6ebdeb5af137bf45fb68f5ce09fe42d5206b --- /dev/null +++ b/zh-cn/react-native-compass-heading.md @@ -0,0 +1,215 @@ +> 模板版本:v0.2.2 + +

+

react-native-compass-heading

+

+

+ + Supported platforms + + + License + +

+ +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-compass-heading) + +## 安装与使用 + +请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-compass-heading Releases](https://github.com/react-native-oh-library/react-native-compass-heading/releases),并下载适用版本的 tgz 包。 + +进入到工程目录并输入以下命令: + +> [!TIP] # 处替换为 tgz 包的路径 + + + +#### **npm** + +```bash +npm install @react-native-oh-tpl/react-native-compass-heading@file:# +``` + +#### **yarn** + +```bash +yarn add @react-native-oh-tpl/react-native-compass-heading@file:# +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 + +```js +import * as React from "react"; +import { useState, useEffect } from "react"; +import { StyleSheet, View, Text, Button, ScrollView } from "react-native"; +import CompassHeading from "react-native-compass-heading"; + +export function RNCompassHeading() { + const [heading, setHeading] = useState(0); + const [accuracy, setAccuracy] = useState(0); + + interface Data { + heading: number; + accuracy: number; + } + + useEffect(() => { + const degree_update_rate = 3; + CompassHeading.start(degree_update_rate, (data: Data) => { + setHeading(data.heading); + setAccuracy(data.accuracy); + }); + return () => { + CompassHeading.stop(); + }; + }, []); + + return ( + + + + {"heading: " + heading} + {"headings: " + accuracy} + + + + ); +} + +const styles = StyleSheet.create({ + container: { + backgroundColor: "#fff", + alignItems: "center", + justifyContent: "center", + height: 400, + }, +}); +``` + +## 使用 Codegen + +本库已经适配了 `Codegen` ,在使用前需要主动执行生成三方库桥接代码,详细请参考[ Codegen 使用文档](/zh-cn/codegen.md)。 + +## Link + +目前 HarmonyOS 暂不支持 AutoLink,所以 Link 步骤需要手动配置。 + +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony` + +### 在工程根目录的 `oh-package.json5` 添加 overrides 字段 + +```json +{ + ... + "overrides": { + "@rnoh/react-native-openharmony" : "./react_native_openharmony" + } +} +``` + +### 引入原生端代码 + +目前有两种方法: + +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/react-native-compass-heading": "file:../../node_modules/@react-native-oh-tpl/react-native-compass-heading/harmony/compass_heading.har" + } +``` + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +方法二:直接链接源码 + +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) + +### 在 ArkTs 侧引入 RNHeadingCompassPackage Package + +打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: + +```diff + ... ++ import {RNHeadingCompassPackage} from '@react-native-oh-tpl/react-native-compass-heading/ts'; + +export function createRNPackages(ctx: RNPackageContext): RNPackage[] { + return [ + new SamplePackage(ctx), ++ new RNHeadingCompassPackage(ctx) + ]; +} +``` + +### 运行 + +点击右上角的 `sync` 按钮 + +或者在终端执行: + +```bash +cd entry +ohpm install +``` + +然后编译、运行即可。 + +## 约束与限制 + +### 兼容性 + +要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 + +请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/react-native-compass-heading Releases](https://github.com/react-native-oh-library/react-native-compass-heading/releases) + +## API + +> [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 + +> [!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。 + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ----- | ------------- | ----------------------------------------------------- | -------- | ----------- | ----------------- | +| start | start compass | (degreeUpdateRate: number, callback: CompassCallback) | yes | Android/iOS | yes | +| stop | stop compass | void | no | Android/iOS | yes | + +### start() + +| Name | Description | Type | Required | Platform | HarmonyOS Support | +| ---------------- | ------------------------- | --------------------------------------------- | -------- | ----------- | ----------------- | +| degreeUpdateRate | Compass refresh frequency | number | yes | Android/iOS | yes | +| callback | compass callback | ({heading: number;accuracy: number;}) => void | yes | Android/iOS | yes | + +## 遗留问题 + +## 其他 + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/firofame/react-native-compass-heading/blob/master/LICENSE) ,请自由地享受和参与开源。 diff --git a/zh-cn/react-native-print.md b/zh-cn/react-native-print.md new file mode 100644 index 0000000000000000000000000000000000000000..3051d4777afcf1419343bedf4cd88485b13960bc --- /dev/null +++ b/zh-cn/react-native-print.md @@ -0,0 +1,315 @@ +> 模板版本:v0.2.2 + +

+

react-native-print

+

+

+ + Supported platforms + + + License + + +

+ +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-print) + +## 安装与使用 + +请到三方库的 Releases 发布地址查看配套的版本信息:[@react-native-oh-tpl/react-native-print Releases](https://github.com/react-native-oh-library/react-native-print/releases),并下载适用版本的 tgz 包。 + +进入到工程目录并输入以下命令: + +> [!TIP] # 处替换为 tgz 包的路径 + + + +#### **npm** + +```bash +npm install @react-native-oh-tpl/react-native-print@file:# +``` + +#### **yarn** + +```bash +yarn add @react-native-oh-tpl/react-native-print@file:# +``` + + + +下面的代码展示了这个库的基本使用场景: + +> [!WARNING] 使用时 import 的库名不变。 + +```js +import {Tester, TestSuite, TestCase} from '@rnoh/testerino'; +import React, {useState} from 'react'; +import { + ScrollView, + Button, +} from 'react-native'; +import { + pick, + DocumentPickerOptions, + isCancel, +} from 'react-native-document-picker'; +import RNPrint from 'react-native-print'; + +type DirType = 'documentDirectory' | 'cachesDirectory'; + +interface DirOpt { + label: DirType; + selected: boolean; +} + +export default function RNPrint(): JSX.Element { + const [pickResult, setPickResult] = useState(''); + const [allowMultiSelection, setAllowMultiSelection] = useState(true); + const [fileTypes, setFileTypes] = useState([]); + const [dirUi, setDirui] = useState>([ + {label: 'documentDirectory', selected: false}, + {label: 'cachesDirectory', selected: false}, + ]); + const copyTo = dirUi.find(d => d.selected)?.label; + const pickOpt: DocumentPickerOptions<'harmony'> = { + allowMultiSelection, + presentationStyle: 'overFullScreen', + }; + if (copyTo) { + pickOpt.copyTo = copyTo; + } + if (fileTypes.length) { + pickOpt.type = fileTypes; + } + const pickFile = async () => { + try { + const res = await pick(pickOpt); + setPickResult(JSON.stringify(res)); + return res; + } catch (err) { + console.log(err); + console.log('isCancel: ' + isCancel(err)); + } + }; + + return ( +