@towsila/expo-ui-library 4.11.4 → 4.11.6

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.
@@ -1,4 +1,3 @@
1
-
2
1
  import { useState, useRef } from "react";
3
2
  import {
4
3
  Text,
@@ -6,6 +5,7 @@ import {
6
5
  TouchableOpacity,
7
6
  ScrollView,
8
7
  Modal,
8
+ useWindowDimensions,
9
9
  } from "react-native";
10
10
  import { useAppTheme } from "../../context/ThemeContext";
11
11
  import { Fonts, textSize } from "../../tokens/typography";
@@ -30,6 +30,8 @@ interface SelectProps {
30
30
  bgColor?: string;
31
31
  }
32
32
 
33
+ const DROPDOWN_MAX_HEIGHT = 240;
34
+
33
35
  export default function Select({
34
36
  options,
35
37
  value,
@@ -50,17 +52,23 @@ export default function Select({
50
52
 
51
53
  const triggerRef = useRef<View>(null);
52
54
  const { colors } = useAppTheme();
53
- const {isRTL} = useLanguage();
55
+ const { isRTL } = useLanguage();
56
+ const { height: screenH } = useWindowDimensions();
54
57
 
55
- const selectedLabel = options.find(
56
- (option) => option.value === value
57
- )?.label;
58
+ const selectedLabel = options.find((option) => option.value === value)?.label;
58
59
 
59
60
  const handleOpen = () => {
60
61
  triggerRef.current?.measureInWindow((x, y, width, measuredHeight) => {
62
+ const spaceBelow = screenH - (y + measuredHeight);
63
+ const spaceAbove = y;
64
+ // Flip above if there isn't enough room below AND there's more room above
65
+ const flipUp =
66
+ spaceBelow < DROPDOWN_MAX_HEIGHT + 8 && spaceAbove > spaceBelow;
61
67
  setDropdownPos({
62
68
  x,
63
- y: y + measuredHeight,
69
+ y: flipUp
70
+ ? Math.max(y - DROPDOWN_MAX_HEIGHT - 4, 8)
71
+ : y + measuredHeight,
64
72
  width,
65
73
  });
66
74
  setOpen(true);
@@ -68,8 +76,9 @@ export default function Select({
68
76
 
69
77
  onClearError?.();
70
78
  };
71
- const align = isRTL ? "right":"left";
72
- const layout = isRTL?"row-reverse":"row";
79
+ const align = isRTL ? "right" : "left";
80
+ const layout = isRTL ? "row-reverse" : "row";
81
+
73
82
  return (
74
83
  <View style={{ marginBottom: 4 }}>
75
84
  {label && (
@@ -79,7 +88,7 @@ const layout = isRTL?"row-reverse":"row";
79
88
  fontSize: textSize.xs,
80
89
  fontFamily: Fonts.montserrat.semiBold,
81
90
  marginBottom: 6,
82
- textAlign: align
91
+ textAlign: align,
83
92
  }}
84
93
  >
85
94
  {label}
@@ -93,44 +102,48 @@ const layout = isRTL?"row-reverse":"row";
93
102
  <View ref={triggerRef} collapsable={false}>
94
103
  <View
95
104
  style={{
96
- height,
105
+ minHeight: height,
97
106
  backgroundColor: bgColor ?? colors.background.main,
98
107
  borderWidth: 1.4,
99
108
  borderColor: error
100
109
  ? colors.semantic.error
101
110
  : open
102
- ? colors.primary
103
- : colors.text.primary,
111
+ ? colors.primary
112
+ : colors.text.primary,
104
113
  borderRadius: 12,
105
114
  paddingHorizontal: 14,
106
- flexDirection:layout,
115
+ paddingVertical: 12,
116
+ flexDirection: layout,
107
117
  alignItems: "center",
108
118
  justifyContent: "space-between",
119
+ gap: 8,
109
120
  }}
110
121
  >
111
122
  <Text
112
123
  numberOfLines={1}
113
124
  style={{
114
125
  flex: 1,
126
+ minWidth: 0,
115
127
  fontSize: textSize.sm,
116
128
  fontFamily: Fonts.montserrat.regular,
117
129
  color: colors.text.primary,
118
- textAlign: align
130
+ textAlign: align,
119
131
  }}
120
132
  >
121
133
  {selectedLabel ?? placeholder}
122
134
  </Text>
123
-
124
- <Ionicons
125
- name={open ? "chevron-up" : "chevron-down"}
126
- size={16}
127
- color={colors.text.primary}
128
- />
135
+ <View style={{ flexShrink: 0 }}>
136
+ <Ionicons
137
+ name={open ? "chevron-up" : "chevron-down"}
138
+ size={16}
139
+ color={colors.text.primary}
140
+ />
141
+ </View>
129
142
  </View>
130
143
  </View>
131
144
  </TouchableOpacity>
132
145
 
133
- {error && <ErrorMessage message={error} position={align}/>}
146
+ {error && <ErrorMessage message={error} position={align} />}
134
147
 
135
148
  <Modal
136
149
  visible={open}
@@ -146,10 +159,10 @@ const layout = isRTL?"row-reverse":"row";
146
159
  <View
147
160
  style={{
148
161
  position: "absolute",
149
- top: dropdownPos.y + 50,
162
+ top: dropdownPos.y,
150
163
  left: dropdownPos.x,
151
164
  width: dropdownPos.width,
152
- maxHeight: 240,
165
+ maxHeight: DROPDOWN_MAX_HEIGHT,
153
166
  backgroundColor: bgColor ?? colors.background.card,
154
167
  borderRadius: 12,
155
168
  borderWidth: 1.4,
@@ -168,9 +181,8 @@ const layout = isRTL?"row-reverse":"row";
168
181
  nestedScrollEnabled
169
182
  showsVerticalScrollIndicator={false}
170
183
  >
171
- {options.map((option, index) => {
184
+ {options.map((option) => {
172
185
  const isSelected = option.value === value;
173
-
174
186
  return (
175
187
  <TouchableOpacity
176
188
  key={option.value}
@@ -185,14 +197,17 @@ const layout = isRTL?"row-reverse":"row";
185
197
  flexDirection: layout,
186
198
  alignItems: "center",
187
199
  justifyContent: "space-between",
200
+ gap: 8,
188
201
  backgroundColor: isSelected
189
202
  ? colors.primary + "12"
190
203
  : bgColor ?? colors.background.card,
191
204
  }}
192
205
  >
193
206
  <Text
207
+ numberOfLines={1}
194
208
  style={{
195
209
  flex: 1,
210
+ minWidth: 0,
196
211
  fontSize: textSize.sm,
197
212
  fontFamily: isSelected
198
213
  ? Fonts.montserrat.semiBold
@@ -200,18 +215,19 @@ const layout = isRTL?"row-reverse":"row";
200
215
  color: isSelected
201
216
  ? colors.primary
202
217
  : colors.text.primary,
203
- textAlign: align
218
+ textAlign: align,
204
219
  }}
205
220
  >
206
221
  {option.label}
207
222
  </Text>
208
-
209
223
  {isSelected && (
210
- <Ionicons
211
- name="checkmark"
212
- size={18}
213
- color={colors.primary}
214
- />
224
+ <View style={{ flexShrink: 0 }}>
225
+ <Ionicons
226
+ name="checkmark"
227
+ size={18}
228
+ color={colors.primary}
229
+ />
230
+ </View>
215
231
  )}
216
232
  </TouchableOpacity>
217
233
  );
@@ -222,4 +238,4 @@ const layout = isRTL?"row-reverse":"row";
222
238
  </Modal>
223
239
  </View>
224
240
  );
225
- }
241
+ }
@@ -1,8 +1,15 @@
1
1
  import React from "react";
2
- import { TouchableOpacity, Text, StyleSheet, ActivityIndicator, View, ViewStyle } from "react-native";
2
+ import {
3
+ TouchableOpacity,
4
+ Text,
5
+ StyleSheet,
6
+ ActivityIndicator,
7
+ View,
8
+ ViewStyle,
9
+ } from "react-native";
3
10
  import { Fonts, textSize } from "../../tokens/typography";
4
11
  import { useAppTheme } from "../../context/ThemeContext";
5
- import SharpContainer from "./sharpContainer"
12
+ import SharpContainer from "./sharpContainer";
6
13
 
7
14
  type ButtonProps = {
8
15
  text: string;
@@ -17,21 +24,21 @@ type ButtonProps = {
17
24
  disabled?: boolean;
18
25
  };
19
26
 
20
-
21
27
  export default function SharpButton({
22
28
  text,
23
29
  bgColor = "transparent",
24
30
  textColor,
25
- borderColor,
31
+ borderColor,
26
32
  onPress,
27
33
  fontSize = textSize.md,
28
34
  fontFamily = Fonts.montserrat.semiBold,
29
35
  height = 56,
30
36
  loading,
31
- disabled= false,
37
+ disabled = false,
32
38
  }: ButtonProps) {
33
39
  const { colors } = useAppTheme();
34
40
  const isInactive = loading || disabled;
41
+
35
42
  return (
36
43
  <TouchableOpacity
37
44
  onPress={onPress}
@@ -39,21 +46,31 @@ export default function SharpButton({
39
46
  disabled={isInactive}
40
47
  style={{ opacity: disabled && !loading ? 0.5 : 1 }}
41
48
  >
42
- <SharpContainer height={height} bgColor={bgColor} borderColor={borderColor ?? colors.text.primary}>
43
- <View style={styles.contentContainer}>
44
- {loading ? (
45
- <ActivityIndicator color={textColor ?? colors.text.primary} size="small" />
46
- ) : (
47
- <Text style={{
48
- fontSize,
49
- fontFamily: fontFamily,
50
- color: textColor ?? colors.text.primary,
51
- textAlign: "center",
52
- }}>
53
- {text}
54
- </Text>
55
- )}
56
- </View>
49
+ <SharpContainer
50
+ height={height}
51
+ bgColor={bgColor}
52
+ borderColor={borderColor ?? colors.text.primary}
53
+ >
54
+ <View style={styles.contentContainer}>
55
+ {loading ? (
56
+ <ActivityIndicator
57
+ color={textColor ?? colors.text.primary}
58
+ size="small"
59
+ />
60
+ ) : (
61
+ <Text
62
+ numberOfLines={2}
63
+ style={{
64
+ fontSize,
65
+ fontFamily: fontFamily,
66
+ color: textColor ?? colors.text.primary,
67
+ textAlign: "center",
68
+ }}
69
+ >
70
+ {text}
71
+ </Text>
72
+ )}
73
+ </View>
57
74
  </SharpContainer>
58
75
  </TouchableOpacity>
59
76
  );
@@ -4,58 +4,87 @@ import { useAppTheme } from "../../context/ThemeContext";
4
4
  import { useLanguage } from "../../context/LanguageContext";
5
5
  import { Fonts, textSize } from "../../tokens/typography";
6
6
 
7
- interface TermsPopupProps{
8
- showTerms: boolean;
9
- generalTerms: string[];
10
- onAgree: ()=>void;
11
- title:string;
12
- description: string;
13
- buttonText: string;
7
+ interface TermsPopupProps {
8
+ showTerms: boolean;
9
+ generalTerms: string[];
10
+ onAgree: () => void;
11
+ title: string;
12
+ description: string;
13
+ buttonText: string;
14
14
  }
15
- export default function TermsPopup({showTerms, generalTerms, onAgree, title, description, buttonText}: TermsPopupProps){
16
- const {colors} = useAppTheme();
17
- const {isRTL} = useLanguage();
18
- const align = isRTL?"right":"left";
19
- return (
15
+
16
+ export default function TermsPopup({
17
+ showTerms,
18
+ generalTerms,
19
+ onAgree,
20
+ title,
21
+ description,
22
+ buttonText,
23
+ }: TermsPopupProps) {
24
+ const { colors } = useAppTheme();
25
+ const { isRTL } = useLanguage();
26
+ const align = isRTL ? "right" : "left";
27
+
28
+ return (
20
29
  <CustomPopUp
21
- visible={showTerms}
22
- title={title}
23
- header={
24
- <Text style={{
30
+ visible={showTerms}
31
+ title={title}
32
+ header={
33
+ <Text
34
+ style={{
25
35
  fontFamily: Fonts.montserrat.regular,
26
36
  fontSize: textSize.sm,
27
37
  color: colors.text.secondary,
28
- marginBottom: 4,
29
- textAlign:align
30
- }}>
31
- {description}
32
- </Text>
33
- }
34
- body={
35
- <ScrollView
36
- style={{ maxHeight: 280 }}
37
- scrollEventThrottle={16}
38
- showsVerticalScrollIndicator={false}
39
- >
40
- {generalTerms.map((term: string, i: number) => (
41
- <View key={i} style={{ flexDirection: isRTL ? "row-reverse" : "row", gap: 8, marginBottom: 8 }}>
42
- <Text style={{ color: colors.primary }}>•</Text>
43
- <Text style={{
38
+ marginBottom: 8,
39
+ textAlign: align,
40
+ lineHeight: textSize.sm * 1.4,
41
+ }}
42
+ >
43
+ {description}
44
+ </Text>
45
+ }
46
+ body={
47
+ <ScrollView
48
+ style={{ maxHeight: 320 }} // a bit more room, still short enough
49
+ scrollEventThrottle={16}
50
+ showsVerticalScrollIndicator={false}
51
+ >
52
+ {generalTerms.map((term, i) => (
53
+ <View
54
+ key={i}
55
+ style={{
56
+ flexDirection: isRTL ? "row-reverse" : "row",
57
+ gap: 8,
58
+ marginBottom: 8,
59
+ alignItems: "flex-start",
60
+ }}
61
+ >
62
+ <Text
63
+ style={{
64
+ color: colors.primary,
65
+ lineHeight: textSize.sm * 1.4,
66
+ }}
67
+ >
68
+ •
69
+ </Text>
70
+ <Text
71
+ style={{
44
72
  fontFamily: Fonts.montserrat.regular,
45
73
  fontSize: textSize.sm,
46
74
  color: colors.text.secondary,
47
75
  flex: 1,
48
- lineHeight: 20,
49
- textAlign:align
50
- }}>
51
- {term}
52
- </Text>
53
- </View>
54
- ))}
55
- </ScrollView>
56
- }
57
- agreeText={buttonText}
58
- onAgree={onAgree}
59
- />
60
- )
76
+ lineHeight: textSize.sm * 1.4,
77
+ textAlign: align,
78
+ }}
79
+ >
80
+ {term}
81
+ </Text>
82
+ </View>
83
+ ))}
84
+ </ScrollView>
85
+ }
86
+ agreeText={buttonText}
87
+ onAgree={onAgree}
88
+ />
89
+ );
61
90
  }
@@ -30,54 +30,51 @@ export default function TextArea({
30
30
  showCharCount = false,
31
31
  }: TextAreaProps) {
32
32
  const { colors } = useAppTheme();
33
- const {isRTL} = useLanguage();
33
+ const { isRTL } = useLanguage();
34
34
  const handleChange = (text: string) => {
35
35
  onChangeText(text);
36
36
  onClearError?.();
37
37
  };
38
- const align = isRTL?"right":"left";
38
+ const align = isRTL ? "right" : "left";
39
+
39
40
  return (
40
41
  <View style={{ marginBottom: 16 }}>
41
42
  {label && (
42
43
  <Text
43
- style={{
44
- fontSize: textSize.xs,
45
- fontFamily: Fonts.montserrat.semiBold,
46
- color: colors.text.primary,
47
- marginBottom: 6,
48
- textAlign:align
49
- }}
50
- >
51
- {label}
52
- </Text>
44
+ style={{
45
+ fontSize: textSize.xs,
46
+ fontFamily: Fonts.montserrat.semiBold,
47
+ color: colors.text.primary,
48
+ marginBottom: 6,
49
+ textAlign: align,
50
+ }}
51
+ >
52
+ {label}
53
+ </Text>
53
54
  )}
54
55
 
55
- <TextInput
56
- value={value}
57
- onChangeText={handleChange}
58
- placeholder={placeholder}
59
- multiline
60
- textAlignVertical="top"
61
- maxLength={maxLength}
62
- placeholderTextColor={colors.text.placeholder}
63
- style={{
64
- minHeight,
65
- padding: 14,
66
- backgroundColor: bgColor ?? colors.background.card,
67
- borderWidth: 1.4,
68
- borderColor: error
69
- ? colors.semantic.error
70
- : colors.text.primary,
71
- borderRadius: 12,
72
- fontSize: textSize.sm,
73
- fontFamily: Fonts.montserrat.regular,
74
- color: colors.text.primary,
75
-
76
- // Text and cursor direction
77
- textAlign: isRTL ? "right" : "left",
78
- writingDirection: isRTL ? "rtl" : "ltr",
79
- }}
80
- />
56
+ <TextInput
57
+ value={value}
58
+ onChangeText={handleChange}
59
+ placeholder={placeholder}
60
+ multiline
61
+ textAlignVertical="top"
62
+ maxLength={maxLength}
63
+ placeholderTextColor={colors.text.placeholder}
64
+ style={{
65
+ minHeight,
66
+ padding: 14,
67
+ backgroundColor: bgColor ?? colors.background.card,
68
+ borderWidth: 1.4,
69
+ borderColor: error ? colors.semantic.error : colors.text.primary,
70
+ borderRadius: 12,
71
+ fontSize: textSize.sm,
72
+ fontFamily: Fonts.montserrat.regular,
73
+ color: colors.text.primary,
74
+ textAlign: isRTL ? "right" : "left",
75
+ writingDirection: isRTL ? "rtl" : "ltr",
76
+ }}
77
+ />
81
78
 
82
79
  {showCharCount && (
83
80
  <Text
@@ -92,11 +89,11 @@ const align = isRTL?"right":"left";
92
89
  marginTop: 4,
93
90
  }}
94
91
  >
95
- {maxLength} / {value.length}
92
+ {value.length} / {maxLength}
96
93
  </Text>
97
94
  )}
98
95
 
99
- {error && <ErrorMessage message={error} />}
96
+ {error && <ErrorMessage message={error} position={align} />}
100
97
  </View>
101
98
  );
102
99
  }