react-native-transformer-text-input 0.1.0-alpha.2 → 0.1.0-alpha.3

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.
Files changed (2) hide show
  1. package/README.md +35 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,7 +1,17 @@
1
- # react-native-transformer-text-input
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.
@@ -123,7 +156,7 @@ Code in this repository is thought through and mostly written by humans, with AI
123
156
 
124
157
  ## Acknowledgments
125
158
 
126
- - [react-native-live-markdown](https://github.com/Expensify/react-native-live-markdown) for an example of how to extend TextInput.
159
+ - [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
160
  - [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
161
 
129
162
  ## Contributing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-transformer-text-input",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.3",
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",