File tree 1 file changed +22
-10
lines changed
packages/react-native-web/src/exports/TextInput
1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,15 @@ const TextInput: React.AbstractComponent<
192
192
193
193
const dimensions = React . useRef ( { height : null , width : null } ) ;
194
194
const hostRef = React . useRef ( null ) ;
195
+ const prevSelection = React . useRef ( null ) ;
196
+ const prevSecureTextEntry = React . useRef ( false ) ;
197
+
198
+ React . useEffect ( ( ) => {
199
+ if ( hostRef . current && prevSelection . current ) {
200
+ setSelection ( hostRef . current , prevSelection . current ) ;
201
+ }
202
+ prevSecureTextEntry . current = secureTextEntry ;
203
+ } , [ secureTextEntry ] ) ;
195
204
196
205
const handleContentSizeChange = React . useCallback (
197
206
( hostNode ) => {
@@ -323,18 +332,21 @@ const TextInput: React.AbstractComponent<
323
332
}
324
333
325
334
function handleSelectionChange ( e ) {
326
- if ( onSelectionChange ) {
327
- try {
328
- const node = e . target ;
329
- const { selectionStart, selectionEnd } = node ;
330
- e . nativeEvent . selection = {
331
- start : selectionStart ,
332
- end : selectionEnd
333
- } ;
335
+ try {
336
+ const { selectionStart , selectionEnd } = e . target ;
337
+ const selection = {
338
+ start : selectionStart ,
339
+ end : selectionEnd
340
+ } ;
341
+ if ( onSelectionChange ) {
342
+ e . nativeEvent . selection = selection ;
334
343
e . nativeEvent . text = e . target . value ;
335
344
onSelectionChange ( e ) ;
336
- } catch ( e ) { }
337
- }
345
+ }
346
+ if ( prevSecureTextEntry . current === secureTextEntry ) {
347
+ prevSelection . current = selection ;
348
+ }
349
+ } catch ( e ) { }
338
350
}
339
351
340
352
useLayoutEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments