@onekeyfe/react-native-text-input 6.7.0-alpha.466 → 6.8.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -39
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-text-input
|
|
2
4
|
|
|
3
|
-
React Native TextInput
|
|
5
|
+
**React Native's `TextInput` plus native paste events for text and image clipboard items.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-text-input)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Wraps React Native text inputs and emits a native `onPaste` event for clipboard
|
|
16
|
+
content that React Native does not surface, including images. The platform input
|
|
17
|
+
still performs the actual paste; the callback reports what the clipboard held and
|
|
18
|
+
the application decides how to use it. Payloads are platform-shaped: iOS loads an
|
|
19
|
+
image into a temporary file, Android reports the clipboard item's URI and MIME
|
|
20
|
+
type without copying it. There is no Web implementation.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **Native paste events** — an optional `onPaste` callback reports clipboard
|
|
25
|
+
items next to the ordinary `TextInput` props.
|
|
26
|
+
- **Text and image coverage** — text uses `text/plain`; image clipboard items
|
|
27
|
+
arrive with a platform-specific locator instead of raw bytes.
|
|
28
|
+
- **No Android copy** — for URI content the package reports the content
|
|
29
|
+
resolver's MIME type and the original URI, without creating a temporary file.
|
|
30
|
+
- **iOS temporary file URL** — image data is written to a temporary file and the
|
|
31
|
+
application owns any durable copy it needs.
|
|
32
|
+
- **Full `TextInput` surface** — the default export accepts React Native
|
|
33
|
+
`TextInputProps`, including controlled text and ref methods.
|
|
34
|
+
- **Opt-in native listener** — with no `onPaste`, iOS has no paste subscription
|
|
35
|
+
and Android has no paste watcher.
|
|
4
36
|
|
|
5
37
|
## Installation
|
|
6
38
|
|
|
@@ -8,57 +40,85 @@ React Native TextInput with paste events for text and images on Android and iOS.
|
|
|
8
40
|
yarn add @onekeyfe/react-native-text-input
|
|
9
41
|
```
|
|
10
42
|
|
|
11
|
-
Install the
|
|
12
|
-
the paste
|
|
13
|
-
|
|
43
|
+
Install the app's iOS pods and rebuild the native application after adding the
|
|
44
|
+
package so the iOS paste observer and the Android input component are
|
|
45
|
+
registered; Android links through autolinking. The package declares no
|
|
46
|
+
additional permissions or `Info.plist` entries.
|
|
14
47
|
|
|
15
48
|
## Usage
|
|
16
49
|
|
|
17
50
|
```tsx
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
import { useCallback, useState } from 'react';
|
|
52
|
+
import TextInput, {
|
|
53
|
+
type IPasteEventParams,
|
|
54
|
+
} from '@onekeyfe/react-native-text-input';
|
|
55
|
+
|
|
56
|
+
function PasteAwareField() {
|
|
57
|
+
const [text, setText] = useState('');
|
|
58
|
+
const onPaste = useCallback((event: IPasteEventParams) => {
|
|
59
|
+
const item = event.nativeEvent.items?.[0];
|
|
60
|
+
if (item?.type === 'text/plain') {
|
|
61
|
+
console.log(item.data);
|
|
62
|
+
}
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<TextInput
|
|
67
|
+
style={{ minHeight: 48 }}
|
|
68
|
+
value={text}
|
|
69
|
+
onChangeText={setText}
|
|
70
|
+
onPaste={onPaste}
|
|
71
|
+
placeholder="Paste text or an image"
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
25
75
|
```
|
|
26
76
|
|
|
27
|
-
|
|
77
|
+
Check `nativeEvent.items` before iterating and inspect each item's `type` before
|
|
78
|
+
interpreting its `data`.
|
|
79
|
+
|
|
80
|
+
## API
|
|
81
|
+
|
|
82
|
+
| Export | Type | Description | Platforms |
|
|
83
|
+
| --- | --- | --- | :-: |
|
|
84
|
+
| `TextInput` (default) | component | React Native `TextInput` props and ref, plus `onPaste`. | iOS, Android |
|
|
85
|
+
| `ITextInputProps` | interface | Extends React Native `TextInputProps` with `onPaste`. | iOS, Android |
|
|
86
|
+
| `onPaste` | `(event: IPasteEventParams) => void` | Paste event; absent items are allowed. | iOS, Android |
|
|
87
|
+
| `IPasteEventParams` | type | `{ nativeEvent: { items?: IPasteEventPayload } }`. | iOS, Android |
|
|
88
|
+
| `IPasteEventPayloadItem` | type | `{ type?: EPasteEventPayloadItemType; data?: string }`. | iOS, Android |
|
|
89
|
+
| `EPasteEventPayloadItemType` | enum | MIME types; currently `TextPlain = 'text/plain'`. | iOS, Android |
|
|
90
|
+
|
|
91
|
+
See [`src/type.ts`](src/type.ts) for the payload types and
|
|
92
|
+
[`docs/SPEC.md`](docs/SPEC.md) for event ownership, temporary-file handling and
|
|
93
|
+
the platform behavior.
|
|
28
94
|
|
|
29
|
-
|
|
30
|
-
`type` and `data` fields. Text items use `text/plain` and carry their text in
|
|
31
|
-
`data`. The event does not supply image bytes directly.
|
|
95
|
+
## Platform support
|
|
32
96
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
97
|
+
| Capability | iOS | Android | Web |
|
|
98
|
+
| --- | :-: | :-: | :-: |
|
|
99
|
+
| Emit `onPaste` | ✅ | ✅ | — |
|
|
100
|
+
| Text items (`text/plain`) | ✅ | ✅ | — |
|
|
101
|
+
| Image items | ✅ MIME + temporary file URL | ✅ MIME + content URI | — |
|
|
102
|
+
| Plain `TextInput` behavior without `onPaste` | ✅ | ✅ | — |
|
|
39
103
|
|
|
40
|
-
|
|
41
|
-
input retains its ordinary paste fallback when there is no reportable event.
|
|
42
|
-
This package defines paste integration for iOS and Android, not a Web clipboard
|
|
43
|
-
implementation.
|
|
104
|
+
## Caveats
|
|
44
105
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
106
|
+
> [!IMPORTANT]
|
|
107
|
+
> `onPaste` never supplies image bytes. iOS gives a temporary file URL that the
|
|
108
|
+
> application should consume while it is available; Android gives a content URI
|
|
109
|
+
> plus MIME type and copies nothing. The application owns any durable copy.
|
|
48
110
|
|
|
49
|
-
|
|
111
|
+
> [!NOTE]
|
|
112
|
+
> Android inspects only the first clipboard item. Without an `onPaste` callback
|
|
113
|
+
> the native paste subscription/watcher is disabled, and both platforms still
|
|
114
|
+
> run their ordinary native paste path after an optional event.
|
|
50
115
|
|
|
51
|
-
|
|
52
|
-
absent. Inspect each item's MIME `type` before interpreting its string `data`.
|
|
53
|
-
A text string, a temporary iOS file URL and an Android content URI need distinct
|
|
54
|
-
consumer handling; the callback does not copy them into a common byte format.
|
|
116
|
+
## References
|
|
55
117
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
[specification](https://github.com/OneKeyHQ/app-modules/blob/main/native-views/react-native-text-input/docs/SPEC.md) separates these platform behaviors and documents
|
|
60
|
-
pending device acceptance.
|
|
118
|
+
- [Package spec](docs/SPEC.md)
|
|
119
|
+
- [Example page](../../example/react-native/pages/TextInputTestPage.tsx)
|
|
120
|
+
- [Changelog](../../CHANGELOG.md)
|
|
61
121
|
|
|
62
122
|
## License
|
|
63
123
|
|
|
64
|
-
MIT.
|
|
124
|
+
MIT. See [LICENSE](LICENSE).
|