react-native-typerich 1.0.0 → 1.1.1
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
|
@@ -11,36 +11,266 @@ npm install react-native-typerich
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
```
|
|
14
|
+
```jsx
|
|
15
15
|
import { TypeRichTextInput } from 'react-native-typerich';
|
|
16
16
|
|
|
17
17
|
// ...
|
|
18
|
-
|
|
19
18
|
<TypeRichTextInput
|
|
20
|
-
ref={
|
|
19
|
+
ref={inputRef}
|
|
20
|
+
value={value}
|
|
21
21
|
style={styles.typeRichTextInput}
|
|
22
22
|
placeholder="Type here..."
|
|
23
23
|
placeholderTextColor="rgb(0, 26, 114)"
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
editable={true}
|
|
25
|
+
selectionColor="deepskyblue"
|
|
26
|
+
cursorColor="dodgerblue"
|
|
26
27
|
autoCapitalize="words"
|
|
28
|
+
autoFocus
|
|
27
29
|
onChangeText={(text: string) => console.log(text)}
|
|
28
30
|
onFocus={() => console.log('focused')}
|
|
29
31
|
onBlur={() => console.log('blurred')}
|
|
30
32
|
onChangeSelection={(e: { start: number, end: number, text: string }) =>
|
|
31
33
|
console.log(e)
|
|
32
34
|
}
|
|
33
|
-
androidExperimentalSynchronousEvents={true}
|
|
34
|
-
multiline
|
|
35
|
-
numberOfLines={5}
|
|
36
35
|
onPasteImageData={(e) => {
|
|
36
|
+
setImage(e);
|
|
37
37
|
console.log(e);
|
|
38
38
|
}}
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
androidExperimentalSynchronousEvents={true} // not tested very well
|
|
40
|
+
multiline
|
|
41
|
+
numberOfLines={5}
|
|
42
|
+
lineHeight={22}
|
|
43
|
+
fontFamily="serif"
|
|
44
|
+
fontStyle="italic"
|
|
45
|
+
fontWeight={'700'}
|
|
46
|
+
fontSize={26}
|
|
47
|
+
color="darkgreen"
|
|
41
48
|
/>;
|
|
42
49
|
```
|
|
43
50
|
|
|
51
|
+
## Props
|
|
52
|
+
|
|
53
|
+
- **Props that works Same as React Native's Default `TextInput`:**
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
value?: string;
|
|
57
|
+
autoFocus?: boolean;
|
|
58
|
+
editable?: boolean;
|
|
59
|
+
defaultValue?: string;
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
placeholderTextColor?: ColorValue;
|
|
62
|
+
cursorColor?: ColorValue;
|
|
63
|
+
selectionColor?: ColorValue;
|
|
64
|
+
autoCapitalize?: string;
|
|
65
|
+
scrollEnabled?: boolean;
|
|
66
|
+
secureTextEntry?: boolean;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- **Styling Props you need to pass externally:**
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
color?: ColorValue;
|
|
73
|
+
fontSize?: Float;
|
|
74
|
+
fontFamily?: string;
|
|
75
|
+
fontWeight?: string;
|
|
76
|
+
fontStyle?: string;
|
|
77
|
+
lineHeight?: Float;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- **props that have some bugs:**
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
multiline?: boolean;
|
|
84
|
+
numberOfLines?: Int32;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
> using this togather adds some extra height sometimes.
|
|
88
|
+
> use multline without numberOfLines and it works fine
|
|
89
|
+
> use `maxHeight` instead of number of lines
|
|
90
|
+
|
|
91
|
+
> [!NOTE]
|
|
92
|
+
> This is not a Major bug and the change is unnoticable
|
|
93
|
+
|
|
94
|
+
## Events
|
|
95
|
+
|
|
96
|
+
### 1. onFocus
|
|
97
|
+
|
|
98
|
+
callback signature
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
onFocus?: () => void;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 2. onBlur
|
|
105
|
+
|
|
106
|
+
callback signature
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
onBlur?: () => void;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 3. onChangeText
|
|
113
|
+
|
|
114
|
+
callback signature
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
onChangeText?: (value: string) => void;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 4. onChangeSelection
|
|
121
|
+
|
|
122
|
+
callback signature
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
onChangeSelection?: (event: {
|
|
126
|
+
start: number;
|
|
127
|
+
end: number;
|
|
128
|
+
text: string;
|
|
129
|
+
}) => void;
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 4. onPasteImageData
|
|
133
|
+
|
|
134
|
+
> fires on when user paste image
|
|
135
|
+
|
|
136
|
+
callback signature
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
onPasteImageData?: (data: {
|
|
140
|
+
uri: string;
|
|
141
|
+
type: string;
|
|
142
|
+
fileName: string;
|
|
143
|
+
fileSize: Double;
|
|
144
|
+
source: 'keyboard' | 'clipboard' | 'context_menu'; // it never receives source as 'context_menu' and will be removed in future we suggest not using it
|
|
145
|
+
error?: { message: string };
|
|
146
|
+
}) => void;
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Event props
|
|
150
|
+
|
|
151
|
+
- `uri`: uri of the image, can be directly used or passed to Image comp
|
|
152
|
+
- `type`: mime type of image
|
|
153
|
+
- `fileName`: File name of image (always starts with `typerich_` prefix)
|
|
154
|
+
- `fileSize`: File Size in bytes
|
|
155
|
+
- `source`: its enum with two possible values
|
|
156
|
+
- `keyboard`: if its pasted from gboard's clipboard or is a sticker or something similar
|
|
157
|
+
- `clipboard`: if its pasted from context menu (long press)
|
|
158
|
+
- `error`: error message if there is any
|
|
159
|
+
|
|
160
|
+
## Commands
|
|
161
|
+
|
|
162
|
+
### 1. focus()
|
|
163
|
+
|
|
164
|
+
> use to get programmatic focus on TextInput
|
|
165
|
+
|
|
166
|
+
Command signature
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
focus: () => void;
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
useage
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
inputRef.current?.focus();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 2. blur()
|
|
179
|
+
|
|
180
|
+
> use to programmatically blur TextInput
|
|
181
|
+
|
|
182
|
+
Command signature
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
blur: () => void;
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
useage
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
inputRef.current?.blur();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 3. setText(text)
|
|
195
|
+
|
|
196
|
+
> use to set the value of TextInput (replaces whole content)
|
|
197
|
+
|
|
198
|
+
> [!NOTE]
|
|
199
|
+
> it does not updates selection automatically use have to call `setSelection()`
|
|
200
|
+
|
|
201
|
+
Command signature
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
setText: (text: string) => void;
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
useage
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
inputRef.current?.setText('This is Text');
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### 4. insertTextAt(start, end, text)
|
|
214
|
+
|
|
215
|
+
> use to insert value at specific position (keeps content of TextInput)
|
|
216
|
+
|
|
217
|
+
> [!NOTE]
|
|
218
|
+
> it preserves the cursor and updates the selection
|
|
219
|
+
> no need to call the `setSelection` after this
|
|
220
|
+
|
|
221
|
+
Command signature
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
insertTextAt: (start: number, end: number, text: string) => void;
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
useage
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
inputRef.current?.insertTextAt(4, 6, 'This is Text');
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 5. setSelection(start, end)
|
|
234
|
+
|
|
235
|
+
> use to set the value of TextInput (replaces whole content)
|
|
236
|
+
|
|
237
|
+
Command signature
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
setSelection: (start: number, end: number) => void;
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
useage
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
inputRef.current?.setSelection(4, 6);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 6. getNativeRef()
|
|
250
|
+
|
|
251
|
+
> use to get the internal ref object of the TypeRichTextInput
|
|
252
|
+
|
|
253
|
+
> [!NOTE]
|
|
254
|
+
> you mostly does not need to use this
|
|
255
|
+
> only use this when you need to use the ref in certain cases like following
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
const hostRef = input?.getNativeRef?.();
|
|
259
|
+
const node = findNodeHandle(hostRef); // findNodeHandle is from 'react-native'
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Command signature
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
getNativeRef: () => any | null;
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
useage
|
|
269
|
+
|
|
270
|
+
```ts
|
|
271
|
+
inputRef.current?.getNativeRef();
|
|
272
|
+
```
|
|
273
|
+
|
|
44
274
|
## Contributing
|
|
45
275
|
|
|
46
276
|
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
@@ -54,3 +284,12 @@ MIT
|
|
|
54
284
|
---
|
|
55
285
|
|
|
56
286
|
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
287
|
+
|
|
288
|
+
## Credits
|
|
289
|
+
|
|
290
|
+
- **Divyanshu Patil** – Author & maintainer
|
|
291
|
+
- Built with help from the open-source community ❤️
|
|
292
|
+
|
|
293
|
+
### special thanks to [Software-Mansion](https://github.com/software-mansion) for the custom shadow node code
|
|
294
|
+
|
|
295
|
+
checkout [react-native-enriched](https://github.com/software-mansion/react-native-enriched) by [software-mansion](https://github.com/software-mansion)
|
|
@@ -496,6 +496,7 @@ class TypeRichTextInputView : AppCompatEditText {
|
|
|
496
496
|
val sizePx = ceil(PixelUtil.toPixelFromSP(size))
|
|
497
497
|
fontSize = sizePx
|
|
498
498
|
setTextSize(TypedValue.COMPLEX_UNIT_PX, sizePx)
|
|
499
|
+
layoutManager.invalidateLayout()
|
|
499
500
|
}
|
|
500
501
|
|
|
501
502
|
fun setFontFamily(family: String?) {
|
|
@@ -539,6 +540,10 @@ class TypeRichTextInputView : AppCompatEditText {
|
|
|
539
540
|
}
|
|
540
541
|
|
|
541
542
|
fun setSecureTextEntry(isSecure: Boolean) {
|
|
543
|
+
if (isSecure) {
|
|
544
|
+
setMultiline(false)
|
|
545
|
+
maxLines = 1
|
|
546
|
+
}
|
|
542
547
|
transformationMethod =
|
|
543
548
|
if (isSecure)
|
|
544
549
|
android.text.method.PasswordTransformationMethod.getInstance()
|