@izonnet-web-solution/react-native-date-time-picker-kit 0.0.0-stage → 1.0.1

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.
Files changed (216) hide show
  1. package/DateTimePickerKit.podspec +22 -0
  2. package/LICENSE +20 -0
  3. package/README.md +652 -2
  4. package/android/build.gradle +36 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/datetimepickerkit/DatePickerHelper.kt +185 -0
  7. package/android/src/main/java/com/datetimepickerkit/DateTimePickerHelper.kt +214 -0
  8. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitModule.kt +258 -0
  9. package/android/src/main/java/com/datetimepickerkit/DateTimePickerKitPackage.kt +30 -0
  10. package/android/src/main/java/com/datetimepickerkit/TimePickerHelper.kt +208 -0
  11. package/ios/DateTimePickerKit.h +11 -0
  12. package/ios/DateTimePickerKit.mm +84 -0
  13. package/ios/DateTimePickerModule.swift +474 -0
  14. package/lib/module/NativeDateTimePickerKit.js +5 -0
  15. package/lib/module/NativeDateTimePickerKit.js.map +1 -0
  16. package/lib/module/components/CalendarPicker.js +419 -0
  17. package/lib/module/components/CalendarPicker.js.map +1 -0
  18. package/lib/module/components/ClockPicker.js +273 -0
  19. package/lib/module/components/ClockPicker.js.map +1 -0
  20. package/lib/module/components/DatePicker.js +181 -0
  21. package/lib/module/components/DatePicker.js.map +1 -0
  22. package/lib/module/components/DateRangePicker.js +158 -0
  23. package/lib/module/components/DateRangePicker.js.map +1 -0
  24. package/lib/module/components/DateTimePicker.js +674 -0
  25. package/lib/module/components/DateTimePicker.js.map +1 -0
  26. package/lib/module/components/MonthPicker.js +145 -0
  27. package/lib/module/components/MonthPicker.js.map +1 -0
  28. package/lib/module/components/TimePicker.js +142 -0
  29. package/lib/module/components/TimePicker.js.map +1 -0
  30. package/lib/module/components/TimeSlotPicker.js +118 -0
  31. package/lib/module/components/TimeSlotPicker.js.map +1 -0
  32. package/lib/module/components/WheelPicker.js +159 -0
  33. package/lib/module/components/WheelPicker.js.map +1 -0
  34. package/lib/module/components/YearPicker.js +151 -0
  35. package/lib/module/components/YearPicker.js.map +1 -0
  36. package/lib/module/components/common/ModalWrapper.js +136 -0
  37. package/lib/module/components/common/ModalWrapper.js.map +1 -0
  38. package/lib/module/components/common/PickerHeader.js +82 -0
  39. package/lib/module/components/common/PickerHeader.js.map +1 -0
  40. package/lib/module/components/common/PresetsBar.js +66 -0
  41. package/lib/module/components/common/PresetsBar.js.map +1 -0
  42. package/lib/module/errors/DateTimePickerError.js +12 -0
  43. package/lib/module/errors/DateTimePickerError.js.map +1 -0
  44. package/lib/module/hooks/useDateTimePicker.js +73 -0
  45. package/lib/module/hooks/useDateTimePicker.js.map +1 -0
  46. package/lib/module/index.js +40 -0
  47. package/lib/module/index.js.map +1 -0
  48. package/lib/module/localization/index.js +6 -0
  49. package/lib/module/localization/index.js.map +1 -0
  50. package/lib/module/localization/locales.js +186 -0
  51. package/lib/module/localization/locales.js.map +1 -0
  52. package/lib/module/localization/types.js +2 -0
  53. package/lib/module/localization/types.js.map +1 -0
  54. package/lib/module/localization/useLocale.js +176 -0
  55. package/lib/module/localization/useLocale.js.map +1 -0
  56. package/lib/module/native/NativeDateTimePicker.js +110 -0
  57. package/lib/module/native/NativeDateTimePicker.js.map +1 -0
  58. package/lib/module/package.json +1 -0
  59. package/lib/module/presets/datePresets.js +75 -0
  60. package/lib/module/presets/datePresets.js.map +1 -0
  61. package/lib/module/presets/index.js +4 -0
  62. package/lib/module/presets/index.js.map +1 -0
  63. package/lib/module/slots/index.js +4 -0
  64. package/lib/module/slots/index.js.map +1 -0
  65. package/lib/module/slots/timeSlots.js +59 -0
  66. package/lib/module/slots/timeSlots.js.map +1 -0
  67. package/lib/module/theme/defaultTheme.js +91 -0
  68. package/lib/module/theme/defaultTheme.js.map +1 -0
  69. package/lib/module/theme/index.js +6 -0
  70. package/lib/module/theme/index.js.map +1 -0
  71. package/lib/module/theme/types.js +2 -0
  72. package/lib/module/theme/types.js.map +1 -0
  73. package/lib/module/theme/useTheme.js +81 -0
  74. package/lib/module/theme/useTheme.js.map +1 -0
  75. package/lib/module/types/events.js +4 -0
  76. package/lib/module/types/events.js.map +1 -0
  77. package/lib/module/types/index.js +7 -0
  78. package/lib/module/types/index.js.map +1 -0
  79. package/lib/module/types/native.js +2 -0
  80. package/lib/module/types/native.js.map +1 -0
  81. package/lib/module/types/presentation.js +2 -0
  82. package/lib/module/types/presentation.js.map +1 -0
  83. package/lib/module/types/props.js +4 -0
  84. package/lib/module/types/props.js.map +1 -0
  85. package/lib/module/utils/constants.js +14 -0
  86. package/lib/module/utils/constants.js.map +1 -0
  87. package/lib/module/utils/dateConversion.js +224 -0
  88. package/lib/module/utils/dateConversion.js.map +1 -0
  89. package/lib/module/utils/dateFormatting.js +102 -0
  90. package/lib/module/utils/dateFormatting.js.map +1 -0
  91. package/lib/module/utils/dateValidation.js +161 -0
  92. package/lib/module/utils/dateValidation.js.map +1 -0
  93. package/lib/module/utils/index.js +7 -0
  94. package/lib/module/utils/index.js.map +1 -0
  95. package/lib/typescript/package.json +1 -0
  96. package/lib/typescript/src/NativeDateTimePickerKit.d.ts +17 -0
  97. package/lib/typescript/src/NativeDateTimePickerKit.d.ts.map +1 -0
  98. package/lib/typescript/src/components/CalendarPicker.d.ts +51 -0
  99. package/lib/typescript/src/components/CalendarPicker.d.ts.map +1 -0
  100. package/lib/typescript/src/components/ClockPicker.d.ts +22 -0
  101. package/lib/typescript/src/components/ClockPicker.d.ts.map +1 -0
  102. package/lib/typescript/src/components/DatePicker.d.ts +44 -0
  103. package/lib/typescript/src/components/DatePicker.d.ts.map +1 -0
  104. package/lib/typescript/src/components/DateRangePicker.d.ts +56 -0
  105. package/lib/typescript/src/components/DateRangePicker.d.ts.map +1 -0
  106. package/lib/typescript/src/components/DateTimePicker.d.ts +7 -0
  107. package/lib/typescript/src/components/DateTimePicker.d.ts.map +1 -0
  108. package/lib/typescript/src/components/MonthPicker.d.ts +21 -0
  109. package/lib/typescript/src/components/MonthPicker.d.ts.map +1 -0
  110. package/lib/typescript/src/components/TimePicker.d.ts +31 -0
  111. package/lib/typescript/src/components/TimePicker.d.ts.map +1 -0
  112. package/lib/typescript/src/components/TimeSlotPicker.d.ts +18 -0
  113. package/lib/typescript/src/components/TimeSlotPicker.d.ts.map +1 -0
  114. package/lib/typescript/src/components/WheelPicker.d.ts +17 -0
  115. package/lib/typescript/src/components/WheelPicker.d.ts.map +1 -0
  116. package/lib/typescript/src/components/YearPicker.d.ts +14 -0
  117. package/lib/typescript/src/components/YearPicker.d.ts.map +1 -0
  118. package/lib/typescript/src/components/common/ModalWrapper.d.ts +11 -0
  119. package/lib/typescript/src/components/common/ModalWrapper.d.ts.map +1 -0
  120. package/lib/typescript/src/components/common/PickerHeader.d.ts +13 -0
  121. package/lib/typescript/src/components/common/PickerHeader.d.ts.map +1 -0
  122. package/lib/typescript/src/components/common/PresetsBar.d.ts +12 -0
  123. package/lib/typescript/src/components/common/PresetsBar.d.ts.map +1 -0
  124. package/lib/typescript/src/errors/DateTimePickerError.d.ts +7 -0
  125. package/lib/typescript/src/errors/DateTimePickerError.d.ts.map +1 -0
  126. package/lib/typescript/src/hooks/useDateTimePicker.d.ts +17 -0
  127. package/lib/typescript/src/hooks/useDateTimePicker.d.ts.map +1 -0
  128. package/lib/typescript/src/index.d.ts +23 -0
  129. package/lib/typescript/src/index.d.ts.map +1 -0
  130. package/lib/typescript/src/localization/index.d.ts +4 -0
  131. package/lib/typescript/src/localization/index.d.ts.map +1 -0
  132. package/lib/typescript/src/localization/locales.d.ts +12 -0
  133. package/lib/typescript/src/localization/locales.d.ts.map +1 -0
  134. package/lib/typescript/src/localization/types.d.ts +23 -0
  135. package/lib/typescript/src/localization/types.d.ts.map +1 -0
  136. package/lib/typescript/src/localization/useLocale.d.ts +31 -0
  137. package/lib/typescript/src/localization/useLocale.d.ts.map +1 -0
  138. package/lib/typescript/src/native/NativeDateTimePicker.d.ts +14 -0
  139. package/lib/typescript/src/native/NativeDateTimePicker.d.ts.map +1 -0
  140. package/lib/typescript/src/presets/datePresets.d.ts +8 -0
  141. package/lib/typescript/src/presets/datePresets.d.ts.map +1 -0
  142. package/lib/typescript/src/presets/index.d.ts +2 -0
  143. package/lib/typescript/src/presets/index.d.ts.map +1 -0
  144. package/lib/typescript/src/slots/index.d.ts +2 -0
  145. package/lib/typescript/src/slots/index.d.ts.map +1 -0
  146. package/lib/typescript/src/slots/timeSlots.d.ts +18 -0
  147. package/lib/typescript/src/slots/timeSlots.d.ts.map +1 -0
  148. package/lib/typescript/src/theme/defaultTheme.d.ts +9 -0
  149. package/lib/typescript/src/theme/defaultTheme.d.ts.map +1 -0
  150. package/lib/typescript/src/theme/index.d.ts +4 -0
  151. package/lib/typescript/src/theme/index.d.ts.map +1 -0
  152. package/lib/typescript/src/theme/types.d.ts +76 -0
  153. package/lib/typescript/src/theme/types.d.ts.map +1 -0
  154. package/lib/typescript/src/theme/useTheme.d.ts +4 -0
  155. package/lib/typescript/src/theme/useTheme.d.ts.map +1 -0
  156. package/lib/typescript/src/types/events.d.ts +8 -0
  157. package/lib/typescript/src/types/events.d.ts.map +1 -0
  158. package/lib/typescript/src/types/index.d.ts +5 -0
  159. package/lib/typescript/src/types/index.d.ts.map +1 -0
  160. package/lib/typescript/src/types/native.d.ts +26 -0
  161. package/lib/typescript/src/types/native.d.ts.map +1 -0
  162. package/lib/typescript/src/types/presentation.d.ts +26 -0
  163. package/lib/typescript/src/types/presentation.d.ts.map +1 -0
  164. package/lib/typescript/src/types/props.d.ts +221 -0
  165. package/lib/typescript/src/types/props.d.ts.map +1 -0
  166. package/lib/typescript/src/utils/constants.d.ts +12 -0
  167. package/lib/typescript/src/utils/constants.d.ts.map +1 -0
  168. package/lib/typescript/src/utils/dateConversion.d.ts +46 -0
  169. package/lib/typescript/src/utils/dateConversion.d.ts.map +1 -0
  170. package/lib/typescript/src/utils/dateFormatting.d.ts +8 -0
  171. package/lib/typescript/src/utils/dateFormatting.d.ts.map +1 -0
  172. package/lib/typescript/src/utils/dateValidation.d.ts +46 -0
  173. package/lib/typescript/src/utils/dateValidation.d.ts.map +1 -0
  174. package/lib/typescript/src/utils/index.d.ts +5 -0
  175. package/lib/typescript/src/utils/index.d.ts.map +1 -0
  176. package/package.json +191 -4
  177. package/src/NativeDateTimePickerKit.ts +19 -0
  178. package/src/components/CalendarPicker.tsx +623 -0
  179. package/src/components/ClockPicker.tsx +403 -0
  180. package/src/components/DatePicker.tsx +276 -0
  181. package/src/components/DateRangePicker.tsx +251 -0
  182. package/src/components/DateTimePicker.tsx +1028 -0
  183. package/src/components/MonthPicker.tsx +216 -0
  184. package/src/components/TimePicker.tsx +203 -0
  185. package/src/components/TimeSlotPicker.tsx +163 -0
  186. package/src/components/WheelPicker.tsx +229 -0
  187. package/src/components/YearPicker.tsx +228 -0
  188. package/src/components/common/ModalWrapper.tsx +192 -0
  189. package/src/components/common/PickerHeader.tsx +121 -0
  190. package/src/components/common/PresetsBar.tsx +104 -0
  191. package/src/errors/DateTimePickerError.ts +29 -0
  192. package/src/hooks/useDateTimePicker.ts +100 -0
  193. package/src/index.tsx +92 -0
  194. package/src/localization/index.ts +3 -0
  195. package/src/localization/locales.ts +499 -0
  196. package/src/localization/types.ts +21 -0
  197. package/src/localization/useLocale.ts +197 -0
  198. package/src/native/NativeDateTimePicker.ts +154 -0
  199. package/src/presets/datePresets.ts +97 -0
  200. package/src/presets/index.ts +1 -0
  201. package/src/slots/index.ts +1 -0
  202. package/src/slots/timeSlots.ts +89 -0
  203. package/src/theme/defaultTheme.ts +102 -0
  204. package/src/theme/index.ts +3 -0
  205. package/src/theme/types.ts +82 -0
  206. package/src/theme/useTheme.ts +98 -0
  207. package/src/types/events.ts +8 -0
  208. package/src/types/index.ts +4 -0
  209. package/src/types/native.ts +28 -0
  210. package/src/types/presentation.ts +28 -0
  211. package/src/types/props.ts +291 -0
  212. package/src/utils/constants.ts +15 -0
  213. package/src/utils/dateConversion.ts +273 -0
  214. package/src/utils/dateFormatting.ts +166 -0
  215. package/src/utils/dateValidation.ts +178 -0
  216. package/src/utils/index.ts +4 -0
