模板版本:v0.2.2
[!TIP] Github 地址
进入到工程目录并输入以下命令:
npm install [email protected]
yarn add [email protected]
使用时,还需在项目下的module.json5处配置querySchemes
{
"module": {
...
+ "querySchemes": ["maps","http","https","customDomain"],
}
}
下面的代码展示了这个库的基本使用场景:
[!WARNING] 使用时 import 的库名不变。
import React, { useState } from "react";
import { View, Text } from "react-native";
import Hyperlink from "react-native-hyperlink";
export default function App() {
return (
<Hyperlink
linkDefault
injectViewProps={(url) => ({
testID: url === "http://link.com" ? "id1" : "id2",
style:
url === "https://link.com" ? { color: "red" } : { color: "blue" },
//any other props you wish to pass to the component
})}
>
<Text>
You can pass props to clickable components matched by url.
<Text>This url looks red https://link.com</Text> and this url looks blue
https://link2.com{" "}
</Text>
</Hyperlink>
);
}
本文档内容基于以下版本验证通过:
- RNOH: 0.72.27; SDK: HarmonyOS-Next-DB1 5.0.0.25 (API Version 12 Canary4); IDE: DevEco Studio 5.0.3.400SP7; ROM: 3.0.0.29;
- RNOH:0.72.33; SDK:OpenHarmony 5.0.0.71(API Version 12 Release); IDE:DevEco Studio 5.0.3.900; ROM:NEXT.0.0.71;
[!TIP] "Platform"列表示该属性在原三方库上支持的平台。
[!TIP] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
Name | Description | Type | Required | Platform | HarmonyOS Support |
---|---|---|---|---|---|
linkify | linkify-it object, for custom schema | object | no | all | yes |
linkStyle | highlight clickable text with styles | object | no | all | yes |
linkText | A string or a func to replace parsed text | string | function | no | all | yes |
onPress | Func to handle click over a clickable text with parsed text as arg | function | no | all | yes |
onLongPress | Func to handle long click over a clickable text with parsed text as arg | function | no | all | yes |
linkDefault | A platform specific fallback to handle onPress. Uses Linking. Disabled by default | boolean | no | all | yes |
injectViewProps | Func with url as a param to inject props to the clickable component | function | no | all | yes |
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。