react-native-fancy-date-picker 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized to the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control
17
+ with that entity. For the purposes of this definition, "control" means
18
+ (i) the power, direct or indirect, to cause the direction or management
19
+ of such entity, whether by contract or otherwise, or (ii) ownership of
20
+ fifty percent (50%) or more of the outstanding shares, or (iii)
21
+ beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source,
28
+ and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but not
32
+ limited to compiled object code, generated documentation, and
33
+ conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright
37
+ notice that is included in or attached to the work (an example is
38
+ provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions to
50
+ that Work or Derivative Works thereof, that is intentionally submitted
51
+ to Licensor for inclusion in the Work by the copyright owner or by an
52
+ individual or Legal Entity authorized to submit on behalf of the
53
+ copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent to
55
+ the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable by
79
+ such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
84
+ Contribution incorporated within the Work constitutes direct or
85
+ contributory patent infringement, then any patent licenses granted to
86
+ You under this License for that Work shall terminate as of the date
87
+ such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing the
166
+ Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf of
171
+ any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2025] [timekeeper]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # react-native-fancy-date-picker
2
+
3
+ A 3D wheel-style date and time picker for React Native.
4
+
5
+ ![Demo](./demo.gif)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install react-native-fancy-date-picker
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import React, { useState } from "react";
17
+ import { View, Text } from "react-native";
18
+ import { FancyDatePicker } from "react-native-fancy-date-picker";
19
+
20
+ export default function Example() {
21
+ const [value, setValue] = useState("");
22
+
23
+ return (
24
+ <View>
25
+ <FancyDatePicker
26
+ onDateChange={(date) => {
27
+ setValue(
28
+ `${date.month} ${date.day}, ${date.year} ${date.hour}:${date.minute} ${date.ampm}`,
29
+ );
30
+ }}
31
+ showTime
32
+ itemTextStyle={{ color: "#00ff00", fontSize: 20 }}
33
+ containerStyle={{ backgroundColor: "#000" }}
34
+ />
35
+ <Text>{value}</Text>
36
+ </View>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ## Props
42
+
43
+ | Prop | Type | Required | Description |
44
+ |------|------|----------|-------------|
45
+ | `onDateChange` | `(date) => void` | Yes | Callback when date/time changes |
46
+ | `initialDate` | `Date` | No | Initial date to display |
47
+ | `showTime` | `boolean` | No | Show time picker (default: `true`) |
48
+ | `containerStyle` | `ViewStyle` | No | Style for main container |
49
+ | `pickerRowStyle` | `ViewStyle` | No | Style for date picker row |
50
+ | `timePickerRowStyle` | `ViewStyle` | No | Style for time picker row |
51
+ | `itemTextStyle` | `TextStyle` | No | Style for text in scrollers |
52
+ | `timeSeparatorStyle` | `TextStyle` | No | Style for ":" separator |
53
+ | `selectionHighlightStyle` | `ViewStyle` | No | Style for selection highlight |
54
+
55
+ ## Peer dependencies
56
+
57
+ This package expects these to be installed in the app:
58
+
59
+ - react
60
+ - react-native
61
+ - react-native-reanimated
62
+ - react-native-gesture-handler
63
+ - react-native-reanimated-carousel
64
+ - expo-haptics (optional)
65
+
66
+ ## Build
67
+
68
+ ```bash
69
+ npm run build
70
+ ```
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { ViewStyle, TextStyle } from "react-native";
3
+ export interface FancyDatePickerProps {
4
+ onDateChange: (date: {
5
+ day: string;
6
+ month: string;
7
+ year: string;
8
+ hour: string;
9
+ minute: string;
10
+ ampm: string;
11
+ }) => void;
12
+ initialDate?: Date;
13
+ showTime?: boolean;
14
+ containerStyle?: ViewStyle;
15
+ pickerRowStyle?: ViewStyle;
16
+ timePickerRowStyle?: ViewStyle;
17
+ itemTextStyle?: TextStyle;
18
+ timeSeparatorStyle?: TextStyle;
19
+ selectionHighlightStyle?: ViewStyle;
20
+ }
21
+ declare const FancyDatePicker: ({ onDateChange, initialDate, showTime, containerStyle, pickerRowStyle, timePickerRowStyle, itemTextStyle, timeSeparatorStyle, selectionHighlightStyle, }: FancyDatePickerProps) => React.JSX.Element;
22
+ export default FancyDatePicker;
23
+ //# sourceMappingURL=FancyDatePicker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FancyDatePicker.d.ts","sourceRoot":"","sources":["../src/FancyDatePicker.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAC1E,OAAO,EAML,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AA8LtB,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,CAAC,IAAI,EAAE;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,MAAM,CAAC;KACd,KAAK,IAAI,CAAC;IACX,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,kBAAkB,CAAC,EAAE,SAAS,CAAC;IAC/B,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,kBAAkB,CAAC,EAAE,SAAS,CAAC;IAC/B,uBAAuB,CAAC,EAAE,SAAS,CAAC;CACrC;AA2BD,QAAA,MAAM,eAAe,GAAI,0JAUtB,oBAAoB,sBAyKtB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,317 @@
1
+ const Haptics = (() => {
2
+ try {
3
+ return require("expo-haptics");
4
+ }
5
+ catch {
6
+ return null;
7
+ }
8
+ })();
9
+ import React, { memo, useEffect, useMemo, useRef, useState } from "react";
10
+ import { Dimensions, Platform, StyleSheet, Text, View, } from "react-native";
11
+ import Animated, { Extrapolation, interpolate, useAnimatedStyle, } from "react-native-reanimated";
12
+ import Carousel from "react-native-reanimated-carousel";
13
+ const { width: SCREEN_WIDTH } = Dimensions.get("window");
14
+ const ITEM_HEIGHT = 48;
15
+ const VISIBLE_ITEMS = 3;
16
+ const PICKER_HEIGHT = ITEM_HEIGHT * VISIBLE_ITEMS;
17
+ const PICKER_WIDTH = SCREEN_WIDTH * 0.92;
18
+ // Calculated widths based on flex ratios (1.5 : 0.7 : 1)
19
+ const TOTAL_FLEX = 3.2;
20
+ const MONTH_WIDTH = (PICKER_WIDTH * 1.5) / TOTAL_FLEX;
21
+ const DAY_WIDTH = (PICKER_WIDTH * 0.7) / TOTAL_FLEX;
22
+ const YEAR_WIDTH = (PICKER_WIDTH * 1.0) / TOTAL_FLEX;
23
+ // Time picker widths
24
+ const TIME_PICKER_WIDTH = SCREEN_WIDTH * 0.6;
25
+ const TIME_SEPARATOR_WIDTH = 12;
26
+ const TIME_WHEEL_WIDTH = TIME_PICKER_WIDTH - TIME_SEPARATOR_WIDTH;
27
+ const TIME_TOTAL_FLEX = 3;
28
+ const HOUR_WIDTH = (TIME_WHEEL_WIDTH * 1) / TIME_TOTAL_FLEX;
29
+ const MINUTE_WIDTH = (TIME_WHEEL_WIDTH * 1) / TIME_TOTAL_FLEX;
30
+ const AMPM_WIDTH = (TIME_WHEEL_WIDTH * 1) / TIME_TOTAL_FLEX;
31
+ // Carousel wheel item
32
+ const WheelItem = memo(({ item, animationValue, textStyle, }) => {
33
+ const animatedStyles = useAnimatedStyle(() => {
34
+ // Fisheye scale - center is largest, edges shrink significantly
35
+ const scale = interpolate(animationValue.value, [-3, -2, -1, 0, 1, 2, 3], [0.25, 0.5, 0.75, 1, 0.75, 0.5, 0.25], Extrapolation.CLAMP);
36
+ // Opacity falloff for depth
37
+ const opacity = interpolate(animationValue.value, [-2, -1, 0, 1, 2], [0.15, 0.4, 1, 0.4, 0.15], Extrapolation.CLAMP);
38
+ // 3D cylinder rotation effect
39
+ const rotateX = interpolate(animationValue.value, [-1, 0, 1], [30, 0, -30], Extrapolation.CLAMP);
40
+ // Vertical displacement for curved surface
41
+ const translateY = interpolate(animationValue.value, [-2, 0, 2], [6, 0, -6], Extrapolation.CLAMP);
42
+ return {
43
+ transform: [
44
+ { perspective: 500 },
45
+ { rotateX: `${rotateX}deg` },
46
+ { scale },
47
+ { translateY },
48
+ ],
49
+ opacity,
50
+ };
51
+ });
52
+ return (<Animated.View style={[styles.item, animatedStyles]}>
53
+ <Text style={[styles.itemText, textStyle]}>{item}</Text>
54
+ </Animated.View>);
55
+ });
56
+ WheelItem.displayName = "WheelItem";
57
+ const WheelPicker = React.forwardRef(({ data, selectedIndex, onSelect, width, syncOnChange = true, textStyle }, ref) => {
58
+ const carouselRef = useRef(null);
59
+ const isScrolling = useRef(false);
60
+ const shouldLoop = data.length > 2;
61
+ const safeIndex = Math.max(0, Math.min(selectedIndex, data.length - 1));
62
+ const isFirstRender = useRef(true);
63
+ // Expose ref
64
+ React.useImperativeHandle(ref, () => carouselRef.current);
65
+ // Sync selectedIndex changes from parent (e.g. date clamping)
66
+ useEffect(() => {
67
+ if (!syncOnChange) {
68
+ return;
69
+ }
70
+ if (isFirstRender.current) {
71
+ isFirstRender.current = false;
72
+ return;
73
+ }
74
+ if (carouselRef.current && !isScrolling.current) {
75
+ carouselRef.current.scrollTo({ index: safeIndex, animated: true });
76
+ }
77
+ }, [safeIndex, syncOnChange]);
78
+ return (<View style={[styles.wheelContainer, { width }]}>
79
+ <View style={styles.gradientTop} pointerEvents="none"/>
80
+ <Carousel ref={carouselRef} data={data} width={width} height={ITEM_HEIGHT} style={{
81
+ width: width,
82
+ height: PICKER_HEIGHT,
83
+ justifyContent: "center",
84
+ alignItems: "center",
85
+ }} vertical loop={shouldLoop} windowSize={shouldLoop ? 5 : Math.max(1, data.length)} defaultIndex={safeIndex} pagingEnabled snapEnabled onProgressChange={() => {
86
+ isScrolling.current = true;
87
+ }} onSnapToItem={(index) => {
88
+ var _a;
89
+ if (data[index] !== undefined) {
90
+ // Only trigger onSelect if index actually changed to avoid loop
91
+ if (index !== selectedIndex) {
92
+ onSelect(data[index], index);
93
+ if (Platform.OS !== "web") {
94
+ const style = (_a = Haptics === null || Haptics === void 0 ? void 0 : Haptics.ImpactFeedbackStyle) === null || _a === void 0 ? void 0 : _a.Light;
95
+ if ((Haptics === null || Haptics === void 0 ? void 0 : Haptics.impactAsync) && style !== undefined) {
96
+ Haptics.impactAsync(style);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }} renderItem={({ item, animationValue, }) => (<WheelItem item={item} animationValue={animationValue} textStyle={textStyle}/>)}/>
102
+ <View style={styles.gradientBottom} pointerEvents="none"/>
103
+ </View>);
104
+ });
105
+ WheelPicker.displayName = "WheelPicker";
106
+ const MONTHS = [
107
+ "January",
108
+ "February",
109
+ "March",
110
+ "April",
111
+ "May",
112
+ "June",
113
+ "July",
114
+ "August",
115
+ "September",
116
+ "October",
117
+ "November",
118
+ "December",
119
+ ];
120
+ const generateDays = () => Array.from({ length: 31 }, (_, i) => String(i + 1).padStart(2, "0"));
121
+ const generateYears = (start, end) => Array.from({ length: end - start + 1 }, (_, i) => String(start + i));
122
+ const generateHours = () => Array.from({ length: 12 }, (_, i) => String(i + 1).padStart(2, "0"));
123
+ const generateMinutes = () => Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
124
+ const AMPM = ["AM", "PM"];
125
+ const FancyDatePicker = ({ onDateChange, initialDate, showTime = true, containerStyle, pickerRowStyle, timePickerRowStyle, itemTextStyle, timeSeparatorStyle, selectionHighlightStyle, }) => {
126
+ const didInitRef = useRef(false);
127
+ const days = useMemo(() => generateDays(), []);
128
+ const years = useMemo(() => generateYears(1920, 2100), []);
129
+ const hours = useMemo(() => generateHours(), []);
130
+ const minutes = useMemo(() => generateMinutes(), []);
131
+ const baseDate = useMemo(() => initialDate || new Date(), [initialDate]);
132
+ const [selectedDay, setSelectedDay] = useState(baseDate.getDate() - 1);
133
+ const [selectedMonth, setSelectedMonth] = useState(baseDate.getMonth());
134
+ const [selectedYear, setSelectedYear] = useState(years.indexOf(String(baseDate.getFullYear())));
135
+ // Time state
136
+ const initialHour = baseDate.getHours();
137
+ const [selectedHour, setSelectedHour] = useState(initialHour === 0
138
+ ? 11
139
+ : initialHour > 12
140
+ ? initialHour - 13
141
+ : initialHour - 1);
142
+ const [selectedMinute, setSelectedMinute] = useState(baseDate.getMinutes());
143
+ const [selectedAmPm, setSelectedAmPm] = useState(initialHour >= 12 ? 1 : 0);
144
+ const dayRef = useRef(null);
145
+ const monthRef = useRef(null);
146
+ const yearRef = useRef(null);
147
+ const hourRef = useRef(null);
148
+ const minuteRef = useRef(null);
149
+ const ampmRef = useRef(null);
150
+ // Sync state when initialDate changes
151
+ useEffect(() => {
152
+ if (!initialDate && !didInitRef.current) {
153
+ didInitRef.current = true;
154
+ return;
155
+ }
156
+ setSelectedDay(baseDate.getDate() - 1);
157
+ setSelectedMonth(baseDate.getMonth());
158
+ setSelectedYear(years.indexOf(String(baseDate.getFullYear())));
159
+ const initialHour = baseDate.getHours();
160
+ setSelectedHour(initialHour === 0
161
+ ? 11
162
+ : initialHour > 12
163
+ ? initialHour - 13
164
+ : initialHour - 1);
165
+ setSelectedMinute(baseDate.getMinutes());
166
+ setSelectedAmPm(initialHour >= 12 ? 1 : 0);
167
+ }, [initialDate, baseDate, years]);
168
+ // Get max days for selected month/year
169
+ const maxDays = useMemo(() => {
170
+ const year = parseInt(years[selectedYear] || String(baseDate.getFullYear()));
171
+ const month = selectedMonth;
172
+ return new Date(year, month + 1, 0).getDate();
173
+ }, [selectedMonth, selectedYear, years, baseDate]);
174
+ // Adjust day if it exceeds max days for the month
175
+ useEffect(() => {
176
+ if (selectedDay >= maxDays) {
177
+ setSelectedDay(maxDays - 1);
178
+ }
179
+ }, [maxDays, selectedDay]);
180
+ useEffect(() => {
181
+ onDateChange({
182
+ day: days[selectedDay] || "01",
183
+ month: MONTHS[selectedMonth] || "January",
184
+ year: years[selectedYear] || String(baseDate.getFullYear()),
185
+ hour: hours[selectedHour] || "12",
186
+ minute: minutes[selectedMinute] || "00",
187
+ ampm: AMPM[selectedAmPm] || "AM",
188
+ });
189
+ }, [
190
+ selectedDay,
191
+ selectedMonth,
192
+ selectedYear,
193
+ selectedHour,
194
+ selectedMinute,
195
+ selectedAmPm,
196
+ onDateChange,
197
+ ]);
198
+ const visibleDays = useMemo(() => days.slice(0, maxDays), [days, maxDays]);
199
+ return (<View style={[styles.container, containerStyle]}>
200
+ <View style={[styles.pickerRow, pickerRowStyle]}>
201
+ {/* Single unified selection highlight */}
202
+ <View style={styles.selectionOverlay} pointerEvents="none">
203
+ <View style={[styles.selectionHighlight, selectionHighlightStyle]}/>
204
+ </View>
205
+ <WheelPicker ref={monthRef} data={MONTHS} selectedIndex={selectedMonth} onSelect={(_, index) => setSelectedMonth(index)} width={MONTH_WIDTH} textStyle={itemTextStyle}/>
206
+ <View style={styles.separator}/>
207
+ <WheelPicker ref={dayRef} data={visibleDays} selectedIndex={Math.min(selectedDay, maxDays - 1)} onSelect={(_, index) => setSelectedDay(index)} width={DAY_WIDTH} textStyle={itemTextStyle}/>
208
+ <View style={styles.separator}/>
209
+ <WheelPicker ref={yearRef} data={years} selectedIndex={selectedYear} onSelect={(_, index) => setSelectedYear(index)} width={YEAR_WIDTH} textStyle={itemTextStyle}/>
210
+ </View>
211
+
212
+ {/* Time Picker */}
213
+ {showTime && (<View style={[styles.timePickerRow, timePickerRowStyle]}>
214
+ {/* Single unified selection highlight */}
215
+ <View style={styles.selectionOverlay} pointerEvents="none">
216
+ <View style={[styles.selectionHighlight, selectionHighlightStyle]}/>
217
+ </View>
218
+ <WheelPicker ref={hourRef} data={hours} selectedIndex={selectedHour} onSelect={(_, index) => setSelectedHour(index)} width={HOUR_WIDTH} syncOnChange={false} textStyle={itemTextStyle}/>
219
+ <Text style={[styles.timeSeparator, timeSeparatorStyle]}>:</Text>
220
+ <WheelPicker ref={minuteRef} data={minutes} selectedIndex={selectedMinute} onSelect={(_, index) => setSelectedMinute(index)} width={MINUTE_WIDTH} syncOnChange={false} textStyle={itemTextStyle}/>
221
+ <WheelPicker ref={ampmRef} data={AMPM} selectedIndex={selectedAmPm} onSelect={(_, index) => setSelectedAmPm(index)} width={AMPM_WIDTH} syncOnChange={false} textStyle={itemTextStyle}/>
222
+ </View>)}
223
+ </View>);
224
+ };
225
+ export default FancyDatePicker;
226
+ const styles = StyleSheet.create({
227
+ container: {
228
+ alignItems: "center",
229
+ justifyContent: "center",
230
+ // paddingVertical: 20,
231
+ },
232
+ pickerRow: {
233
+ flexDirection: "row",
234
+ alignItems: "center",
235
+ justifyContent: "center",
236
+ width: PICKER_WIDTH,
237
+ height: PICKER_HEIGHT,
238
+ // backgroundColor: "rgba(30, 30, 35, 0.95)",
239
+ borderRadius: 15,
240
+ overflow: "hidden",
241
+ borderWidth: 0,
242
+ borderColor: "rgba(255, 255, 255, 0)",
243
+ // shadowColor: "#000",
244
+ // shadowOffset: { width: 0, height: 8 },
245
+ },
246
+ timePickerRow: {
247
+ marginTop: 14,
248
+ flexDirection: "row",
249
+ alignItems: "center",
250
+ justifyContent: "center",
251
+ width: TIME_PICKER_WIDTH,
252
+ height: PICKER_HEIGHT,
253
+ borderRadius: 15,
254
+ overflow: "hidden",
255
+ },
256
+ wheelContainer: {
257
+ height: PICKER_HEIGHT,
258
+ justifyContent: "center",
259
+ alignItems: "center",
260
+ },
261
+ item: {
262
+ height: ITEM_HEIGHT,
263
+ justifyContent: "center",
264
+ alignItems: "center",
265
+ },
266
+ itemText: {
267
+ color: "#ffffff",
268
+ fontSize: 18,
269
+ fontWeight: "600",
270
+ },
271
+ separator: {
272
+ width: 6,
273
+ },
274
+ timeSeparator: {
275
+ color: "#ffffff",
276
+ fontSize: 22,
277
+ fontWeight: "700",
278
+ marginHorizontal: 6,
279
+ },
280
+ selectionOverlay: {
281
+ position: "absolute",
282
+ top: ITEM_HEIGHT,
283
+ left: 0,
284
+ right: 0,
285
+ height: ITEM_HEIGHT,
286
+ alignItems: "center",
287
+ justifyContent: "center",
288
+ zIndex: 1,
289
+ },
290
+ selectionHighlight: {
291
+ width: "100%",
292
+ height: "100%",
293
+ backgroundColor: "rgba(255,255,255,0.08)",
294
+ borderTopWidth: 1,
295
+ borderBottomWidth: 1,
296
+ borderColor: "rgba(255,255,255,0.18)",
297
+ },
298
+ gradientTop: {
299
+ position: "absolute",
300
+ top: 0,
301
+ left: 0,
302
+ right: 0,
303
+ height: ITEM_HEIGHT,
304
+ backgroundColor: "rgba(0,0,0,0.45)",
305
+ zIndex: 2,
306
+ },
307
+ gradientBottom: {
308
+ position: "absolute",
309
+ bottom: 0,
310
+ left: 0,
311
+ right: 0,
312
+ height: ITEM_HEIGHT,
313
+ backgroundColor: "rgba(0,0,0,0.45)",
314
+ zIndex: 2,
315
+ },
316
+ });
317
+ //# sourceMappingURL=FancyDatePicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FancyDatePicker.js","sourceRo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;QACR,MAAM,EAAE,WAAW;QACnB,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;QACxB,MAAM,EAAE,CAAC;KACV;IACD,kBAAkB,EAAE;QAClB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,eAAe,EAAE,wBAAwB;QACzC,cAAc,EAAE,CAAC;QACjB,iBAAiB,EAAE,CAAC;QACpB,WAAW,EAAE,wBAAwB;KACtC;IACD,WAAW,EAAE;QACX,QAAQ,EAAE,UAAU;QACpB,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,WAAW;QACnB,eAAe,EAAE,kBAAkB;QACnC,MAAM,EAAE,CAAC;KACV;IACD,cAAc,EAAE;QACd,QAAQ,EAAE,UAAU;QACpB,MAAM,EAAE,CAAC;QACT,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,WAAW;QACnB,eAAe,EAAE,kBAAkB;QACnC,MAAM,EAAE,CAAC;KACV;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { default as FancyDatePicker } from "./FancyDatePicker";
2
+ export type { FancyDatePickerProps } from "./FancyDatePicker";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as FancyDatePicker } from "./FancyDatePicker";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "react-native-fancy-date-picker",
3
+ "version": "0.1.0",
4
+ "description": "A 3D wheel-style date and time picker for React Native.",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "react-native": "src/index.ts",
9
+ "source": "src/index.ts",
10
+ "files": [
11
+ "dist",
12
+ "src",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "prepare": "npm run build"
19
+ },
20
+ "peerDependencies": {
21
+ "expo-haptics": "*",
22
+ "react": "*",
23
+ "react-native": "*",
24
+ "react-native-gesture-handler": ">=2.0.0",
25
+ "react-native-reanimated": ">=3.0.0",
26
+ "react-native-reanimated-carousel": ">=3.0.0"
27
+ },
28
+ "peerDependenciesMeta": {
29
+ "expo-haptics": {
30
+ "optional": true
31
+ }
32
+ },
33
+ "devDependencies": {
34
+ "@types/react": "^19.0.0",
35
+ "expo-haptics": "^13.0.1",
36
+ "react-native": "^0.83.1",
37
+ "react-native-gesture-handler": "^2.20.2",
38
+ "react-native-reanimated": "^4.2.1",
39
+ "react-native-reanimated-carousel": "^4.0.3",
40
+ "typescript": "^5.0.0"
41
+ },
42
+ "keywords": [
43
+ "react-native",
44
+ "date-picker",
45
+ "time-picker",
46
+ "wheel",
47
+ "expo"
48
+ ]
49
+ }
@@ -0,0 +1,529 @@
1
+ type HapticsModule = {
2
+ impactAsync?: (style: number) => Promise<void> | void;
3
+ ImpactFeedbackStyle?: { Light: number };
4
+ };
5
+
6
+ const Haptics: HapticsModule | null = (() => {
7
+ try {
8
+ return require("expo-haptics");
9
+ } catch {
10
+ return null;
11
+ }
12
+ })();
13
+ import React, { memo, useEffect, useMemo, useRef, useState } from "react";
14
+ import {
15
+ Dimensions,
16
+ Platform,
17
+ StyleSheet,
18
+ Text,
19
+ View,
20
+ ViewStyle,
21
+ TextStyle,
22
+ } from "react-native";
23
+ import Animated, {
24
+ Extrapolation,
25
+ interpolate,
26
+ SharedValue,
27
+ useAnimatedStyle,
28
+ } from "react-native-reanimated";
29
+ import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
30
+
31
+ const { width: SCREEN_WIDTH } = Dimensions.get("window");
32
+ const ITEM_HEIGHT = 48;
33
+ const VISIBLE_ITEMS = 3;
34
+ const PICKER_HEIGHT = ITEM_HEIGHT * VISIBLE_ITEMS;
35
+ const PICKER_WIDTH = SCREEN_WIDTH * 0.92;
36
+
37
+ // Calculated widths based on flex ratios (1.5 : 0.7 : 1)
38
+ const TOTAL_FLEX = 3.2;
39
+ const MONTH_WIDTH = (PICKER_WIDTH * 1.5) / TOTAL_FLEX;
40
+ const DAY_WIDTH = (PICKER_WIDTH * 0.7) / TOTAL_FLEX;
41
+ const YEAR_WIDTH = (PICKER_WIDTH * 1.0) / TOTAL_FLEX;
42
+
43
+ // Time picker widths
44
+ const TIME_PICKER_WIDTH = SCREEN_WIDTH * 0.6;
45
+ const TIME_SEPARATOR_WIDTH = 12;
46
+ const TIME_WHEEL_WIDTH = TIME_PICKER_WIDTH - TIME_SEPARATOR_WIDTH;
47
+ const TIME_TOTAL_FLEX = 3;
48
+ const HOUR_WIDTH = (TIME_WHEEL_WIDTH * 1) / TIME_TOTAL_FLEX;
49
+ const MINUTE_WIDTH = (TIME_WHEEL_WIDTH * 1) / TIME_TOTAL_FLEX;
50
+ const AMPM_WIDTH = (TIME_WHEEL_WIDTH * 1) / TIME_TOTAL_FLEX;
51
+
52
+ // Carousel wheel item
53
+ const WheelItem = memo(
54
+ ({
55
+ item,
56
+ animationValue,
57
+ textStyle,
58
+ }: {
59
+ item: string;
60
+ animationValue: SharedValue<number>;
61
+ textStyle?: TextStyle;
62
+ }) => {
63
+ const animatedStyles = useAnimatedStyle(() => {
64
+ // Fisheye scale - center is largest, edges shrink significantly
65
+ const scale = interpolate(
66
+ animationValue.value,
67
+ [-3, -2, -1, 0, 1, 2, 3],
68
+ [0.25, 0.5, 0.75, 1, 0.75, 0.5, 0.25],
69
+ Extrapolation.CLAMP,
70
+ );
71
+ // Opacity falloff for depth
72
+ const opacity = interpolate(
73
+ animationValue.value,
74
+ [-2, -1, 0, 1, 2],
75
+ [0.15, 0.4, 1, 0.4, 0.15],
76
+ Extrapolation.CLAMP,
77
+ );
78
+ // 3D cylinder rotation effect
79
+ const rotateX = interpolate(
80
+ animationValue.value,
81
+ [-1, 0, 1],
82
+ [30, 0, -30],
83
+ Extrapolation.CLAMP,
84
+ );
85
+ // Vertical displacement for curved surface
86
+ const translateY = interpolate(
87
+ animationValue.value,
88
+ [-2, 0, 2],
89
+ [6, 0, -6],
90
+ Extrapolation.CLAMP,
91
+ );
92
+ return {
93
+ transform: [
94
+ { perspective: 500 },
95
+ { rotateX: `${rotateX}deg` },
96
+ { scale },
97
+ { translateY },
98
+ ],
99
+ opacity,
100
+ };
101
+ });
102
+
103
+ return (
104
+ <Animated.View style={[styles.item, animatedStyles]}>
105
+ <Text style={[styles.itemText, textStyle]}>{item}</Text>
106
+ </Animated.View>
107
+ );
108
+ },
109
+ );
110
+ WheelItem.displayName = "WheelItem";
111
+
112
+ // WheelPicker using reanimated-carousel
113
+ interface WheelPickerProps {
114
+ data: string[];
115
+ selectedIndex: number;
116
+ onSelect: (value: string, index: number) => void;
117
+ width: number;
118
+ syncOnChange?: boolean;
119
+ textStyle?: TextStyle;
120
+ }
121
+
122
+ const WheelPicker = React.forwardRef<ICarouselInstance, WheelPickerProps>(
123
+ (
124
+ { data, selectedIndex, onSelect, width, syncOnChange = true, textStyle },
125
+ ref,
126
+ ) => {
127
+ const carouselRef = useRef<ICarouselInstance>(null);
128
+ const isScrolling = useRef(false);
129
+ const shouldLoop = data.length > 2;
130
+ const safeIndex = Math.max(0, Math.min(selectedIndex, data.length - 1));
131
+ const isFirstRender = useRef(true);
132
+
133
+ // Expose ref
134
+ React.useImperativeHandle(
135
+ ref,
136
+ () => carouselRef.current as ICarouselInstance,
137
+ );
138
+
139
+ // Sync selectedIndex changes from parent (e.g. date clamping)
140
+ useEffect(() => {
141
+ if (!syncOnChange) {
142
+ return;
143
+ }
144
+ if (isFirstRender.current) {
145
+ isFirstRender.current = false;
146
+ return;
147
+ }
148
+ if (carouselRef.current && !isScrolling.current) {
149
+ carouselRef.current.scrollTo({ index: safeIndex, animated: true });
150
+ }
151
+ }, [safeIndex, syncOnChange]);
152
+
153
+ return (
154
+ <View style={[styles.wheelContainer, { width }]}>
155
+ <View style={styles.gradientTop} pointerEvents="none" />
156
+ <Carousel
157
+ ref={carouselRef}
158
+ data={data}
159
+ width={width}
160
+ height={ITEM_HEIGHT}
161
+ style={{
162
+ width: width,
163
+ height: PICKER_HEIGHT,
164
+ justifyContent: "center",
165
+ alignItems: "center",
166
+ }}
167
+ vertical
168
+ loop={shouldLoop}
169
+ windowSize={shouldLoop ? 5 : Math.max(1, data.length)}
170
+ defaultIndex={safeIndex}
171
+ pagingEnabled
172
+ snapEnabled
173
+ onProgressChange={() => {
174
+ isScrolling.current = true;
175
+ }}
176
+ onSnapToItem={(index: number) => {
177
+ if (data[index] !== undefined) {
178
+ // Only trigger onSelect if index actually changed to avoid loop
179
+ if (index !== selectedIndex) {
180
+ onSelect(data[index], index);
181
+ if (Platform.OS !== "web") {
182
+ const style = Haptics?.ImpactFeedbackStyle?.Light;
183
+ if (Haptics?.impactAsync && style !== undefined) {
184
+ Haptics.impactAsync(style);
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }}
190
+ renderItem={({
191
+ item,
192
+ animationValue,
193
+ }: {
194
+ item: string;
195
+ animationValue: any;
196
+ }) => (
197
+ <WheelItem
198
+ item={item}
199
+ animationValue={animationValue}
200
+ textStyle={textStyle}
201
+ />
202
+ )}
203
+ />
204
+ <View style={styles.gradientBottom} pointerEvents="none" />
205
+ </View>
206
+ );
207
+ },
208
+ );
209
+ WheelPicker.displayName = "WheelPicker";
210
+
211
+ // Main DatePicker component
212
+ export interface FancyDatePickerProps {
213
+ onDateChange: (date: {
214
+ day: string;
215
+ month: string;
216
+ year: string;
217
+ hour: string;
218
+ minute: string;
219
+ ampm: string;
220
+ }) => void;
221
+ initialDate?: Date;
222
+ showTime?: boolean;
223
+ containerStyle?: ViewStyle;
224
+ pickerRowStyle?: ViewStyle;
225
+ timePickerRowStyle?: ViewStyle;
226
+ itemTextStyle?: TextStyle;
227
+ timeSeparatorStyle?: TextStyle;
228
+ selectionHighlightStyle?: ViewStyle;
229
+ }
230
+
231
+ const MONTHS = [
232
+ "January",
233
+ "February",
234
+ "March",
235
+ "April",
236
+ "May",
237
+ "June",
238
+ "July",
239
+ "August",
240
+ "September",
241
+ "October",
242
+ "November",
243
+ "December",
244
+ ];
245
+
246
+ const generateDays = () =>
247
+ Array.from({ length: 31 }, (_, i) => String(i + 1).padStart(2, "0"));
248
+ const generateYears = (start: number, end: number) =>
249
+ Array.from({ length: end - start + 1 }, (_, i) => String(start + i));
250
+ const generateHours = () =>
251
+ Array.from({ length: 12 }, (_, i) => String(i + 1).padStart(2, "0"));
252
+ const generateMinutes = () =>
253
+ Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
254
+ const AMPM = ["AM", "PM"];
255
+
256
+ const FancyDatePicker = ({
257
+ onDateChange,
258
+ initialDate,
259
+ showTime = true,
260
+ containerStyle,
261
+ pickerRowStyle,
262
+ timePickerRowStyle,
263
+ itemTextStyle,
264
+ timeSeparatorStyle,
265
+ selectionHighlightStyle,
266
+ }: FancyDatePickerProps) => {
267
+ const didInitRef = useRef(false);
268
+ const days = useMemo(() => generateDays(), []);
269
+ const years = useMemo(() => generateYears(1920, 2100), []);
270
+ const hours = useMemo(() => generateHours(), []);
271
+ const minutes = useMemo(() => generateMinutes(), []);
272
+
273
+ const baseDate = useMemo(() => initialDate || new Date(), [initialDate]);
274
+ const [selectedDay, setSelectedDay] = useState(baseDate.getDate() - 1);
275
+ const [selectedMonth, setSelectedMonth] = useState(baseDate.getMonth());
276
+ const [selectedYear, setSelectedYear] = useState(
277
+ years.indexOf(String(baseDate.getFullYear())),
278
+ );
279
+
280
+ // Time state
281
+ const initialHour = baseDate.getHours();
282
+ const [selectedHour, setSelectedHour] = useState(
283
+ initialHour === 0
284
+ ? 11
285
+ : initialHour > 12
286
+ ? initialHour - 13
287
+ : initialHour - 1,
288
+ );
289
+ const [selectedMinute, setSelectedMinute] = useState(baseDate.getMinutes());
290
+ const [selectedAmPm, setSelectedAmPm] = useState(initialHour >= 12 ? 1 : 0);
291
+
292
+ const dayRef = useRef<any>(null);
293
+ const monthRef = useRef<any>(null);
294
+ const yearRef = useRef<any>(null);
295
+ const hourRef = useRef<any>(null);
296
+ const minuteRef = useRef<any>(null);
297
+ const ampmRef = useRef<any>(null);
298
+
299
+ // Sync state when initialDate changes
300
+ useEffect(() => {
301
+ if (!initialDate && !didInitRef.current) {
302
+ didInitRef.current = true;
303
+ return;
304
+ }
305
+
306
+ setSelectedDay(baseDate.getDate() - 1);
307
+ setSelectedMonth(baseDate.getMonth());
308
+ setSelectedYear(years.indexOf(String(baseDate.getFullYear())));
309
+
310
+ const initialHour = baseDate.getHours();
311
+ setSelectedHour(
312
+ initialHour === 0
313
+ ? 11
314
+ : initialHour > 12
315
+ ? initialHour - 13
316
+ : initialHour - 1,
317
+ );
318
+ setSelectedMinute(baseDate.getMinutes());
319
+ setSelectedAmPm(initialHour >= 12 ? 1 : 0);
320
+ }, [initialDate, baseDate, years]);
321
+
322
+ // Get max days for selected month/year
323
+ const maxDays = useMemo(() => {
324
+ const year = parseInt(
325
+ years[selectedYear] || String(baseDate.getFullYear()),
326
+ );
327
+ const month = selectedMonth;
328
+ return new Date(year, month + 1, 0).getDate();
329
+ }, [selectedMonth, selectedYear, years, baseDate]);
330
+
331
+ // Adjust day if it exceeds max days for the month
332
+ useEffect(() => {
333
+ if (selectedDay >= maxDays) {
334
+ setSelectedDay(maxDays - 1);
335
+ }
336
+ }, [maxDays, selectedDay]);
337
+
338
+ useEffect(() => {
339
+ onDateChange({
340
+ day: days[selectedDay] || "01",
341
+ month: MONTHS[selectedMonth] || "January",
342
+ year: years[selectedYear] || String(baseDate.getFullYear()),
343
+ hour: hours[selectedHour] || "12",
344
+ minute: minutes[selectedMinute] || "00",
345
+ ampm: AMPM[selectedAmPm] || "AM",
346
+ });
347
+ }, [
348
+ selectedDay,
349
+ selectedMonth,
350
+ selectedYear,
351
+ selectedHour,
352
+ selectedMinute,
353
+ selectedAmPm,
354
+ onDateChange,
355
+ ]);
356
+
357
+ const visibleDays = useMemo(() => days.slice(0, maxDays), [days, maxDays]);
358
+
359
+ return (
360
+ <View style={[styles.container, containerStyle]}>
361
+ <View style={[styles.pickerRow, pickerRowStyle]}>
362
+ {/* Single unified selection highlight */}
363
+ <View style={styles.selectionOverlay} pointerEvents="none">
364
+ <View style={[styles.selectionHighlight, selectionHighlightStyle]} />
365
+ </View>
366
+ <WheelPicker
367
+ ref={monthRef}
368
+ data={MONTHS}
369
+ selectedIndex={selectedMonth}
370
+ onSelect={(_, index) => setSelectedMonth(index)}
371
+ width={MONTH_WIDTH}
372
+ textStyle={itemTextStyle}
373
+ />
374
+ <View style={styles.separator} />
375
+ <WheelPicker
376
+ ref={dayRef}
377
+ data={visibleDays}
378
+ selectedIndex={Math.min(selectedDay, maxDays - 1)}
379
+ onSelect={(_, index) => setSelectedDay(index)}
380
+ width={DAY_WIDTH}
381
+ textStyle={itemTextStyle}
382
+ />
383
+ <View style={styles.separator} />
384
+ <WheelPicker
385
+ ref={yearRef}
386
+ data={years}
387
+ selectedIndex={selectedYear}
388
+ onSelect={(_, index) => setSelectedYear(index)}
389
+ width={YEAR_WIDTH}
390
+ textStyle={itemTextStyle}
391
+ />
392
+ </View>
393
+
394
+ {/* Time Picker */}
395
+ {showTime && (
396
+ <View style={[styles.timePickerRow, timePickerRowStyle]}>
397
+ {/* Single unified selection highlight */}
398
+ <View style={styles.selectionOverlay} pointerEvents="none">
399
+ <View
400
+ style={[styles.selectionHighlight, selectionHighlightStyle]}
401
+ />
402
+ </View>
403
+ <WheelPicker
404
+ ref={hourRef}
405
+ data={hours}
406
+ selectedIndex={selectedHour}
407
+ onSelect={(_, index) => setSelectedHour(index)}
408
+ width={HOUR_WIDTH}
409
+ syncOnChange={false}
410
+ textStyle={itemTextStyle}
411
+ />
412
+ <Text style={[styles.timeSeparator, timeSeparatorStyle]}>:</Text>
413
+ <WheelPicker
414
+ ref={minuteRef}
415
+ data={minutes}
416
+ selectedIndex={selectedMinute}
417
+ onSelect={(_, index) => setSelectedMinute(index)}
418
+ width={MINUTE_WIDTH}
419
+ syncOnChange={false}
420
+ textStyle={itemTextStyle}
421
+ />
422
+ <WheelPicker
423
+ ref={ampmRef}
424
+ data={AMPM}
425
+ selectedIndex={selectedAmPm}
426
+ onSelect={(_, index) => setSelectedAmPm(index)}
427
+ width={AMPM_WIDTH}
428
+ syncOnChange={false}
429
+ textStyle={itemTextStyle}
430
+ />
431
+ </View>
432
+ )}
433
+ </View>
434
+ );
435
+ };
436
+
437
+ export default FancyDatePicker;
438
+
439
+ const styles = StyleSheet.create({
440
+ container: {
441
+ alignItems: "center",
442
+ justifyContent: "center",
443
+ // paddingVertical: 20,
444
+ },
445
+ pickerRow: {
446
+ flexDirection: "row",
447
+ alignItems: "center",
448
+ justifyContent: "center",
449
+ width: PICKER_WIDTH,
450
+ height: PICKER_HEIGHT,
451
+ // backgroundColor: "rgba(30, 30, 35, 0.95)",
452
+ borderRadius: 15,
453
+ overflow: "hidden",
454
+ borderWidth: 0,
455
+ borderColor: "rgba(255, 255, 255, 0)",
456
+ // shadowColor: "#000",
457
+ // shadowOffset: { width: 0, height: 8 },
458
+ },
459
+ timePickerRow: {
460
+ marginTop: 14,
461
+ flexDirection: "row",
462
+ alignItems: "center",
463
+ justifyContent: "center",
464
+ width: TIME_PICKER_WIDTH,
465
+ height: PICKER_HEIGHT,
466
+ borderRadius: 15,
467
+ overflow: "hidden",
468
+ },
469
+ wheelContainer: {
470
+ height: PICKER_HEIGHT,
471
+ justifyContent: "center",
472
+ alignItems: "center",
473
+ },
474
+ item: {
475
+ height: ITEM_HEIGHT,
476
+ justifyContent: "center",
477
+ alignItems: "center",
478
+ },
479
+ itemText: {
480
+ color: "#ffffff",
481
+ fontSize: 18,
482
+ fontWeight: "600",
483
+ },
484
+ separator: {
485
+ width: 6,
486
+ },
487
+ timeSeparator: {
488
+ color: "#ffffff",
489
+ fontSize: 22,
490
+ fontWeight: "700",
491
+ marginHorizontal: 6,
492
+ },
493
+ selectionOverlay: {
494
+ position: "absolute",
495
+ top: ITEM_HEIGHT,
496
+ left: 0,
497
+ right: 0,
498
+ height: ITEM_HEIGHT,
499
+ alignItems: "center",
500
+ justifyContent: "center",
501
+ zIndex: 1,
502
+ },
503
+ selectionHighlight: {
504
+ width: "100%",
505
+ height: "100%",
506
+ backgroundColor: "rgba(255,255,255,0.08)",
507
+ borderTopWidth: 1,
508
+ borderBottomWidth: 1,
509
+ borderColor: "rgba(255,255,255,0.18)",
510
+ },
511
+ gradientTop: {
512
+ position: "absolute",
513
+ top: 0,
514
+ left: 0,
515
+ right: 0,
516
+ height: ITEM_HEIGHT,
517
+ backgroundColor: "rgba(0,0,0,0.45)",
518
+ zIndex: 2,
519
+ },
520
+ gradientBottom: {
521
+ position: "absolute",
522
+ bottom: 0,
523
+ left: 0,
524
+ right: 0,
525
+ height: ITEM_HEIGHT,
526
+ backgroundColor: "rgba(0,0,0,0.45)",
527
+ zIndex: 2,
528
+ },
529
+ });
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as FancyDatePicker } from "./FancyDatePicker";
2
+ export type { FancyDatePickerProps } from "./FancyDatePicker";
3
+