react-native-dates-picker 0.0.8 → 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.
Files changed (148) hide show
  1. package/lib/commonjs/CalendarContext.js.map +1 -1
  2. package/lib/commonjs/DateTimePicker.js +6 -1
  3. package/lib/commonjs/DateTimePicker.js.map +1 -1
  4. package/lib/commonjs/components/Calendar.js +1 -1
  5. package/lib/commonjs/components/Calendar.js.map +1 -1
  6. package/lib/commonjs/components/DatePicker.js +31 -27
  7. package/lib/commonjs/components/DatePicker.js.map +1 -1
  8. package/lib/commonjs/components/Day.js +11 -10
  9. package/lib/commonjs/components/Day.js.map +1 -1
  10. package/lib/commonjs/components/DaySelector.js +1 -1
  11. package/lib/commonjs/components/DaySelector.js.map +1 -1
  12. package/lib/commonjs/components/Header.js.map +1 -1
  13. package/lib/commonjs/components/MonthSelector.js.map +1 -1
  14. package/lib/commonjs/components/TimeSelector.js +6 -3
  15. package/lib/commonjs/components/TimeSelector.js.map +1 -1
  16. package/lib/commonjs/components/WheelPicker/Wheel.js +9 -5
  17. package/lib/commonjs/components/WheelPicker/Wheel.js.map +1 -1
  18. package/lib/commonjs/components/WheelPicker/WheelNative.js +16 -38
  19. package/lib/commonjs/components/WheelPicker/WheelNative.js.map +1 -1
  20. package/lib/commonjs/components/WheelPicker/WheelNativePicker/index.js +10 -0
  21. package/lib/commonjs/components/WheelPicker/WheelNativePicker/index.js.map +1 -0
  22. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +124 -0
  23. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -0
  24. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js +169 -0
  25. package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -0
  26. package/lib/commonjs/components/WheelPicker/WheelWeb.js +43 -38
  27. package/lib/commonjs/components/WheelPicker/WheelWeb.js.map +1 -1
  28. package/lib/commonjs/components/WheelPicker/animated-math.js +26 -0
  29. package/lib/commonjs/components/WheelPicker/animated-math.js.map +1 -0
  30. package/lib/commonjs/components/WheelPicker/period-native.js +36 -0
  31. package/lib/commonjs/components/WheelPicker/period-native.js.map +1 -0
  32. package/lib/commonjs/components/WheelPicker/period-picker.js +19 -0
  33. package/lib/commonjs/components/WheelPicker/period-picker.js.map +1 -0
  34. package/lib/commonjs/components/WheelPicker/period-web.js +34 -0
  35. package/lib/commonjs/components/WheelPicker/period-web.js.map +1 -0
  36. package/lib/commonjs/components/YearSelector.js.map +1 -1
  37. package/lib/commonjs/enums.js +5 -4
  38. package/lib/commonjs/enums.js.map +1 -1
  39. package/lib/commonjs/utils.js +4 -1
  40. package/lib/commonjs/utils.js.map +1 -1
  41. package/lib/module/CalendarContext.js.map +1 -1
  42. package/lib/module/DateTimePicker.js +6 -1
  43. package/lib/module/DateTimePicker.js.map +1 -1
  44. package/lib/module/components/Calendar.js +2 -2
  45. package/lib/module/components/Calendar.js.map +1 -1
  46. package/lib/module/components/DatePicker.js +32 -28
  47. package/lib/module/components/DatePicker.js.map +1 -1
  48. package/lib/module/components/Day.js +10 -10
  49. package/lib/module/components/Day.js.map +1 -1
  50. package/lib/module/components/DaySelector.js +1 -1
  51. package/lib/module/components/DaySelector.js.map +1 -1
  52. package/lib/module/components/Header.js.map +1 -1
  53. package/lib/module/components/MonthSelector.js.map +1 -1
  54. package/lib/module/components/TimeSelector.js +7 -4
  55. package/lib/module/components/TimeSelector.js.map +1 -1
  56. package/lib/module/components/WheelPicker/Wheel.js +6 -4
  57. package/lib/module/components/WheelPicker/Wheel.js.map +1 -1
  58. package/lib/module/components/WheelPicker/WheelNative.js +12 -36
  59. package/lib/module/components/WheelPicker/WheelNative.js.map +1 -1
  60. package/lib/module/components/WheelPicker/WheelNativePicker/index.js +3 -0
  61. package/lib/module/components/WheelPicker/WheelNativePicker/index.js.map +1 -0
  62. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +116 -0
  63. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -0
  64. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js +160 -0
  65. package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -0
  66. package/lib/module/components/WheelPicker/WheelWeb.js +44 -39
  67. package/lib/module/components/WheelPicker/WheelWeb.js.map +1 -1
  68. package/lib/module/components/WheelPicker/animated-math.js +20 -0
  69. package/lib/module/components/WheelPicker/animated-math.js.map +1 -0
  70. package/lib/module/components/WheelPicker/period-native.js +27 -0
  71. package/lib/module/components/WheelPicker/period-native.js.map +1 -0
  72. package/lib/module/components/WheelPicker/period-picker.js +10 -0
  73. package/lib/module/components/WheelPicker/period-picker.js.map +1 -0
  74. package/lib/module/components/WheelPicker/period-web.js +26 -0
  75. package/lib/module/components/WheelPicker/period-web.js.map +1 -0
  76. package/lib/module/components/YearSelector.js.map +1 -1
  77. package/lib/module/enums.js +4 -3
  78. package/lib/module/enums.js.map +1 -1
  79. package/lib/module/utils.js +4 -1
  80. package/lib/module/utils.js.map +1 -1
  81. package/lib/typescript/CalendarContext.d.ts.map +1 -1
  82. package/lib/typescript/DateTimePicker.d.ts +1 -1
  83. package/lib/typescript/DateTimePicker.d.ts.map +1 -1
  84. package/lib/typescript/components/Calendar.d.ts +1 -1
  85. package/lib/typescript/components/DatePicker.d.ts +2 -2
  86. package/lib/typescript/components/DatePicker.d.ts.map +1 -1
  87. package/lib/typescript/components/Day.d.ts +1 -2
  88. package/lib/typescript/components/Day.d.ts.map +1 -1
  89. package/lib/typescript/components/DaySelector.d.ts +2 -2
  90. package/lib/typescript/components/DaySelector.d.ts.map +1 -1
  91. package/lib/typescript/components/Header.d.ts +2 -2
  92. package/lib/typescript/components/Header.d.ts.map +1 -1
  93. package/lib/typescript/components/MonthSelector.d.ts +2 -2
  94. package/lib/typescript/components/MonthSelector.d.ts.map +1 -1
  95. package/lib/typescript/components/TimeSelector.d.ts +2 -2
  96. package/lib/typescript/components/TimeSelector.d.ts.map +1 -1
  97. package/lib/typescript/components/WheelPicker/Wheel.d.ts +5 -4
  98. package/lib/typescript/components/WheelPicker/Wheel.d.ts.map +1 -1
  99. package/lib/typescript/components/WheelPicker/WheelNative.d.ts +7 -8
  100. package/lib/typescript/components/WheelPicker/WheelNative.d.ts.map +1 -1
  101. package/lib/typescript/components/WheelPicker/WheelNativePicker/index.d.ts +3 -0
  102. package/lib/typescript/components/WheelPicker/WheelNativePicker/index.d.ts.map +1 -0
  103. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts +16 -0
  104. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts.map +1 -0
  105. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts +20 -0
  106. package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts.map +1 -0
  107. package/lib/typescript/components/WheelPicker/WheelWeb.d.ts +5 -4
  108. package/lib/typescript/components/WheelPicker/WheelWeb.d.ts.map +1 -1
  109. package/lib/typescript/components/WheelPicker/animated-math.d.ts +5 -0
  110. package/lib/typescript/components/WheelPicker/animated-math.d.ts.map +1 -0
  111. package/lib/typescript/components/WheelPicker/period-native.d.ts +8 -0
  112. package/lib/typescript/components/WheelPicker/period-native.d.ts.map +1 -0
  113. package/lib/typescript/components/WheelPicker/period-picker.d.ts +8 -0
  114. package/lib/typescript/components/WheelPicker/period-picker.d.ts.map +1 -0
  115. package/lib/typescript/components/WheelPicker/period-web.d.ts +8 -0
  116. package/lib/typescript/components/WheelPicker/period-web.d.ts.map +1 -0
  117. package/lib/typescript/components/YearSelector.d.ts +2 -2
  118. package/lib/typescript/components/YearSelector.d.ts.map +1 -1
  119. package/lib/typescript/enums.d.ts +2 -1
  120. package/lib/typescript/enums.d.ts.map +1 -1
  121. package/lib/typescript/types.d.ts +4 -0
  122. package/lib/typescript/types.d.ts.map +1 -1
  123. package/lib/typescript/utils.d.ts +2 -2
  124. package/lib/typescript/utils.d.ts.map +1 -1
  125. package/package.json +7 -6
  126. package/src/DateTimePicker.tsx +13 -8
  127. package/src/components/Calendar.tsx +4 -4
  128. package/src/components/DatePicker.tsx +33 -42
  129. package/src/components/Day.tsx +10 -10
  130. package/src/components/DaySelector.tsx +2 -2
  131. package/src/components/Header.tsx +1 -1
  132. package/src/components/MonthSelector.tsx +1 -1
  133. package/src/components/TimeSelector.tsx +8 -9
  134. package/src/components/WheelPicker/Wheel.tsx +9 -9
  135. package/src/components/WheelPicker/WheelNative.tsx +17 -39
  136. package/src/components/WheelPicker/WheelNativePicker/index.ts +3 -0
  137. package/src/components/WheelPicker/WheelNativePicker/wheel-picker-item.tsx +137 -0
  138. package/src/components/WheelPicker/WheelNativePicker/wheel-picker.tsx +214 -0
  139. package/src/components/WheelPicker/WheelWeb.tsx +83 -64
  140. package/src/components/WheelPicker/animated-math.ts +33 -0
  141. package/src/components/WheelPicker/period-native.tsx +39 -0
  142. package/src/components/WheelPicker/period-picker.tsx +16 -0
  143. package/src/components/WheelPicker/period-web.tsx +37 -0
  144. package/src/components/YearSelector.tsx +1 -1
  145. package/src/enums.ts +4 -3
  146. package/src/types.ts +5 -0
  147. package/src/utils.ts +3 -3
  148. /package/src/{CalendarContext.tsx → CalendarContext.ts} +0 -0
