@klyftig/mobile-ui 1.3.9 → 1.3.10
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/package.json +1 -1
- package/src/components/GlassInput.tsx +15 -12
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useCallback, useEffect,
|
|
1
|
+
import React, { useState, useCallback, useEffect, memo } from 'react';
|
|
2
2
|
import { View, TextInput as RNTextInput, Text, TouchableOpacity, StyleSheet } from 'react-native';
|
|
3
3
|
import { MaterialCommunityIcons as Icon } from '@expo/vector-icons';
|
|
4
4
|
import { useTheme } from '../hooks/useTheme';
|
|
@@ -60,19 +60,23 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
60
60
|
const { colors } = useTheme();
|
|
61
61
|
const [isSecure, setIsSecure] = useState(secureTextEntry);
|
|
62
62
|
const [isFocused, setIsFocused] = useState(false);
|
|
63
|
-
|
|
63
|
+
// Reinforces the `selection` prop below: on Android, setting `selection` on
|
|
64
|
+
// the SAME render as a `value` that's longer than the field's width is
|
|
65
|
+
// often ignored — the native EditText hasn't measured/laid out the text yet,
|
|
66
|
+
// so it doesn't know where to scroll to reveal position 0. `setNativeProps`
|
|
67
|
+
// does NOT reliably fix this on Android either (selection isn't reliably
|
|
68
|
+
// forwarded through that imperative path for TextInput) — it has to be a
|
|
69
|
+
// genuine PROP change through normal React reconciliation to hit the native
|
|
70
|
+
// "set selection and scroll" command. A fresh object (new reference) fed
|
|
71
|
+
// through state a tick after mount, once layout has committed, does that.
|
|
72
|
+
const [delayedSelectionStart, setDelayedSelectionStart] = useState<typeof SELECTION_START | undefined>(undefined);
|
|
64
73
|
|
|
65
|
-
// Reinforces the `selection` prop below: on Android, setting `selection`
|
|
66
|
-
// on the SAME render as a `value` that's longer than the field's width is
|
|
67
|
-
// often ignored — the native EditText hasn't measured/laid out the text
|
|
68
|
-
// yet, so it doesn't know where to scroll to reveal position 0. Re-asserting
|
|
69
|
-
// via setNativeProps a tick after layout commits (not the same frame)
|
|
70
|
-
// reliably forces the scroll where the declarative prop alone doesn't.
|
|
71
74
|
useEffect(() => {
|
|
75
|
+
setDelayedSelectionStart(undefined);
|
|
72
76
|
if (isFocused || multiline) return;
|
|
73
77
|
const id = setTimeout(() => {
|
|
74
|
-
|
|
75
|
-
},
|
|
78
|
+
setDelayedSelectionStart({ start: 0, end: 0 });
|
|
79
|
+
}, 50);
|
|
76
80
|
return () => clearTimeout(id);
|
|
77
81
|
}, [value, isFocused, multiline]);
|
|
78
82
|
|
|
@@ -107,7 +111,6 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
107
111
|
<Icon name={icon} size={20} color="#9B9B9B" style={styles.leftIcon} />
|
|
108
112
|
)}
|
|
109
113
|
<RNTextInput
|
|
110
|
-
ref={inputRef}
|
|
111
114
|
value={value}
|
|
112
115
|
onChangeText={onChangeText}
|
|
113
116
|
placeholder={placeholder}
|
|
@@ -121,7 +124,7 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
|
|
|
121
124
|
onFocus={handleFocus}
|
|
122
125
|
onBlur={handleBlur}
|
|
123
126
|
selectTextOnFocus={selectTextOnFocus}
|
|
124
|
-
selection={!isFocused && !multiline ? SELECTION_START : undefined}
|
|
127
|
+
selection={!isFocused && !multiline ? (delayedSelectionStart ?? SELECTION_START) : undefined}
|
|
125
128
|
multiline={multiline}
|
|
126
129
|
numberOfLines={numberOfLines}
|
|
127
130
|
textAlignVertical={multiline ? 'top' : undefined}
|