react-native-paper-dates 0.22.8 → 0.22.10

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 (82) hide show
  1. package/lib/commonjs/Date/Calendar.js +7 -3
  2. package/lib/commonjs/Date/Calendar.js.map +1 -1
  3. package/lib/commonjs/Date/CalendarHeader.js +4 -2
  4. package/lib/commonjs/Date/CalendarHeader.js.map +1 -1
  5. package/lib/commonjs/Date/DatePickerInput.js +4 -2
  6. package/lib/commonjs/Date/DatePickerInput.js.map +1 -1
  7. package/lib/commonjs/Date/DatePickerInputWithoutModal.js +3 -1
  8. package/lib/commonjs/Date/DatePickerInputWithoutModal.js.map +1 -1
  9. package/lib/commonjs/Date/DatePickerModalContent.js +4 -2
  10. package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
  11. package/lib/commonjs/Date/DayNames.js +8 -5
  12. package/lib/commonjs/Date/DayNames.js.map +1 -1
  13. package/lib/commonjs/Date/DayRange.js +1 -4
  14. package/lib/commonjs/Date/DayRange.js.map +1 -1
  15. package/lib/commonjs/Date/Month.js +18 -16
  16. package/lib/commonjs/Date/Month.js.map +1 -1
  17. package/lib/commonjs/Date/Swiper.js +11 -8
  18. package/lib/commonjs/Date/Swiper.js.map +1 -1
  19. package/lib/commonjs/Date/Swiper.native.js +8 -7
  20. package/lib/commonjs/Date/Swiper.native.js.map +1 -1
  21. package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
  22. package/lib/commonjs/Date/dateUtils.js +13 -6
  23. package/lib/commonjs/Date/dateUtils.js.map +1 -1
  24. package/lib/module/Date/Calendar.js +7 -3
  25. package/lib/module/Date/Calendar.js.map +1 -1
  26. package/lib/module/Date/CalendarHeader.js +4 -2
  27. package/lib/module/Date/CalendarHeader.js.map +1 -1
  28. package/lib/module/Date/DatePickerInput.js +4 -2
  29. package/lib/module/Date/DatePickerInput.js.map +1 -1
  30. package/lib/module/Date/DatePickerInputWithoutModal.js +3 -1
  31. package/lib/module/Date/DatePickerInputWithoutModal.js.map +1 -1
  32. package/lib/module/Date/DatePickerModalContent.js +4 -2
  33. package/lib/module/Date/DatePickerModalContent.js.map +1 -1
  34. package/lib/module/Date/DayNames.js +8 -5
  35. package/lib/module/Date/DayNames.js.map +1 -1
  36. package/lib/module/Date/DayRange.js +1 -4
  37. package/lib/module/Date/DayRange.js.map +1 -1
  38. package/lib/module/Date/Month.js +18 -16
  39. package/lib/module/Date/Month.js.map +1 -1
  40. package/lib/module/Date/Swiper.js +11 -8
  41. package/lib/module/Date/Swiper.js.map +1 -1
  42. package/lib/module/Date/Swiper.native.js +8 -7
  43. package/lib/module/Date/Swiper.native.js.map +1 -1
  44. package/lib/module/Date/SwiperUtils.js.map +1 -1
  45. package/lib/module/Date/dateUtils.js +13 -6
  46. package/lib/module/Date/dateUtils.js.map +1 -1
  47. package/lib/typescript/Date/Calendar.d.ts +1 -0
  48. package/lib/typescript/Date/Calendar.d.ts.map +1 -1
  49. package/lib/typescript/Date/CalendarHeader.d.ts +2 -1
  50. package/lib/typescript/Date/CalendarHeader.d.ts.map +1 -1
  51. package/lib/typescript/Date/DatePickerInput.d.ts.map +1 -1
  52. package/lib/typescript/Date/DatePickerInput.shared.d.ts +1 -0
  53. package/lib/typescript/Date/DatePickerInput.shared.d.ts.map +1 -1
  54. package/lib/typescript/Date/DatePickerInputWithoutModal.d.ts +2 -0
  55. package/lib/typescript/Date/DatePickerInputWithoutModal.d.ts.map +1 -1
  56. package/lib/typescript/Date/DatePickerModalContent.d.ts.map +1 -1
  57. package/lib/typescript/Date/DayNames.d.ts +2 -1
  58. package/lib/typescript/Date/DayNames.d.ts.map +1 -1
  59. package/lib/typescript/Date/DayRange.d.ts.map +1 -1
  60. package/lib/typescript/Date/Month.d.ts +4 -3
  61. package/lib/typescript/Date/Month.d.ts.map +1 -1
  62. package/lib/typescript/Date/Swiper.d.ts +1 -1
  63. package/lib/typescript/Date/Swiper.d.ts.map +1 -1
  64. package/lib/typescript/Date/Swiper.native.d.ts.map +1 -1
  65. package/lib/typescript/Date/SwiperUtils.d.ts +1 -0
  66. package/lib/typescript/Date/SwiperUtils.d.ts.map +1 -1
  67. package/lib/typescript/Date/dateUtils.d.ts +4 -3
  68. package/lib/typescript/Date/dateUtils.d.ts.map +1 -1
  69. package/package.json +1 -1
  70. package/src/Date/Calendar.tsx +5 -0
  71. package/src/Date/CalendarHeader.tsx +7 -1
  72. package/src/Date/DatePickerInput.shared.tsx +1 -0
  73. package/src/Date/DatePickerInput.tsx +2 -0
  74. package/src/Date/DatePickerInputWithoutModal.tsx +3 -0
  75. package/src/Date/DatePickerModalContent.tsx +2 -0
  76. package/src/Date/DayNames.tsx +16 -12
  77. package/src/Date/DayRange.tsx +1 -4
  78. package/src/Date/Month.tsx +29 -14
  79. package/src/Date/Swiper.native.tsx +17 -6
  80. package/src/Date/Swiper.tsx +15 -5
  81. package/src/Date/SwiperUtils.ts +1 -0
  82. package/src/Date/dateUtils.tsx +13 -5
