react-native-transformer-text-input 0.1.0-alpha.2 → 0.1.0-alpha.4
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,7 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# React Native Transformer Text Input
|
|
2
2
|
|
|
3
3
|
TextInput component that allows transforming text synchronously with a worklet.
|
|
4
4
|
|
|
5
|
+
## Motivation
|
|
6
|
+
|
|
7
|
+
Transforming input as users type is common — phone numbers, credit cards, usernames. Existing approaches have trade-offs:
|
|
8
|
+
|
|
9
|
+
**Pattern-based masking** (e.g., [react-native-advanced-input-mask](https://github.com/IvanIhnatsiuk/react-native-advanced-input-mask)) uses declarative patterns like `+1 ([000]) [000]-[0000]`. This works well for fixed formats, but patterns can't express conditional logic, variable-length formats, or transformations that depend on context.
|
|
10
|
+
|
|
11
|
+
**Controlled inputs** (`value` + `onChangeText` + state) give you full JS flexibility, but create a native → JS → re-render → native round-trip. This causes visible lag and cursor flicker—the input feels sluggish because keystrokes are corrected asynchronously.
|
|
12
|
+
|
|
13
|
+
**This library** combines JS flexibility with synchronous execution. Your transform runs as a worklet on the UI thread — no bridge delay, no flicker. Write any logic you need with the responsiveness of a native input.
|
|
14
|
+
|
|
5
15
|
## Installation
|
|
6
16
|
```sh
|
|
7
17
|
npm install react-native-transformer-text-input
|
|
@@ -98,6 +108,29 @@ Default behavior when no `selection` is returned:
|
|
|
98
108
|
|
|
99
109
|
The library includes ready-to-use transformers for common use cases.
|
|
100
110
|
|
|
111
|
+
### PatternTransformer
|
|
112
|
+
|
|
113
|
+
Formats input using a pattern string with placeholder characters.
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { PatternTransformer } from 'react-native-transformer-text-input/formatters/pattern';
|
|
117
|
+
|
|
118
|
+
const dateTransformer = new PatternTransformer({
|
|
119
|
+
pattern: '##/##/####', // # = digit, A = letter, * = alphanumeric
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Formats as: 12/31/2024
|
|
123
|
+
<TransformerTextInput
|
|
124
|
+
transformer={dateTransformer}
|
|
125
|
+
keyboardType="number-pad"
|
|
126
|
+
/>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Options:
|
|
130
|
+
- `pattern`: Pattern string where `#` matches digits, `A` matches letters, `*` matches alphanumeric.
|
|
131
|
+
- `definitions`: Custom placeholder definitions (e.g., `{ 'X': /[0-9A-F]/i }` for hex).
|
|
132
|
+
- `showTrailingLiterals`: Show literal characters after the last input (default: `false`).
|
|
133
|
+
|
|
101
134
|
### PhoneNumberTransformer
|
|
102
135
|
|
|
103
136
|
Formats phone numbers as the user types.
|
|
@@ -117,13 +150,9 @@ const phoneTransformer = new PhoneNumberTransformer({
|
|
|
117
150
|
/>
|
|
118
151
|
```
|
|
119
152
|
|
|
120
|
-
## AI Disclosure
|
|
121
|
-
|
|
122
|
-
Code in this repository is thought through and mostly written by humans, with AI used to improve clarity, consistency, and implementation details.
|
|
123
|
-
|
|
124
153
|
## Acknowledgments
|
|
125
154
|
|
|
126
|
-
- [react-native-live-markdown](https://github.com/Expensify/react-native-live-markdown) for
|
|
155
|
+
- [react-native-live-markdown](https://github.com/Expensify/react-native-live-markdown) and [react-native-advanced-input-mask](https://github.com/IvanIhnatsiuk/react-native-advanced-input-mask) for examples of how to extend TextInput.
|
|
127
156
|
- [react-native-worklets](https://github.com/software-mansion/react-native-reanimated/tree/main/packages/react-native-worklets) for the worklet runtime powering UI-thread execution.
|
|
128
157
|
|
|
129
158
|
## Contributing
|
|
@@ -3,6 +3,11 @@ require "json"
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
5
|
pods_root = Pod::Config.instance.project_pods_root
|
|
6
|
+
|
|
7
|
+
react_native_node_modules_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
|
|
8
|
+
react_native_common_dir_absolute = File.join(react_native_node_modules_dir, 'ReactCommon')
|
|
9
|
+
react_native_common_dir = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
|
|
10
|
+
|
|
6
11
|
react_native_worklets_node_modules_dir = ENV['REACT_NATIVE_WORKLETS_NODE_MODULES_DIR'] ||
|
|
7
12
|
File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native-worklets/package.json')"`)
|
|
8
13
|
react_native_worklets_node_modules_dir_from_pods_root = Pathname.new(react_native_worklets_node_modules_dir).relative_path_from(pods_root).to_s
|
|
@@ -28,6 +33,7 @@ Pod::Spec.new do |s|
|
|
|
28
33
|
|
|
29
34
|
s.xcconfig = {
|
|
30
35
|
"HEADER_SEARCH_PATHS" => [
|
|
36
|
+
"\"$(PODS_ROOT)/#{react_native_common_dir}\"",
|
|
31
37
|
"\"$(PODS_ROOT)/#{react_native_worklets_node_modules_dir_from_pods_root}/apple\"",
|
|
32
38
|
"\"$(PODS_ROOT)/#{react_native_worklets_node_modules_dir_from_pods_root}/Common/cpp\"",
|
|
33
39
|
].join(' '),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-transformer-text-input",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.4",
|
|
4
4
|
"description": "TextInput component that allows transforming text synchronously with a worklet",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|