@@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react';
2
2
  import { View, StyleSheet } from 'react-native';
3
3
  import { useCalendarContext } from '../CalendarContext';
4
4
  import Wheel from './WheelPicker/Wheel';
5
- import { CALENDAR_HEIGHT } from '../enums';
5
+ import { CONTAINER_HEIGHT } from '../enums';
6
6
  import {
7
7
  getFormatted,
8
8
  getParsedDate,
@@ -11,13 +11,14 @@ import {
11
11
  getDate,
12
12
  } from '../utils';
13
13
 
14
- function createNumberList(start: number, end: number) {
15
- return new Array(end - start)
16
- .fill(0)
17
- .map((_, index) => String(index + 1 + start).padStart(2, '0'));
14
+ function createNumberList(start: number, end: number, first: number = 1) {
15
+ return new Array(end - start).fill(0).map((_, index) => ({
16
+ value: index + first + start,
17
+ text: String(index + first + start).padStart(2, '0'),
18
+ }));
18
19
  }
19
20
 
20
- const DatePicker = () => {
21
+ const DatePicker: React.FC = () => {
21
22
  const {
22
23
  columns,
23
24
  currentDate,
@@ -41,6 +42,7 @@ const DatePicker = () => {
41
42
 
42
43
  const { year: startYear, month: startMonth } = getParsedDate(minDate);
43
44
  const { year: endYear, month: endMonth } = getParsedDate(maxDate);
45
+ const { hour, minute, second } = getParsedDate(currentDate);
44
46
  const years = createNumberList(startYear - 1, endYear);
45
47
  const months = useMemo(
46
48
  () =>
@@ -57,31 +59,32 @@ const DatePicker = () => {
57
59
  );
58
60
  const hours = useMemo(
59
61
  () =>
60
- createNumberList(...getTimeRange(currentDate, minDate, maxDate, 'hour')),
62
+ createNumberList(
63
+ ...getTimeRange(currentDate, minDate, maxDate, 'hour'),
64
+ 0
65
+ ),
61
66
  [currentDate, maxDate, minDate]
62
67
  );
63
68
  const minutes = useMemo(
64
69
  () =>
65
70
  createNumberList(
66
- ...getTimeRange(currentDate, minDate, maxDate, 'minute')
71
+ ...getTimeRange(currentDate, minDate, maxDate, 'minute'),
72
+ 0
67
73
  ),
68
74
  [currentDate, maxDate, minDate]
69
75
  );
70
76
  const seconds = useMemo(
71
77
  () =>
72
78
  createNumberList(
73
- ...getTimeRange(currentDate, minDate, maxDate, 'second')
79
+ ...getTimeRange(currentDate, minDate, maxDate, 'second'),
80
+ 0
74
81
  ),
75
82
  [currentDate, maxDate, minDate]
76
83
  );
77
84
 
78
85
  const handleChangeDate = useCallback(
79
- (
80
- value: number,
81
- data: Array<string>,
82
- type: 'date' | 'hour' | 'minute' | 'second'
83
- ) => {
84
- const newDate = getDate(currentDate)[type](Number(data[value]));
86
+ (value: number, type: 'date' | 'hour' | 'minute' | 'second') => {
87
+ const newDate = getDate(currentDate).set(type, value);
85
88
  onSelectDate(getFormatted(newDate));
86
89
  },
87
90
  [currentDate, onSelectDate]
@@ -107,63 +110,49 @@ const DatePicker = () => {
107
110
  <View style={styles.wheelContainer} key={item}>
108
111
  {item === 'year' && (
109
112
  <Wheel
110
- value={years.indexOf(String(year))}
113
+ value={year}
111
114
  items={years}
112
- key={years.length}
113
- setValue={(value) => onSelectYear(Number(years[value]))}
115
+ setValue={(value) => onSelectYear(value)}
114
116
  indicatorStyle={createIndicatorStyle(index)}
115
117
  />
116
118
  )}
117
119
  {item === 'month' && (
118
120
  <Wheel
119
- value={months.indexOf(String(month + 1).padStart(2, '0'))}
121
+ value={month + 1}
120
122
  items={months}
121
- key={months.length}
122
- setValue={(value) => onSelectMonth(Number(months[value]) - 1)}
123
+ setValue={(value) => onSelectMonth(value - 1)}
123
124
  indicatorStyle={createIndicatorStyle(index)}
124
125
  />
125
126
  )}
126
127
  {item === 'day' && (
127
128
  <Wheel
128
- value={days.indexOf(
129
- String(getDate(currentDate).date()).padStart(2, '0')
130
- )}
131
- key={days.length}
129
+ value={getDate(currentDate).date()}
132
130
  items={days}
133
- setValue={(value) => handleChangeDate(value, days, 'date')}
131
+ setValue={(value) => handleChangeDate(value, 'date')}
134
132
  indicatorStyle={createIndicatorStyle(index)}
135
133
  />
136
134
  )}
137
135
  {item === 'hour' && (
138
136
  <Wheel
139
- value={hours.indexOf(
140
- String(getDate(currentDate).hour()).padStart(2, '0')
141
- )}
142
- key={hours.length}
137
+ value={hour}
143
138
  items={hours}
144
- setValue={(value) => handleChangeDate(value, hours, 'hour')}
139
+ setValue={(value) => handleChangeDate(value, 'hour')}
145
140
  indicatorStyle={createIndicatorStyle(index)}
146
141
  />
147
142
  )}
148
143
  {item === 'minute' && (
149
144
  <Wheel
150
- value={minutes.indexOf(
151
- String(getDate(currentDate).minute()).padStart(2, '0')
152
- )}
153
- key={minutes.length}
145
+ value={minute}
154
146
  items={minutes}
155
- setValue={(value) => handleChangeDate(value, minutes, 'minute')}
147
+ setValue={(value) => handleChangeDate(value, 'minute')}
156
148
  indicatorStyle={createIndicatorStyle(index)}
157
149
  />
158
150
  )}
159
151
  {item === 'second' && (
160
152
  <Wheel
161
- value={seconds.indexOf(
162
- String(getDate(currentDate).second()).padStart(2, '0')
163
- )}
164
- key={seconds.length}
153
+ value={second}
165
154
  items={seconds}
166
- setValue={(value) => handleChangeDate(value, seconds, 'second')}
155
+ setValue={(value) => handleChangeDate(value, 'second')}
167
156
  indicatorStyle={createIndicatorStyle(index)}
168
157
  />
169
158
  )}
@@ -179,16 +168,18 @@ const styles = StyleSheet.create({
179
168
  flex: 1,
180
169
  alignItems: 'center',
181
170
  justifyContent: 'center',
171
+ width: '100%',
182
172
  },
183
173
  wheelContainer: {
184
174
  flex: 1,
185
175
  },
186
176
  datePickerContainer: {
177
+ width: '100%',
187
178
  flexDirection: 'row',
188
179
  alignItems: 'center',
189
180
  justifyContent: 'center',
190
181
  paddingHorizontal: 16,
191
- height: CALENDAR_HEIGHT / 2,
182
+ height: CONTAINER_HEIGHT / 2,
192
183
  },
193
184
  });
194
185
 
@@ -1,7 +1,7 @@
1
- import React from 'react';
1
+ import React, { memo, useCallback } from 'react';
2
2
  import { View, Text, Pressable, StyleSheet } from 'react-native';
3
3
  import { CalendarThemeProps, IDayObject } from '../types';
4
- import { CALENDAR_HEIGHT } from '../enums';
4
+ import { CONTAINER_HEIGHT } from '../enums';
5
5
  import { addColorAlpha } from '../utils';
6
6
  import { isEqual } from 'lodash';
7
7
 
@@ -16,13 +16,13 @@ interface Props extends Omit<IDayObject, 'day'> {
16
16
  }
17
17
 
18
18
  function EmptyDayPure({ height }: { height?: number }) {
19
- const style = styles(height || CALENDAR_HEIGHT);
19
+ const style = styles(height || CONTAINER_HEIGHT);
20
20
  return <View style={style.dayCell} />;
21
21
  }
22
22
 
23
- export const EmptyDay = React.memo(EmptyDayPure);
23
+ export const EmptyDay = memo(EmptyDayPure);
24
24
 
25
- function Day({
25
+ const Day: React.FC<Props> = ({
26
26
  date,
27
27
  text,
28
28
  disabled,
@@ -35,8 +35,8 @@ function Day({
35
35
  onSelectDate,
36
36
  theme,
37
37
  height,
38
- }: Props) {
39
- const onPress = React.useCallback(() => {
38
+ }) => {
39
+ const onPress = useCallback(() => {
40
40
  onSelectDate(date);
41
41
  }, [onSelectDate, date]);
42
42
 
@@ -83,7 +83,7 @@ function Day({
83
83
  const rangeRootBackground =
84
84
  selectedRangeBackgroundColor ?? addColorAlpha(selectedItemColor, 0.15);
85
85
 
86
- const style = styles(height || CALENDAR_HEIGHT);
86
+ const style = styles(height || CONTAINER_HEIGHT);
87
87
 
88
88
  return (
89
89
  <View style={style.dayCell}>
@@ -138,7 +138,7 @@ function Day({
138
138
  </Pressable>
139
139
  </View>
140
140
  );
141
- }
141
+ };
142
142
 
143
143
  const styles = (height: number) =>
144
144
  StyleSheet.create({
@@ -190,4 +190,4 @@ const customComparator = (
190
190
  );
191
191
  };
192
192
 
193
- export default React.memo(Day, customComparator);
193
+ export default memo(Day, customComparator);
@@ -14,7 +14,7 @@ import {
14
14
  getFormatted,
15
15
  } from '../utils';
16
16
 
17
- const DaySelector = () => {
17
+ const DaySelector: React.FC = () => {
18
18
  const {
19
19
  mode,
20
20
  date,
@@ -117,7 +117,7 @@ const DaySelector = () => {
117
117
  if (inRange && !leftCrop && !rightCrop) isSelected = false;
118
118
  }
119
119
  } else if (mode === 'single')
120
- isSelected = areDatesOnSameDay(day.date, currentDate);
120
+ isSelected = areDatesOnSameDay(day.date, date);
121
121
 
122
122
  return {
123
123
  ...day,
@@ -5,7 +5,7 @@ import dayjs from 'dayjs';
5
5
  import type { HeaderProps } from '../types';
6
6
  import { getDateYear, getYearRange, YEAR_PAGE_SIZE } from '../utils';
7
7
 
8
- const Header = ({ buttonPrevIcon, buttonNextIcon }: HeaderProps) => {
8
+ const Header: React.FC<HeaderProps> = ({ buttonPrevIcon, buttonNextIcon }) => {
9
9
  const {
10
10
  mode,
11
11
  date,
@@ -3,7 +3,7 @@ import { Text, View, Pressable, StyleSheet } from 'react-native';
3
3
  import { useCalendarContext } from '../CalendarContext';
4
4
  import { getParsedDate, getMonths } from '../utils';
5
5
 
6
- const MonthSelector = () => {
6
+ const MonthSelector: React.FC = () => {
7
7
  const { currentDate, onSelectMonth, theme } = useCalendarContext();
8
8
  const { month } = getParsedDate(currentDate);
9
9
 
@@ -2,22 +2,21 @@ import React, { useCallback } from 'react';
2
2
  import { Text, View, StyleSheet } from 'react-native';
3
3
  import { useCalendarContext } from '../CalendarContext';
4
4
  import Wheel from './WheelPicker/Wheel';
5
- import { CALENDAR_HEIGHT } from '../enums';
5
+ import { CONTAINER_HEIGHT } from '../enums';
6
6
  import { getParsedDate, getDate, getFormatted } from '../utils';
7
7
 
8
8
  function createNumberList(num: number) {
9
- return new Array(num)
10
- .fill(0)
11
- .map((_, index) =>
12
- index < 10 ? `0${index.toString()}` : index.toString()
13
- );
9
+ return new Array(num).fill(0).map((_, index) => ({
10
+ text: index.toString().padStart(2, '0'),
11
+ value: index,
12
+ }));
14
13
  }
15
14
 
16
15
  const hours = createNumberList(24);
17
16
  const minutes = createNumberList(60);
18
17
  const seconds = createNumberList(60);
19
18
 
20
- const TimeSelector = () => {
19
+ const TimeSelector: React.FC = () => {
21
20
  const { date, onSelectDate, theme } = useCalendarContext();
22
21
  const { hour, minute, second } = getParsedDate(date);
23
22
 
@@ -87,8 +86,8 @@ const styles = StyleSheet.create({
87
86
  flexDirection: 'row',
88
87
  alignItems: 'center',
89
88
  justifyContent: 'center',
90
- width: CALENDAR_HEIGHT / 2,
91
- height: CALENDAR_HEIGHT / 2,
89
+ width: CONTAINER_HEIGHT / 2,
90
+ height: CONTAINER_HEIGHT / 2,
92
91
  },
93
92
  timePickerText: {
94
93
  fontSize: 24,
@@ -1,19 +1,19 @@
1
- import React from 'react';
1
+ import React, { memo } from 'react';
2
2
  import { Platform, type ViewStyle } from 'react-native';
3
3
  import WheelNative from './WheelNative';
4
4
  import WheelWeb from './WheelWeb';
5
+ import { PickerOption } from '../../types';
5
6
 
6
7
  interface WheelProps {
7
8
  value: number;
8
9
  setValue?: (value: number) => void;
9
- items: string[];
10
+ items: Array<PickerOption>;
10
11
  indicatorStyle?: ViewStyle;
11
12
  }
12
13
 
13
- export default function Wheel(props: WheelProps) {
14
- return Platform.OS === 'web' ? (
15
- <WheelWeb {...props} />
16
- ) : (
17
- <WheelNative {...props} />
18
- );
19
- }
14
+ const Wheel: React.FC<WheelProps> = (props) => {
15
+ const Component = Platform.OS === 'web' ? WheelWeb : WheelNative;
16
+ return <Component {...props} />;
17
+ };
18
+
19
+ export default memo(Wheel);
@@ -1,49 +1,34 @@
1
- import React from 'react';
2
- import { StyleSheet, Platform, type ViewStyle } from 'react-native';
3
- import WheelPicker from 'react-native-wheely';
4
- import { useCalendarContext } from '../../CalendarContext';
1
+ import React, { memo } from 'react';
2
+ import { StyleSheet, Platform } from 'react-native';
3
+ import WheelPicker from './WheelNativePicker';
4
+ import { PickerOption } from '../../types';
5
5
 
6
6
  interface WheelProps {
7
- value: number;
8
- setValue?: (value: number) => void;
9
- items: string[];
10
- indicatorStyle?: ViewStyle;
7
+ value: number | string;
8
+ setValue?: (value: any) => void;
9
+ items: PickerOption[];
11
10
  }
12
11
 
13
- export default function WheelNative({
12
+ const WheelNative: React.FC<WheelProps> = ({
14
13
  value,
15
14
  setValue = () => {},
16
15
  items,
17
- indicatorStyle,
18
- }: WheelProps) {
19
- const { theme } = useCalendarContext();
20
-
16
+ }) => {
21
17
  return (
22
18
  <WheelPicker
23
- selectedIndex={value < 0 ? 0 : value}
19
+ value={value}
24
20
  options={items}
25
21
  onChange={setValue}
26
- containerStyle={{
27
- ...styles.container,
28
- ...theme?.wheelPickerContainerStyle,
29
- }}
30
- itemStyle={theme?.wheelPickerItemStyle}
31
- itemTextStyle={{
32
- ...styles.wheelPickerText,
33
- ...theme?.wheelPickerTextStyle,
34
- }}
35
- selectedIndicatorStyle={{
36
- ...styles.wheelSelectedIndicator,
37
- ...indicatorStyle,
38
- ...theme?.wheelPickerIndicatorStyle,
39
- }}
40
- itemHeight={45}
41
- decelerationRate={theme?.wheelPickerDecelerationRate}
22
+ containerStyle={defaultStyles.container}
23
+ itemHeight={44}
24
+ decelerationRate="fast"
42
25
  />
43
26
  );
44
- }
27
+ };
28
+
29
+ export default memo(WheelNative);
45
30
 
46
- const styles = StyleSheet.create({
31
+ const defaultStyles = StyleSheet.create({
47
32
  container: {
48
33
  display: 'flex',
49
34
  ...Platform.select({
@@ -52,11 +37,4 @@ const styles = StyleSheet.create({
52
37
  },
53
38
  }),
54
39
  },
55
- wheelSelectedIndicator: {
56
- borderRadius: 10,
57
- },
58
- wheelPickerText: {
59
- fontSize: 18,
60
- fontWeight: '500',
61
- },
62
40
  });
@@ -0,0 +1,3 @@
1
+ import WheelPicker from './wheel-picker';
2
+
3
+ export default WheelPicker;
@@ -0,0 +1,137 @@
1
+ import React, { memo } from 'react';
2
+ import { Animated, Text, StyleSheet } from 'react-native';
3
+ import { PickerOption } from 'src/types';
4
+
5
+ interface ItemProps {
6
+ option: PickerOption | null;
7
+ height: number;
8
+ index: number;
9
+ currentScrollIndex: Animated.AnimatedAddition<number>;
10
+ visibleRest: number;
11
+ rotationFunction: (x: number) => number;
12
+ opacityFunction: (x: number) => number;
13
+ scaleFunction: (x: number) => number;
14
+ }
15
+
16
+ const WheelPickerItem: React.FC<ItemProps> = ({
17
+ height,
18
+ option,
19
+ index,
20
+ visibleRest,
21
+ currentScrollIndex,
22
+ opacityFunction,
23
+ rotationFunction,
24
+ scaleFunction,
25
+ }) => {
26
+ const relativeScrollIndex = Animated.subtract(index, currentScrollIndex);
27
+
28
+ const translateY = relativeScrollIndex.interpolate({
29
+ inputRange: (() => {
30
+ const range = [0];
31
+ for (let i = 1; i <= visibleRest + 1; i++) {
32
+ range.unshift(-i);
33
+ range.push(i);
34
+ }
35
+ return range;
36
+ })(),
37
+ outputRange: (() => {
38
+ const range = [0];
39
+ for (let i = 1; i <= visibleRest + 1; i++) {
40
+ let y =
41
+ (height / 2) * (1 - Math.sin(Math.PI / 2 - rotationFunction(i)));
42
+ for (let j = 1; j < i; j++) {
43
+ y += height * (1 - Math.sin(Math.PI / 2 - rotationFunction(j)));
44
+ }
45
+ range.unshift(y);
46
+ range.push(-y);
47
+ }
48
+ return range;
49
+ })(),
50
+ });
51
+
52
+ const opacity = relativeScrollIndex.interpolate({
53
+ inputRange: (() => {
54
+ const range = [0];
55
+ for (let i = 1; i <= visibleRest + 1; i++) {
56
+ range.unshift(-i);
57
+ range.push(i);
58
+ }
59
+ return range;
60
+ })(),
61
+ outputRange: (() => {
62
+ const range = [1];
63
+ for (let x = 1; x <= visibleRest + 1; x++) {
64
+ const y = opacityFunction(x);
65
+ range.unshift(y);
66
+ range.push(y);
67
+ }
68
+ return range;
69
+ })(),
70
+ });
71
+
72
+ const scale = relativeScrollIndex.interpolate({
73
+ inputRange: (() => {
74
+ const range = [0];
75
+ for (let i = 1; i <= visibleRest + 1; i++) {
76
+ range.unshift(-i);
77
+ range.push(i);
78
+ }
79
+ return range;
80
+ })(),
81
+ outputRange: (() => {
82
+ const range = [1.0];
83
+ for (let x = 1; x <= visibleRest + 1; x++) {
84
+ const y = scaleFunction(x);
85
+ range.unshift(y);
86
+ range.push(y);
87
+ }
88
+ return range;
89
+ })(),
90
+ });
91
+
92
+ const rotateX = relativeScrollIndex.interpolate({
93
+ inputRange: (() => {
94
+ const range = [0];
95
+ for (let i = 1; i <= visibleRest + 1; i++) {
96
+ range.unshift(-i);
97
+ range.push(i);
98
+ }
99
+ return range;
100
+ })(),
101
+ outputRange: (() => {
102
+ const range = ['0deg'];
103
+ for (let x = 1; x <= visibleRest + 1; x++) {
104
+ const y = rotationFunction(x);
105
+ range.unshift(`${y}deg`);
106
+ range.push(`${y}deg`);
107
+ }
108
+ return range;
109
+ })(),
110
+ });
111
+
112
+ return (
113
+ <Animated.View
114
+ style={[
115
+ styles.option,
116
+ {
117
+ height,
118
+ opacity,
119
+ transform: [{ translateY }, { rotateX }, { scale }],
120
+ },
121
+ ]}
122
+ >
123
+ <Text>{option?.text}</Text>
124
+ </Animated.View>
125
+ );
126
+ };
127
+
128
+ const styles = StyleSheet.create({
129
+ option: {
130
+ alignItems: 'center',
131
+ justifyContent: 'center',
132
+ paddingHorizontal: 10,
133
+ zIndex: 100,
134
+ },
135
+ });
136
+
137
+ export default memo(WheelPickerItem);