react-native-transformer-text-input 0.1.0-alpha.1 → 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.
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
@@ -8,7 +8,31 @@ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
8
8
  set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../cpp)
9
9
  set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
10
10
  set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL})
11
- set(REACT_NATIVE_WORKLETS_DIR ${LIB_ANDROID_DIR}/../node_modules/react-native-worklets)
11
+
12
+ # Resolve path to react-native-worklets.
13
+ set(REACT_NATIVE_WORKLETS_DIR "" CACHE PATH "Path to react-native-worklets root directory")
14
+
15
+ if(NOT DEFINED REACT_NATIVE_WORKLETS_DIR OR "${REACT_NATIVE_WORKLETS_DIR}" STREQUAL "")
16
+ set(NODE_BINARY "node" CACHE STRING "Path to Node.js binary")
17
+
18
+ execute_process(
19
+ COMMAND "${NODE_BINARY}" -p "require.resolve('react-native-worklets/package.json')"
20
+ WORKING_DIRECTORY "${PROJECT_ROOT_DIR}/.."
21
+ OUTPUT_VARIABLE _worklets_pkg_json
22
+ OUTPUT_STRIP_TRAILING_WHITESPACE
23
+ RESULT_VARIABLE _worklets_res
24
+ ERROR_QUIET
25
+ )
26
+
27
+ if (NOT _worklets_res EQUAL 0)
28
+ message(FATAL_ERROR
29
+ "Failed to resolve 'react-native-worklets' with Node from '${PROJECT_ROOT_DIR}/..'. "
30
+ "Set REACT_NATIVE_WORKLETS_DIR or NODE_BINARY explicitly."
31
+ )
32
+ endif()
33
+
34
+ get_filename_component(REACT_NATIVE_WORKLETS_DIR "${_worklets_pkg_json}" DIRECTORY)
35
+ endif()
12
36
 
13
37
  file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_DIR}/*.cpp)
14
38
  file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_JNI_DIR}/*.cpp ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp)
@@ -33,8 +57,11 @@ target_include_directories(
33
57
  "${REACT_NATIVE_WORKLETS_DIR}/android/src/main/cpp"
34
58
  )
35
59
 
36
- message(STATUS "ANDROID_NDK_BUILD_TYPE = ${ANDROID_NDK_BUILD_TYPE}")
37
-
60
+ if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
61
+ set(BUILD_TYPE "debug")
62
+ else()
63
+ set(BUILD_TYPE "release")
64
+ endif()
38
65
 
39
66
  add_library(worklets SHARED IMPORTED)
40
67
 
@@ -42,7 +69,7 @@ set_target_properties(
42
69
  worklets
43
70
  PROPERTIES
44
71
  IMPORTED_LOCATION
45
- "${REACT_NATIVE_WORKLETS_DIR}/android/build/intermediates/cmake/debug/obj/${ANDROID_ABI}/libworklets.so"
72
+ "${REACT_NATIVE_WORKLETS_DIR}/android/build/intermediates/cmake/${BUILD_TYPE}/obj/${ANDROID_ABI}/libworklets.so"
46
73
  )
47
74
 
48
75
  target_link_libraries(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-transformer-text-input",
3
- "version": "0.1.0-alpha.1",
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",