@onekeyfe/react-native-text-input 6.7.0-5 → 6.7.0-50

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 CHANGED
@@ -1,6 +1,38 @@
1
+ <div align="center">
2
+
1
3
  # @onekeyfe/react-native-text-input
2
4
 
3
- React Native TextInput with paste events for text and images on Android and iOS.
5
+ **React Native's `TextInput` plus native paste events for text and image clipboard items.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-text-input?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-text-input)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-text-input?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Android](https://img.shields.io/badge/Android-3DDC84?logo=android&logoColor=white)
11
+ ![Fabric](https://img.shields.io/badge/Fabric-4D6BFE)
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 application's iOS pods and rebuild the native application to register
12
- the paste integration. The default export accepts React Native `TextInputProps`
13
- and the additional `onPaste` callback.
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 TextInput from '@onekeyfe/react-native-text-input';
19
-
20
- <TextInput
21
- onPaste={({ nativeEvent }) => {
22
- console.log(nativeEvent.items);
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
- ## Paste events and platform differences
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
- `onPaste` receives `nativeEvent.items`, an optional array whose entries have
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
- - iOS image items contain a MIME type and a temporary local file URL. Consume
34
- that file while available; the application owns any durable copy it needs.
35
- - Android inspects the first clipboard item. For URI content it reports the
36
- content resolver's MIME type and original URI, without copying an image into
37
- a temporary file. Text paste still follows the underlying native input path.
38
- - With no `onPaste` callback, the native paste subscription/watcher is disabled.
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
- Do not assume an Android content URI is an iOS-style filesystem path. The native
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
- The public payload types are in [src/type.ts](src/type.ts). The
46
- [native behavior specification](https://github.com/OneKeyHQ/app-modules/blob/main/native-views/react-native-text-input/docs/SPEC.md)
47
- records event ownership, temporary-file handling and acceptance limits.
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
- ## Consuming paste payloads
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
- Check `nativeEvent.items` before iterating: the public type allows it to be
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
- On Android both Paste and Paste as plain text continue through the underlying
57
- input paste path after the optional event. On iOS the availability cache is only
58
- a menu hint; the actual paste action checks clipboard contents. The
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).
@@ -100,7 +100,7 @@ class TextInputViewPasteTest {
100
100
  ClipData(ClipDescription("uri", arrayOf("text/uri-list")), ClipData.Item(uri))
101
101
 
102
102
  private class TestReactContext(base: Context) : BridgeReactContext(base) {
103
- override fun <T : NativeModule?> getNativeModule(nativeModuleInterface: Class<T>): T? = null
103
+ override fun <T : NativeModule> getNativeModule(nativeModuleInterface: Class<T>): T? = null
104
104
  }
105
105
 
106
106
  private class MimeProvider(private val mime: String?) : ContentProvider() {
@@ -13,13 +13,17 @@ static dispatch_semaphore_t OneKeyTestReleaseRead;
13
13
 
14
14
  - (BOOL)onekey_test_hasImages
15
15
  {
16
- dispatch_semaphore_t releaseRead;
17
- dispatch_semaphore_t readStarted;
18
- @synchronized (UIPasteboard.class) {
19
- releaseRead = OneKeyTestReleaseRead;
20
- readStarted = OneKeyTestReadStarted;
16
+ dispatch_semaphore_t releaseRead = nil;
17
+ dispatch_semaphore_t readStarted = nil;
18
+ if (!NSThread.isMainThread) {
19
+ @synchronized (UIPasteboard.class) {
20
+ releaseRead = OneKeyTestReleaseRead;
21
+ readStarted = OneKeyTestReadStarted;
22
+ OneKeyTestReleaseRead = nil;
23
+ OneKeyTestReadStarted = nil;
24
+ }
21
25
  }
22
- if (!NSThread.isMainThread && releaseRead != nil) {
26
+ if (releaseRead != nil && readStarted != nil) {
23
27
  dispatch_semaphore_signal(readStarted);
24
28
  dispatch_semaphore_wait(releaseRead, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC));
25
29
  }
@@ -39,6 +43,8 @@ static dispatch_semaphore_t OneKeyTestReleaseRead;
39
43
  NSArray<NSDictionary<NSString *, id> *> *previousItems = pasteboard.items;
40
44
  RCTUITextField *field = [[RCTUITextField alloc] initWithFrame:CGRectZero];
41
45
  SEL paste = @selector(paste:);
46
+ dispatch_semaphore_t readStarted = dispatch_semaphore_create(0);
47
+ dispatch_semaphore_t releaseRead = dispatch_semaphore_create(0);
42
48
 
43
49
  @try {
44
50
  pasteboard.items = @[];
@@ -49,8 +55,8 @@ static dispatch_semaphore_t OneKeyTestReleaseRead;
49
55
  XCTAssertFalse([field canPerformAction:paste withSender:nil]);
50
56
 
51
57
  @synchronized (UIPasteboard.class) {
52
- OneKeyTestReadStarted = dispatch_semaphore_create(0);
53
- OneKeyTestReleaseRead = dispatch_semaphore_create(0);
58
+ OneKeyTestReadStarted = readStarted;
59
+ OneKeyTestReleaseRead = releaseRead;
54
60
  }
55
61
  static dispatch_once_t onceToken;
56
62
  dispatch_once(&onceToken, ^{
@@ -60,25 +66,22 @@ static dispatch_semaphore_t OneKeyTestReleaseRead;
60
66
  });
61
67
 
62
68
  UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(1, 1)];
63
- pasteboard.image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
69
+ UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
64
70
  [UIColor.blackColor setFill];
65
71
  UIRectFill(CGRectMake(0, 0, 1, 1));
66
72
  }];
73
+ [pasteboard setData:UIImagePNGRepresentation(image) forPasteboardType:@"public.png"];
67
74
  [NSNotificationCenter.defaultCenter postNotificationName:UIPasteboardChangedNotification object:pasteboard];
68
- XCTAssertEqual(dispatch_semaphore_wait(OneKeyTestReadStarted, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC)), 0L);
75
+ XCTAssertEqual(dispatch_semaphore_wait(readStarted, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC)), 0L);
69
76
 
70
77
  [NSNotificationCenter.defaultCenter postNotificationName:name object:field];
71
78
  XCTAssertTrue([field canPerformAction:paste withSender:nil]);
72
79
  } @finally {
73
- dispatch_semaphore_t releaseRead;
74
80
  @synchronized (UIPasteboard.class) {
75
- releaseRead = OneKeyTestReleaseRead;
76
81
  OneKeyTestReleaseRead = nil;
77
82
  OneKeyTestReadStarted = nil;
78
83
  }
79
- if (releaseRead != nil) {
80
- dispatch_semaphore_signal(releaseRead);
81
- }
84
+ dispatch_semaphore_signal(releaseRead);
82
85
  pasteboard.items = previousItems;
83
86
  }
84
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-text-input",
3
- "version": "6.7.0-5",
3
+ "version": "6.7.0-50",
4
4
  "description": "React Native TextInput with native paste events",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -54,11 +54,11 @@
54
54
  "registry": "https://registry.npmjs.org/"
55
55
  },
56
56
  "devDependencies": {
57
- "@react-native/babel-preset": "0.86.2",
58
- "@types/react": "^19.2.0",
57
+ "@react-native/babel-preset": "0.88.0",
58
+ "@types/react": "^19.3.0",
59
59
  "del-cli": "^6.0.0",
60
- "react": "19.2.3",
61
- "react-native": "patch:react-native@npm%3A0.86.2#~/.yarn/patches/react-native-npm-0.86.2-c9d546616f.patch",
60
+ "react": "19.3.0",
61
+ "react-native": "patch:react-native@npm%3A0.88.0#~/.yarn/patches/react-native-npm-0.88.0-60c6201dd2.patch",
62
62
  "react-native-builder-bob": "^0.40.13",
63
63
  "typescript": "^5.9.2"
64
64
  },