@klyftig/mobile-ui 1.3.0 → 1.3.2

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.0",
3
+ "version": "1.3.2",
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
  },
@@ -4,13 +4,15 @@ import { MaterialCommunityIcons as Icon } from '@expo/vector-icons';
4
4
  import { useTheme } from '../hooks/useTheme';
5
5
 
6
6
  interface GlassInputProps {
7
- label: string;
7
+ label?: string;
8
8
  value: string;
9
9
  onChangeText: (text: string) => void;
10
10
  placeholder?: string;
11
11
  secureTextEntry?: boolean;
12
- keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad';
12
+ keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'decimal-pad' | 'number-pad';
13
13
  autoCapitalize?: 'none' | 'sentences' | 'words' | 'characters';
14
+ multiline?: boolean;
15
+ numberOfLines?: number;
14
16
  // Off by default for fields where iOS would otherwise replace partially-edited
15
17
  // multi-word values with its autocorrect suggestion and snap the caret to end.
16
18
  autoCorrect?: boolean;
@@ -45,6 +47,8 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
45
47
  onFocus,
46
48
  onBlur,
47
49
  selectTextOnFocus,
50
+ multiline = false,
51
+ numberOfLines,
48
52
  }) => {
49
53
  const { colors } = useTheme();
50
54
  const [isSecure, setIsSecure] = useState(secureTextEntry);
@@ -66,7 +70,9 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
66
70
 
67
71
  return (
68
72
  <View style={styles.container}>
69
- <Text style={[styles.label, { color: colors.text.primary }]}>{label}</Text>
73
+ {label ? (
74
+ <Text style={[styles.label, { color: colors.text.primary }]}>{label}</Text>
75
+ ) : null}
70
76
  <View
71
77
  style={[
72
78
  styles.inputContainer,
@@ -74,7 +80,7 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
74
80
  disabled && styles.inputContainerDisabled,
75
81
  ]}
76
82
  >
77
- <View style={styles.inputWrapper}>
83
+ <View style={[styles.inputWrapper, multiline && styles.inputWrapperMultiline]}>
78
84
  {icon && (
79
85
  <Icon name={icon} size={20} color="#9B9B9B" style={styles.leftIcon} />
80
86
  )}
@@ -92,12 +98,20 @@ const GlassInputComponent: React.FC<GlassInputProps> = ({
92
98
  onFocus={handleFocus}
93
99
  onBlur={handleBlur}
94
100
  selectTextOnFocus={selectTextOnFocus}
101
+ multiline={multiline}
102
+ numberOfLines={numberOfLines}
103
+ textAlignVertical={multiline ? 'top' : undefined}
95
104
  textContentType={textContentType ?? (secureTextEntry ? 'oneTimeCode' : undefined)}
96
105
  autoComplete={autoComplete as any}
97
106
  accessibilityLabel={label}
98
- accessibilityHint={placeholder ? `Enter ${label.toLowerCase()}` : undefined}
107
+ accessibilityHint={placeholder && label ? `Enter ${label.toLowerCase()}` : undefined}
99
108
  accessibilityState={{ disabled }}
100
- style={[styles.input, icon && styles.inputWithLeftIcon, (rightText || showPasswordToggle) && styles.inputWithRightIcon]}
109
+ style={[
110
+ styles.input,
111
+ icon && styles.inputWithLeftIcon,
112
+ (rightText || showPasswordToggle) && styles.inputWithRightIcon,
113
+ multiline && styles.inputMultiline,
114
+ ]}
101
115
  />
102
116
  {rightText && (
103
117
  <Text style={styles.rightText}>{rightText}</Text>
@@ -154,6 +168,17 @@ const styles = StyleSheet.create({
154
168
  paddingHorizontal: 16,
155
169
  height: 56,
156
170
  },
171
+ inputWrapperMultiline: {
172
+ height: undefined,
173
+ minHeight: 96,
174
+ paddingVertical: 12,
175
+ alignItems: 'flex-start',
176
+ },
177
+ inputMultiline: {
178
+ height: undefined,
179
+ minHeight: 72,
180
+ paddingTop: 4,
181
+ },
157
182
  leftIcon: {
158
183
  marginRight: 12,
159
184
  },
@@ -1,11 +1,12 @@
1
- import React, { useEffect, useMemo, useRef } from 'react';
1
+ import React, { useCallback, useEffect, useMemo, useRef } from 'react';
2
2
  import {
3
- ScrollView,
3
+ FlatList,
4
4
  View,
5
5
  Text,
6
6
  StyleSheet,
7
7
  NativeSyntheticEvent,
8
8
  NativeScrollEvent,
9
+ ListRenderItem,
9
10
  } from 'react-native';
10
11
  import { useTheme } from '../hooks/useTheme';
11
12
 
@@ -34,7 +35,7 @@ export function WheelPicker({
34
35
  flex,
35
36
  }: WheelPickerProps) {
36
37
  const { colors } = useTheme();
37
- const scrollRef = useRef<ScrollView>(null);
38
+ const listRef = useRef<FlatList<number>>(null);
38
39
  const containerHeight = itemHeight * visibleCount;
39
40
  const padding = (containerHeight - itemHeight) / 2;
40
41
  const lastIndexRef = useRef<number>(-1);
@@ -45,22 +46,58 @@ export function WheelPicker({
45
46
  }, [values, selected]);
46
47
 
47
48
  useEffect(() => {
48
- if (selectedIndex !== lastIndexRef.current) {
49
- lastIndexRef.current = selectedIndex;
50
- requestAnimationFrame(() => {
51
- scrollRef.current?.scrollTo({ y: selectedIndex * itemHeight, animated: false });
52
- });
53
- }
49
+ if (selectedIndex === lastIndexRef.current) return;
50
+ const prev = lastIndexRef.current;
51
+ lastIndexRef.current = selectedIndex;
52
+ // Skip the very first effect — initialScrollIndex already positioned us.
53
+ if (prev === -1) return;
54
+ listRef.current?.scrollToOffset({ offset: selectedIndex * itemHeight, animated: false });
54
55
  }, [selectedIndex, itemHeight]);
55
56
 
56
- const handleMomentumEnd = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
57
- const offsetY = e.nativeEvent.contentOffset.y;
58
- const index = Math.round(offsetY / itemHeight);
59
- const clamped = Math.max(0, Math.min(values.length - 1, index));
60
- if (values[clamped] !== selected) {
61
- onChange(values[clamped]);
62
- }
63
- };
57
+ const handleMomentumEnd = useCallback(
58
+ (e: NativeSyntheticEvent<NativeScrollEvent>) => {
59
+ const offsetY = e.nativeEvent.contentOffset.y;
60
+ const index = Math.round(offsetY / itemHeight);
61
+ const clamped = Math.max(0, Math.min(values.length - 1, index));
62
+ if (values[clamped] !== selected) {
63
+ onChange(values[clamped]);
64
+ }
65
+ },
66
+ [itemHeight, values, selected, onChange],
67
+ );
68
+
69
+ const getItemLayout = useCallback(
70
+ (_: ArrayLike<number> | null | undefined, index: number) => ({
71
+ length: itemHeight,
72
+ offset: itemHeight * index,
73
+ index,
74
+ }),
75
+ [itemHeight],
76
+ );
77
+
78
+ const keyExtractor = useCallback((item: number) => String(item), []);
79
+
80
+ const dimColor = colors.text.tertiary;
81
+ const activeColor = colors.text.primary;
82
+
83
+ const renderItem: ListRenderItem<number> = useCallback(
84
+ ({ item, index }) => {
85
+ const isSelected = index === selectedIndex;
86
+ return (
87
+ <View style={[styles.item, { height: itemHeight }]}>
88
+ <Text
89
+ style={[
90
+ styles.itemText,
91
+ { color: isSelected ? activeColor : dimColor },
92
+ ]}
93
+ >
94
+ {formatLabel ? formatLabel(item) : String(item)}
95
+ </Text>
96
+ </View>
97
+ );
98
+ },
99
+ [selectedIndex, itemHeight, activeColor, dimColor, formatLabel],
100
+ );
64
101
 
65
102
  return (
66
103
  <View style={[styles.wrapper, { height: containerHeight, width, flex }]}>
@@ -71,34 +108,25 @@ export function WheelPicker({
71
108
  { top: padding, height: itemHeight, backgroundColor: 'rgba(0,0,0,0.06)' },
72
109
  ]}
73
110
  />
74
- <ScrollView
75
- ref={scrollRef}
111
+ <FlatList
112
+ ref={listRef}
113
+ data={values}
114
+ keyExtractor={keyExtractor}
115
+ renderItem={renderItem}
116
+ getItemLayout={getItemLayout}
117
+ initialScrollIndex={selectedIndex}
118
+ extraData={selectedIndex}
76
119
  showsVerticalScrollIndicator={false}
77
120
  snapToInterval={itemHeight}
78
121
  decelerationRate="fast"
79
122
  contentContainerStyle={{ paddingTop: padding, paddingBottom: padding }}
80
123
  onMomentumScrollEnd={handleMomentumEnd}
81
124
  nestedScrollEnabled
82
- contentOffset={{ x: 0, y: selectedIndex * itemHeight }}
83
- >
84
- {values.map((item, index) => {
85
- const isSelected = index === selectedIndex;
86
- return (
87
- <View key={item} style={[styles.item, { height: itemHeight }]}>
88
- <Text
89
- style={[
90
- styles.itemText,
91
- {
92
- color: isSelected ? colors.text.primary : colors.text.tertiary,
93
- },
94
- ]}
95
- >
96
- {formatLabel ? formatLabel(item) : String(item)}
97
- </Text>
98
- </View>
99
- );
100
- })}
101
- </ScrollView>
125
+ initialNumToRender={visibleCount + 4}
126
+ windowSize={3}
127
+ maxToRenderPerBatch={visibleCount + 4}
128
+ removeClippedSubviews
129
+ />
102
130
  </View>
103
131
  );
104
132
  }