Skip to content

Commit 5499396

Browse files
docs: update readme
1 parent caa6eb1 commit 5499396

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
TextInput component that allows transforming text synchronously with a worklet.
44

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+
515
## Installation
616
```sh
717
npm install react-native-transformer-text-input
@@ -98,6 +108,29 @@ Default behavior when no `selection` is returned:
98108
99109
The library includes ready-to-use transformers for common use cases.
100110

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+
101134
### PhoneNumberTransformer
102135

103136
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
123156

124157
## Acknowledgments
125158

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.
127160
- [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.
128161

129162
## Contributing

example/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ hermesEnabled=true
4141
# Use this property to enable edge-to-edge display support.
4242
# This allows your app to draw behind system bars for an immersive UI.
4343
# Note: Only works with ReactActivity and should not be used with custom Activity.
44-
edgeToEdgeEnabled=false
44+
edgeToEdgeEnabled=true

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TouchableOpacity,
77
Alert,
88
type TextInputProps,
9+
StatusBar,
910
} from 'react-native';
1011
import {
1112
KeyboardAwareScrollView,
@@ -160,6 +161,7 @@ export default function App() {
160161
return (
161162
<KeyboardProvider>
162163
<SafeAreaProvider>
164+
<StatusBar barStyle="dark-content" />
163165
<AppContent />
164166
</SafeAreaProvider>
165167
</KeyboardProvider>

0 commit comments

Comments
 (0)