@klyftig/mobile-ui 1.3.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@klyftig/mobile-ui",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "scripts": {
5
5
  "pack-install": "npm pack && mv klyftig-ui-*.tgz /tmp/klyftig-ui-local.tgz && cd ../../mobile && npm install /tmp/klyftig-ui-local.tgz"
6
6
  },
@@ -1,4 +1,4 @@
1
- import React, { useState, useCallback, memo } from 'react';
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,6 +60,25 @@ 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
+ // 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);
73
+
74
+ useEffect(() => {
75
+ setDelayedSelectionStart(undefined);
76
+ if (isFocused || multiline) return;
77
+ const id = setTimeout(() => {
78
+ setDelayedSelectionStart({ start: 0, end: 0 });
79
+ }, 50);
80
+ return () => clearTimeout(id);
81
+ }, [value, isFocused, multiline]);
63
82
 
64
83
  const handleFocus = useCallback(() => {
65
84
  setIsFocused(true);
@@ -105,7 +124,7 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
105
124
  onFocus={handleFocus}
106
125
  onBlur={handleBlur}
107
126
  selectTextOnFocus={selectTextOnFocus}
108
- selection={!isFocused && !multiline ? SELECTION_START : undefined}
127
+ selection={!isFocused && !multiline ? (delayedSelectionStart ?? SELECTION_START) : undefined}
109
128
  multiline={multiline}
110
129
  numberOfLines={numberOfLines}
111
130
  textAlignVertical={multiline ? 'top' : undefined}