You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+291-25
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Auto-Linking component for React Native. Parses text and wraps URLs, phone numbe
6
6
7
7
## Installation
8
8
9
-
```javascript
9
+
```shell
10
10
npm install react-native-autolink --save
11
11
```
12
12
@@ -23,37 +23,303 @@ class MyComponent extends Component {
23
23
<Autolink
24
24
text="This is the string to parse for urls (https://github.com/joshswan/react-native-autolink), phone numbers (415-555-5555), emails ([email protected]), mentions/handles (@twitter), and hashtags (#exciting)"
25
25
hashtag="instagram"
26
-
mention="twitter"/>
26
+
mention="twitter"
27
+
/>
27
28
);
28
29
}
29
30
}
30
31
```
31
32
32
33
## Props
33
34
34
-
**Note: Any props not listed below will be passed through to the main Text node (e.g. style, numberOfLines).**
35
-
36
-
| Prop | Type | Default | Description |
37
-
| ---- | ---- | ------- | ----------- |
38
-
|`text`|`String`||***Required.*** The string to parse for links. |
|`stripPrefix`|`Boolean`|`true`| Enable stripping of protocol from link text (`https://url` -> `url`). |
47
-
|`stripTrailingSlash`|`Boolean`|`true`| Enable stripping of trailing slashs from link text (`example.com/page/` -> `example.com/page`). |
48
-
|`linkStyle`|`TextStyle`|| Custom styling to apply to Text nodes of links. |
49
-
|`onPress`|`function`|| Custom function handler for link press events. Arguments: `url:String`, [`match:Object`][match-url]. |
50
-
|`onLongPress`|`function`|| Function handler for long press events. Arguments: `url:String`, [`match:Object`][match-url]|
51
-
|`renderLink`|`function`|| Custom render function for rendering link nodes. Arguments: `text:String`, [`match:Object`][match-url], `index:Number`. |
52
-
|`showAlert`|`Boolean`|`false`| Displays an alert before leaving the app to help with accidental clicks. Possible values: `true`, `false`|
53
-
|`truncate`|`Number`|`32`| Truncate long link text for display (e.g. `https://www.google.com/../something.html`). Possible values: `0` to disable, `1+` to truncate to that maximum length. |
54
-
|`truncateChars`|`String`|`..`| Characters to replace truncated url segments with, if enabled. |
55
-
|`truncateLocation`|`String`|`"smart"`| Specify location of truncation. Possible values: `"smart"`, `"end"`, `"middle"`. |
56
-
|`webFallback`|`Boolean`| Android: `true` iOS: `false`| Link to web versions of Instagram/Twitter for hashtag and mention links when users don't have the respective app installed. *Requires `LSApplicationQueriesSchemes` on iOS. See: https://facebook.github.io/react-native/docs/linking.html*|
35
+
-[`component?`](#component)
36
+
-[`email?`](#email)
37
+
-[`hashtag?`](#hashtag)
38
+
-[`latlng?`](#latlng)
39
+
-[`linkProps?`](#linkprops)
40
+
-[`linkStyle?`](#linkstyle)
41
+
-[`mention?`](#mention)
42
+
-[`onPress?`](#onpress)
43
+
-[`onLongPress?`](#onlongpress)
44
+
-[`phone?`](#phone)
45
+
-[`renderLink?`](#renderlink)
46
+
-[`renderText?`](#rendertext)
47
+
-[`showAlert?`](#showalert)
48
+
-[`stripPrefix?`](#stripprefix)
49
+
-[`stripTrailingSlash?`](#striptrailingslash)
50
+
-[`text`](#text)
51
+
-[`textProps?`](#textprops)
52
+
-[`truncate?`](#truncate)
53
+
-[`truncateChars?`](#truncatechars)
54
+
-[`truncateLocation?`](#truncatelocation)
55
+
-[`url?`](#url)
56
+
-[`webFallback?`](#webfallback)
57
+
58
+
**Note:** All other props (e.g. `numberOfLines`, `style`, etc.) will be passed through to the container component, which is either `Text` (default) or a custom component supplied to the `component` prop.
| boolean or string | No |`false`| Whether to link hashtags to supplied service. Possible values: `false` (disabled), `"facebook"`, `"instagram"`, `"twitter"`. |
85
+
86
+
```js
87
+
<Autolink text={text} hashtag="facebook"/>
88
+
```
89
+
90
+
### `latlng`
91
+
92
+
| Type | Required | Default | Description |
93
+
| ------- | -------- | ------- | ----------- |
94
+
| boolean | No |`false`| Whether to link latitude, longitude pairs. |
95
+
96
+
*Warning:* Still experimental.
97
+
98
+
```js
99
+
<Autolink text={text} latlng />
100
+
```
101
+
102
+
### `linkProps`
103
+
104
+
| Type | Required | Default | Description |
105
+
| --------- | -------- | ------- | ----------- |
106
+
| TextProps | No |`{}`| Attributes applied to link Text components. |
| boolean or string | No |`false`| Whether to link mentions/handles to supplied service. Possible values: `false` (disabled), `"instagram"`, `"soundcloud"`, `"twitter"`. |
127
+
128
+
```js
129
+
<Autolink text={text} mention="instagram"/>
130
+
```
131
+
132
+
### `onPress`
133
+
134
+
| Type | Required | Default | Description |
135
+
| -------- | -------- | ------- | ----------- |
136
+
| function | No || Override default link press behavior. Signature: `(url: string, match: Match) => void`. |
137
+
138
+
```js
139
+
<Autolink
140
+
text={text}
141
+
onPress={(url, match) => {
142
+
switch (match.getType()) {
143
+
case'mention':
144
+
Alert.alert('Mention pressed!');
145
+
default:
146
+
Alert.alert('Link pressed!');
147
+
}
148
+
}}
149
+
/>
150
+
```
151
+
152
+
### `onLongPress`
153
+
154
+
| Type | Required | Default | Description |
155
+
| -------- | -------- | ------- | ----------- |
156
+
| function | No | none | Handle link long press events. Signature: `(url: string, match: Match) => void`. |
| boolean or string | No |`true`| Whether to link phone numbers. Possible values: `false` (disabled), `true` (`tel:{number}`), `"sms"` or `"text"` (`sms:{number}`). |
177
+
178
+
*Note:* Currently, only US numbers are supported.
179
+
180
+
```js
181
+
<Autolink text={text} phone="sms"/>
182
+
```
183
+
184
+
### `renderLink`
185
+
186
+
| Type | Required | Default | Description |
187
+
| -------- | -------- | ------- | ----------- |
188
+
| function | No || Override default link rendering behavior. Signature: `(text: string, match: Match, index: number) => React.ReactNode`. |
189
+
190
+
*Note:* You'll need to handle press logic yourself when using `renderLink`.
| boolean | No | Android: `true`, iOS: `false`| Whether to link to web versions of services (e.g. Facebook, Instagram, Twitter) for hashtag and mention links when users don't have the respective app installed. |
321
+
322
+
*Note:* Requires `LSApplicationQueriesSchemes` on iOS so it is disabled by default on iOS. See [Linking docs](https://reactnative.dev/docs/linking.html) for more info.
0 commit comments