@@ -0,0 +1,229 @@
1
+ import React, { useCallback, useEffect, useRef } from 'react';
2
+ import {
3
+ FlatList,
4
+ type ListRenderItemInfo,
5
+ type NativeScrollEvent,
6
+ type NativeSyntheticEvent,
7
+ Platform,
8
+ StyleSheet,
9
+ Text,
10
+ TouchableOpacity,
11
+ View,
12
+ } from 'react-native';
13
+ import { useTheme } from '../theme';
14
+ import type { ThemeConfig, ThemeMode } from '../theme/types';
15
+
16
+ export interface WheelPickerItem<T = any> {
17
+ label: string;
18
+ value: T;
19
+ }
20
+
21
+ export interface WheelPickerProps<T = any> {
22
+ items: WheelPickerItem<T>[];
23
+ selectedValue?: T;
24
+ onChange?: (value: T, index: number) => void;
25
+ itemHeight?: number;
26
+ visibleItems?: number; // e.g. 5
27
+ theme?: ThemeMode | ThemeConfig;
28
+ testID?: string;
29
+ }
30
+
31
+ export function WheelPicker<T = any>({
32
+ items,
33
+ selectedValue,
34
+ onChange,
35
+ itemHeight = 44,
36
+ visibleItems = 5,
37
+ theme: propTheme,
38
+ testID,
39
+ }: WheelPickerProps<T>): React.ReactElement {
40
+ const theme = useTheme(propTheme);
41
+ const flatListRef = useRef<FlatList<WheelPickerItem<T>>>(null);
42
+ const isScrollingRef = useRef(false);
43
+
44
+ const halfVisible = Math.floor(visibleItems / 2);
45
+ const totalHeight = itemHeight * visibleItems;
46
+
47
+ const selectedIndex = items.findIndex((it) => it.value === selectedValue);
48
+ const activeIndex = selectedIndex >= 0 ? selectedIndex : 0;
49
+
50
+ // Scroll to position when selectedValue changes externally
51
+ useEffect(() => {
52
+ if (!isScrollingRef.current && flatListRef.current && activeIndex >= 0) {
53
+ try {
54
+ flatListRef.current.scrollToOffset({
55
+ offset: activeIndex * itemHeight,
56
+ animated: false,
57
+ });
58
+ } catch {
59
+ // Fallback for initial render
60
+ }
61
+ }
62
+ }, [activeIndex, itemHeight]);
63
+
64
+ const handleMomentumScrollEnd = useCallback(
65
+ (e: NativeSyntheticEvent<NativeScrollEvent>) => {
66
+ isScrollingRef.current = false;
67
+ const offsetY = e.nativeEvent.contentOffset.y;
68
+ const index = Math.round(offsetY / itemHeight);
69
+ const clampedIndex = Math.max(0, Math.min(items.length - 1, index));
70
+ const item = items[clampedIndex];
71
+ if (item && onChange) {
72
+ onChange(item.value, clampedIndex);
73
+ }
74
+ },
75
+ [itemHeight, items, onChange]
76
+ );
77
+
78
+ const handleScrollBeginDrag = useCallback(() => {
79
+ isScrollingRef.current = true;
80
+ }, []);
81
+
82
+ const handleItemPress = useCallback(
83
+ (index: number) => {
84
+ flatListRef.current?.scrollToOffset({
85
+ offset: index * itemHeight,
86
+ animated: true,
87
+ });
88
+ const item = items[index];
89
+ if (item && onChange) {
90
+ onChange(item.value, index);
91
+ }
92
+ },
93
+ [itemHeight, items, onChange]
94
+ );
95
+
96
+ const renderItem = useCallback(
97
+ ({ item, index }: ListRenderItemInfo<WheelPickerItem<T>>) => {
98
+ const isSelected = index === activeIndex;
99
+ return (
100
+ <TouchableOpacity
101
+ key={`wheel-${index}-${String(item.value)}`}
102
+ accessibilityRole="button"
103
+ accessibilityLabel={item.label}
104
+ accessibilityState={{ selected: isSelected }}
105
+ activeOpacity={0.8}
106
+ onPress={() => handleItemPress(index)}
107
+ style={[
108
+ styles.itemRow,
109
+ {
110
+ height: itemHeight,
111
+ },
112
+ ]}
113
+ >
114
+ <Text
115
+ numberOfLines={1}
116
+ style={[
117
+ styles.itemText,
118
+ {
119
+ color: isSelected ? theme.colors.text : theme.colors.textMuted,
120
+ fontSize: isSelected
121
+ ? theme.typography.fontSizeLarge
122
+ : theme.typography.fontSizeMedium,
123
+ fontWeight: isSelected
124
+ ? theme.typography.fontWeightBold
125
+ : theme.typography.fontWeightRegular,
126
+ transform: isSelected ? [{ scale: 1.05 }] : [{ scale: 0.95 }],
127
+ },
128
+ ]}
129
+ >
130
+ {item.label}
131
+ </Text>
132
+ </TouchableOpacity>
133
+ );
134
+ },
135
+ [activeIndex, handleItemPress, itemHeight, theme]
136
+ );
137
+
138
+ const getItemLayout = useCallback(
139
+ (_: any, index: number) => ({
140
+ length: itemHeight,
141
+ offset: itemHeight * index,
142
+ index,
143
+ }),
144
+ [itemHeight]
145
+ );
146
+
147
+ const keyExtractor = useCallback(
148
+ (item: WheelPickerItem<T>, index: number) =>
149
+ `wheel-${index}-${String(item.value)}`,
150
+ []
151
+ );
152
+
153
+ return (
154
+ <View
155
+ testID={testID}
156
+ style={[
157
+ styles.container,
158
+ {
159
+ height: totalHeight,
160
+ backgroundColor: theme.colors.background,
161
+ },
162
+ ]}
163
+ >
164
+ {/* Center Highlight Indicator */}
165
+ <View
166
+ pointerEvents="none"
167
+ style={[
168
+ styles.selectionIndicator,
169
+ {
170
+ top: halfVisible * itemHeight,
171
+ height: itemHeight,
172
+ borderColor: theme.colors.border,
173
+ backgroundColor: theme.colors.card,
174
+ },
175
+ ]}
176
+ />
177
+
178
+ {/* Optimized FlatList Wheel */}
179
+ <FlatList
180
+ ref={flatListRef}
181
+ data={items}
182
+ renderItem={renderItem}
183
+ keyExtractor={keyExtractor}
184
+ getItemLayout={getItemLayout}
185
+ initialScrollIndex={
186
+ activeIndex >= 0 && activeIndex < items.length ? activeIndex : 0
187
+ }
188
+ showsVerticalScrollIndicator={false}
189
+ snapToInterval={itemHeight}
190
+ snapToAlignment="center"
191
+ decelerationRate="fast"
192
+ removeClippedSubviews={Platform.OS === 'android'}
193
+ maxToRenderPerBatch={visibleItems * 2}
194
+ windowSize={visibleItems + 2}
195
+ onScrollBeginDrag={handleScrollBeginDrag}
196
+ onMomentumScrollEnd={handleMomentumScrollEnd}
197
+ contentContainerStyle={{
198
+ paddingTop: halfVisible * itemHeight,
199
+ paddingBottom: halfVisible * itemHeight,
200
+ }}
201
+ />
202
+ </View>
203
+ );
204
+ }
205
+
206
+ const styles = StyleSheet.create({
207
+ container: {
208
+ position: 'relative',
209
+ overflow: 'hidden',
210
+ width: '100%',
211
+ },
212
+ selectionIndicator: {
213
+ position: 'absolute',
214
+ left: 8,
215
+ right: 8,
216
+ borderTopWidth: 1,
217
+ borderBottomWidth: 1,
218
+ borderRadius: 8,
219
+ zIndex: 0,
220
+ },
221
+ itemRow: {
222
+ justifyContent: 'center',
223
+ alignItems: 'center',
224
+ zIndex: 1,
225
+ },
226
+ itemText: {
227
+ textAlign: 'center',
228
+ },
229
+ });
@@ -0,0 +1,228 @@
1
+ import React, { useCallback, useMemo, useState } from 'react';
2
+ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
3
+ import { useLocale } from '../localization';
4
+ import type { PartialLocaleData } from '../localization/types';
5
+ import { useTheme } from '../theme';
6
+ import type { ThemeConfig, ThemeMode } from '../theme/types';
7
+
8
+ export interface YearPickerProps {
9
+ value?: number | Date;
10
+ onChange?: (year: number) => void;
11
+ minYear?: number;
12
+ maxYear?: number;
13
+ locale?: string | PartialLocaleData;
14
+ theme?: ThemeMode | ThemeConfig;
15
+ testID?: string;
16
+ }
17
+
18
+ const PAGE_SIZE = 12; // 12 years per view (3x4 grid)
19
+
20
+ export const YearPicker: React.FC<YearPickerProps> = ({
21
+ value,
22
+ onChange,
23
+ minYear = 1900,
24
+ maxYear = 2100,
25
+ locale: propLocale,
26
+ theme: propTheme,
27
+ testID,
28
+ }) => {
29
+ const theme = useTheme(propTheme);
30
+ const locale = useLocale(propLocale);
31
+
32
+ const initialYear =
33
+ value instanceof Date
34
+ ? value.getFullYear()
35
+ : typeof value === 'number'
36
+ ? value
37
+ : new Date().getFullYear();
38
+
39
+ const [selectedYear, setSelectedYear] = useState<number>(initialYear);
40
+ // Base start year for current page (e.g. 2020..2031)
41
+ const [pageStartYear, setPageStartYear] = useState<number>(() => {
42
+ return Math.floor(initialYear / PAGE_SIZE) * PAGE_SIZE;
43
+ });
44
+
45
+ const pageYears = useMemo(() => {
46
+ const list: number[] = [];
47
+ for (let i = 0; i < PAGE_SIZE; i++) {
48
+ const yr = pageStartYear + i;
49
+ if (yr >= minYear && yr <= maxYear) {
50
+ list.push(yr);
51
+ }
52
+ }
53
+ return list;
54
+ }, [pageStartYear, minYear, maxYear]);
55
+
56
+ const prevPage = useCallback(() => {
57
+ setPageStartYear((p) => Math.max(minYear, p - PAGE_SIZE));
58
+ }, [minYear]);
59
+
60
+ const nextPage = useCallback(() => {
61
+ setPageStartYear((p) => (p + PAGE_SIZE <= maxYear ? p + PAGE_SIZE : p));
62
+ }, [maxYear]);
63
+
64
+ const handleSelectYear = useCallback(
65
+ (yr: number) => {
66
+ setSelectedYear(yr);
67
+ onChange?.(yr);
68
+ },
69
+ [onChange]
70
+ );
71
+
72
+ const pageRangeLabel = `${pageStartYear} - ${Math.min(
73
+ maxYear,
74
+ pageStartYear + PAGE_SIZE - 1
75
+ )}`;
76
+
77
+ return (
78
+ <View
79
+ testID={testID}
80
+ style={[styles.container, { backgroundColor: theme.colors.background }]}
81
+ >
82
+ {/* Decade Header */}
83
+ <View
84
+ style={[
85
+ styles.headerRow,
86
+ { flexDirection: locale.isRTL ? 'row-reverse' : 'row' },
87
+ ]}
88
+ >
89
+ <TouchableOpacity
90
+ accessibilityRole="button"
91
+ accessibilityLabel="Previous Years"
92
+ onPress={prevPage}
93
+ disabled={pageStartYear <= minYear}
94
+ style={styles.navButton}
95
+ >
96
+ <Text
97
+ style={[
98
+ styles.navArrow,
99
+ {
100
+ color:
101
+ pageStartYear <= minYear
102
+ ? theme.colors.disabledText
103
+ : theme.colors.primary,
104
+ },
105
+ ]}
106
+ >
107
+ {locale.isRTL ? '›' : '‹'}
108
+ </Text>
109
+ </TouchableOpacity>
110
+
111
+ <Text
112
+ style={[
113
+ styles.rangeTitle,
114
+ {
115
+ color: theme.colors.text,
116
+ fontSize: theme.typography.fontSizeLarge,
117
+ fontWeight: theme.typography.fontWeightBold,
118
+ },
119
+ ]}
120
+ >
121
+ {pageRangeLabel}
122
+ </Text>
123
+
124
+ <TouchableOpacity
125
+ accessibilityRole="button"
126
+ accessibilityLabel="Next Years"
127
+ onPress={nextPage}
128
+ disabled={pageStartYear + PAGE_SIZE > maxYear}
129
+ style={styles.navButton}
130
+ >
131
+ <Text
132
+ style={[
133
+ styles.navArrow,
134
+ {
135
+ color:
136
+ pageStartYear + PAGE_SIZE > maxYear
137
+ ? theme.colors.disabledText
138
+ : theme.colors.primary,
139
+ },
140
+ ]}
141
+ >
142
+ {locale.isRTL ? '‹' : '›'}
143
+ </Text>
144
+ </TouchableOpacity>
145
+ </View>
146
+
147
+ {/* 3x4 Years Grid */}
148
+ <View
149
+ style={[
150
+ styles.yearsGrid,
151
+ { flexDirection: locale.isRTL ? 'row-reverse' : 'row' },
152
+ ]}
153
+ >
154
+ {pageYears.map((yr) => {
155
+ const isSelected = selectedYear === yr;
156
+ return (
157
+ <TouchableOpacity
158
+ key={`yr-${yr}`}
159
+ onPress={() => handleSelectYear(yr)}
160
+ style={[
161
+ styles.yearCell,
162
+ isSelected && {
163
+ backgroundColor: theme.colors.selected,
164
+ borderRadius: theme.borderRadius.md,
165
+ },
166
+ ]}
167
+ >
168
+ <Text
169
+ style={[
170
+ styles.yearText,
171
+ {
172
+ color: isSelected
173
+ ? theme.colors.selectedText
174
+ : theme.colors.text,
175
+ fontSize: theme.typography.fontSizeMedium,
176
+ fontWeight: isSelected
177
+ ? theme.typography.fontWeightBold
178
+ : theme.typography.fontWeightRegular,
179
+ },
180
+ ]}
181
+ >
182
+ {yr}
183
+ </Text>
184
+ </TouchableOpacity>
185
+ );
186
+ })}
187
+ </View>
188
+ </View>
189
+ );
190
+ };
191
+
192
+ const styles = StyleSheet.create({
193
+ container: {
194
+ padding: 16,
195
+ },
196
+ headerRow: {
197
+ alignItems: 'center',
198
+ justifyContent: 'space-between',
199
+ marginBottom: 16,
200
+ },
201
+ rangeTitle: {
202
+ textAlign: 'center',
203
+ },
204
+ navButton: {
205
+ width: 36,
206
+ height: 36,
207
+ justifyContent: 'center',
208
+ alignItems: 'center',
209
+ },
210
+ navArrow: {
211
+ fontSize: 24,
212
+ lineHeight: 26,
213
+ },
214
+ yearsGrid: {
215
+ flexWrap: 'wrap',
216
+ justifyContent: 'space-between',
217
+ rowGap: 12,
218
+ },
219
+ yearCell: {
220
+ width: '31%',
221
+ height: 48,
222
+ justifyContent: 'center',
223
+ alignItems: 'center',
224
+ },
225
+ yearText: {
226
+ textAlign: 'center',
227
+ },
228
+ });
@@ -0,0 +1,192 @@
1
+ import React from 'react';
2
+ import {
3
+ KeyboardAvoidingView,
4
+ Modal,
5
+ Platform,
6
+ Pressable,
7
+ SafeAreaView,
8
+ StyleSheet,
9
+ View,
10
+ } from 'react-native';
11
+ import type { ResolvedTheme } from '../../theme';
12
+ import type {
13
+ BaseModalProps,
14
+ PresentationMode,
15
+ } from '../../types/presentation';
16
+
17
+ export interface ModalWrapperProps extends BaseModalProps {
18
+ presentation?: PresentationMode;
19
+ children: React.ReactNode;
20
+ theme: ResolvedTheme;
21
+ isVisible?: boolean;
22
+ }
23
+
24
+ export const ModalWrapper: React.FC<ModalWrapperProps> = ({
25
+ presentation = 'modal',
26
+ visible = false,
27
+ isVisible,
28
+ onClose,
29
+ children,
30
+ theme,
31
+ backdropOpacity,
32
+ animationType,
33
+ showHandle = true,
34
+ closeOnBackdropPress = true,
35
+ }) => {
36
+ const modalVisible = isVisible !== undefined ? isVisible : visible;
37
+ if (presentation === 'inline') {
38
+ return (
39
+ <View
40
+ style={[
41
+ styles.inlineContainer,
42
+ {
43
+ backgroundColor: theme.colors.background,
44
+ borderColor: theme.colors.border,
45
+ borderRadius: theme.borderRadius.lg,
46
+ },
47
+ ]}
48
+ >
49
+ {children}
50
+ </View>
51
+ );
52
+ }
53
+
54
+ const effectiveAnim =
55
+ animationType ||
56
+ (presentation === 'bottom-sheet'
57
+ ? 'slide'
58
+ : presentation === 'fullscreen'
59
+ ? 'slide'
60
+ : 'fade');
61
+
62
+ const overlayBg =
63
+ backdropOpacity !== undefined
64
+ ? `rgba(0, 0, 0, ${backdropOpacity})`
65
+ : theme.colors.modalOverlay;
66
+
67
+ const isBottomSheet = presentation === 'bottom-sheet';
68
+ const isFullscreen = presentation === 'fullscreen';
69
+
70
+ return (
71
+ <Modal
72
+ transparent={!isFullscreen}
73
+ visible={modalVisible}
74
+ animationType={effectiveAnim}
75
+ onRequestClose={onClose}
76
+ statusBarTranslucent
77
+ >
78
+ <KeyboardAvoidingView
79
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
80
+ style={styles.keyboardAvoid}
81
+ >
82
+ {isFullscreen ? (
83
+ <SafeAreaView
84
+ style={[
85
+ styles.fullscreenContainer,
86
+ { backgroundColor: theme.colors.background },
87
+ ]}
88
+ >
89
+ {children}
90
+ </SafeAreaView>
91
+ ) : (
92
+ <View style={styles.modalBackdrop}>
93
+ <Pressable
94
+ style={[StyleSheet.absoluteFill, { backgroundColor: overlayBg }]}
95
+ onPress={closeOnBackdropPress ? onClose : undefined}
96
+ />
97
+
98
+ <View
99
+ style={[
100
+ isBottomSheet
101
+ ? styles.bottomSheetContainer
102
+ : styles.centerModalContainer,
103
+ {
104
+ backgroundColor: theme.colors.modalBackground,
105
+ borderColor: theme.colors.border,
106
+ borderRadius: isBottomSheet
107
+ ? theme.borderRadius.lg
108
+ : theme.borderRadius.lg,
109
+ borderBottomLeftRadius: isBottomSheet
110
+ ? 0
111
+ : theme.borderRadius.lg,
112
+ borderBottomRightRadius: isBottomSheet
113
+ ? 0
114
+ : theme.borderRadius.lg,
115
+ },
116
+ ]}
117
+ >
118
+ {isBottomSheet && showHandle && (
119
+ <View style={styles.handleContainer}>
120
+ <View
121
+ style={[
122
+ styles.handleBar,
123
+ { backgroundColor: theme.colors.modalHandle },
124
+ ]}
125
+ />
126
+ </View>
127
+ )}
128
+ {children}
129
+ {isBottomSheet && (
130
+ <SafeAreaView
131
+ style={{ backgroundColor: theme.colors.modalBackground }}
132
+ />
133
+ )}
134
+ </View>
135
+ </View>
136
+ )}
137
+ </KeyboardAvoidingView>
138
+ </Modal>
139
+ );
140
+ };
141
+
142
+ const styles = StyleSheet.create({
143
+ inlineContainer: {
144
+ borderWidth: 1,
145
+ overflow: 'hidden',
146
+ },
147
+ keyboardAvoid: {
148
+ flex: 1,
149
+ },
150
+ modalBackdrop: {
151
+ flex: 1,
152
+ justifyContent: 'center',
153
+ alignItems: 'center',
154
+ },
155
+ centerModalContainer: {
156
+ width: '90%',
157
+ maxWidth: 420,
158
+ borderWidth: StyleSheet.hairlineWidth,
159
+ overflow: 'hidden',
160
+ shadowColor: '#000',
161
+ shadowOffset: { width: 0, height: 8 },
162
+ shadowOpacity: 0.25,
163
+ shadowRadius: 16,
164
+ elevation: 10,
165
+ },
166
+ bottomSheetContainer: {
167
+ position: 'absolute',
168
+ bottom: 0,
169
+ left: 0,
170
+ right: 0,
171
+ borderTopWidth: StyleSheet.hairlineWidth,
172
+ shadowColor: '#000',
173
+ shadowOffset: { width: 0, height: -4 },
174
+ shadowOpacity: 0.15,
175
+ shadowRadius: 12,
176
+ elevation: 12,
177
+ },
178
+ fullscreenContainer: {
179
+ flex: 1,
180
+ },
181
+ handleContainer: {
182
+ width: '100%',
183
+ height: 20,
184
+ justifyContent: 'center',
185
+ alignItems: 'center',
186
+ },
187
+ handleBar: {
188
+ width: 36,
189
+ height: 4,
190
+ borderRadius: 2,
191
+ },
192
+ });