@@ -20,6 +20,7 @@ function Swiper({
20
20
  renderFooter,
21
21
  selectedYear,
22
22
  initialIndex,
23
+ startWeekOnMonday,
23
24
  }: SwiperProps) {
24
25
  const isHorizontal = scrollMode === 'horizontal'
25
26
  const [index, setIndex] = React.useState(initialIndex)
@@ -66,6 +67,7 @@ function Swiper({
66
67
  initialIndex={initialIndex}
67
68
  estimatedHeight={estimatedMonthHeight}
68
69
  renderItem={renderItem}
70
+ startWeekOnMonday={startWeekOnMonday}
69
71
  />
70
72
  )}
71
73
  </AutoSizer>
@@ -83,12 +85,14 @@ function VerticalScroller({
83
85
  initialIndex,
84
86
  estimatedHeight,
85
87
  renderItem,
88
+ startWeekOnMonday,
86
89
  }: {
87
90
  renderItem: (renderProps: RenderProps) => any
88
91
  width: number
89
92
  height: number
90
93
  initialIndex: number
91
94
  estimatedHeight: number
95
+ startWeekOnMonday: boolean
92
96
  }) {
93
97
  const idx = React.useRef<number>(initialIndex)
94
98
  const [visibleIndexes, setVisibleIndexes] = React.useState<number[]>(
@@ -101,7 +105,8 @@ function VerticalScroller({
101
105
  if (!element) {
102
106
  return
103
107
  }
104
- const top = getVerticalMonthsOffset(idx.current) - montHeaderHeight
108
+ const top =
109
+ getVerticalMonthsOffset(idx.current, startWeekOnMonday) - montHeaderHeight
105
110
 
106
111
  element.scrollTo({
107
112
  top,
@@ -118,14 +123,14 @@ function VerticalScroller({
118
123
  }
119
124
 
120
125
  const offset = top - beginOffset
121
- const index = getIndexFromVerticalOffset(offset)
126
+ const index = getIndexFromVerticalOffset(offset, startWeekOnMonday)
122
127
 
123
128
  if (idx.current !== index) {
124
129
  idx.current = index
125
130
  setVisibleIndexesThrottled(visibleArray(index))
126
131
  }
127
132
  },
128
- [setVisibleIndexesThrottled]
133
+ [setVisibleIndexesThrottled, startWeekOnMonday]
129
134
  )
130
135
 
131
136
  return (
@@ -153,12 +158,17 @@ function VerticalScroller({
153
158
  style={{
154
159
  willChange: 'transform',
155
160
  transform: `translateY(${getVerticalMonthsOffset(
156
- visibleIndexes[vi]
161
+ visibleIndexes[vi],
162
+ startWeekOnMonday
157
163
  )}px)`,
158
164
  left: 0,
159
165
  right: 0,
160
166
  position: 'absolute',
161
- height: getMonthHeight('vertical', visibleIndexes[vi]),
167
+ height: getMonthHeight(
168
+ 'vertical',
169
+ visibleIndexes[vi],
170
+ startWeekOnMonday
171
+ ),
162
172
  }}
163
173
  >
164
174
  {renderItem({
@@ -21,6 +21,7 @@ export type SwiperProps = {
21
21
  renderHeader?: (renderProps: RenderProps) => any
22
22
  renderFooter?: (renderProps: RenderProps) => any
23
23
  selectedYear: number | undefined
24
+ startWeekOnMonday: boolean
24
25
  }
25
26
 
26
27
  export function useYearChange(
@@ -58,11 +58,19 @@ export function getDaysInMonth({
58
58
  export function getFirstDayOfMonth({
59
59
  year,
60
60
  month,
61
+ startWeekOnMonday,
61
62
  }: {
62
63
  year: number
63
64
  month: number
65
+ startWeekOnMonday: boolean
64
66
  }): number {
65
- return new Date(year, month, 1).getDay()
67
+ let dayOfWeek = new Date(year, month, 1).getDay()
68
+ if (startWeekOnMonday) {
69
+ // Map Sunday (0) to 6, Monday (1) to 0, etc.
70
+ dayOfWeek = (dayOfWeek + 6) % 7
71
+ }
72
+
73
+ return dayOfWeek
66
74
  }
67
75
 
68
76
  export function useRangeChecker(validRange: ValidRangeType | undefined) {
@@ -167,22 +175,22 @@ export const totalMonths = startAtIndex * 2
167
175
  export const beginOffset = estimatedMonthHeight * startAtIndex
168
176
  export const gridCounts = new Array<number | undefined>(totalMonths)
169
177
 
170
- export function getGridCount(index: number) {
178
+ export function getGridCount(index: number, startWeekOnMonday: boolean) {
171
179
  const cHeight = gridCounts[index]
172
180
  if (cHeight) {
173
181
  return cHeight
174
182
  }
175
183
  const monthDate = addMonths(new Date(), getRealIndex(index))
176
- const h = getGridCountForDate(monthDate)
184
+ const h = getGridCountForDate(monthDate, startWeekOnMonday)
177
185
  gridCounts[index] = h
178
186
  return h
179
187
  }
180
188
 
181
- export function getGridCountForDate(date: Date) {
189
+ export function getGridCountForDate(date: Date, startWeekOnMonday: boolean) {
182
190
  const year = date.getFullYear()
183
191
  const month = date.getMonth()
184
192
  const daysInMonth = getDaysInMonth({ year, month })
185
- const dayOfWeek = getFirstDayOfMonth({ year, month })
193
+ const dayOfWeek = getFirstDayOfMonth({ year, month, startWeekOnMonday })
186
194
  return Math.ceil((daysInMonth + dayOfWeek) / 7)
187
195
  }
188
196