react-native-paper-dates 0.24.0 → 0.24.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 (116) hide show
  1. package/lib/commonjs/Date/AnimatedCrossView.js +2 -2
  2. package/lib/commonjs/Date/AnimatedCrossView.js.map +1 -1
  3. package/lib/commonjs/Date/AutoSizer.js +24 -11
  4. package/lib/commonjs/Date/AutoSizer.js.map +1 -1
  5. package/lib/commonjs/Date/Calendar.js +5 -3
  6. package/lib/commonjs/Date/Calendar.js.map +1 -1
  7. package/lib/commonjs/Date/CalendarEdit.js +70 -61
  8. package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
  9. package/lib/commonjs/Date/CalendarHeader.js +30 -15
  10. package/lib/commonjs/Date/CalendarHeader.js.map +1 -1
  11. package/lib/commonjs/Date/DatePickerModal.js +5 -11
  12. package/lib/commonjs/Date/DatePickerModal.js.map +1 -1
  13. package/lib/commonjs/Date/DatePickerModalContent.js +48 -34
  14. package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
  15. package/lib/commonjs/Date/DatePickerModalContentHeader.js +12 -5
  16. package/lib/commonjs/Date/DatePickerModalContentHeader.js.map +1 -1
  17. package/lib/commonjs/Date/DatePickerModalHeader.js +40 -40
  18. package/lib/commonjs/Date/DatePickerModalHeader.js.map +1 -1
  19. package/lib/commonjs/Date/DatePickerModalHeaderBackground.js +22 -4
  20. package/lib/commonjs/Date/DatePickerModalHeaderBackground.js.map +1 -1
  21. package/lib/commonjs/Date/Month.js +44 -30
  22. package/lib/commonjs/Date/Month.js.map +1 -1
  23. package/lib/commonjs/Date/Swiper.js +31 -21
  24. package/lib/commonjs/Date/Swiper.js.map +1 -1
  25. package/lib/commonjs/Date/Swiper.native.js +37 -21
  26. package/lib/commonjs/Date/Swiper.native.js.map +1 -1
  27. package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
  28. package/lib/commonjs/Date/YearPicker.js +3 -1
  29. package/lib/commonjs/Date/YearPicker.js.map +1 -1
  30. package/lib/commonjs/Date/weekdayColumns.js +60 -0
  31. package/lib/commonjs/Date/weekdayColumns.js.map +1 -0
  32. package/lib/commonjs/shared/styles.js +3 -0
  33. package/lib/commonjs/shared/styles.js.map +1 -1
  34. package/lib/commonjs/shared/utils.js +9 -0
  35. package/lib/commonjs/shared/utils.js.map +1 -1
  36. package/lib/module/Date/AnimatedCrossView.js +2 -2
  37. package/lib/module/Date/AnimatedCrossView.js.map +1 -1
  38. package/lib/module/Date/AutoSizer.js +25 -12
  39. package/lib/module/Date/AutoSizer.js.map +1 -1
  40. package/lib/module/Date/Calendar.js +5 -3
  41. package/lib/module/Date/Calendar.js.map +1 -1
  42. package/lib/module/Date/CalendarEdit.js +70 -61
  43. package/lib/module/Date/CalendarEdit.js.map +1 -1
  44. package/lib/module/Date/CalendarHeader.js +31 -16
  45. package/lib/module/Date/CalendarHeader.js.map +1 -1
  46. package/lib/module/Date/DatePickerModal.js +7 -13
  47. package/lib/module/Date/DatePickerModal.js.map +1 -1
  48. package/lib/module/Date/DatePickerModalContent.js +48 -34
  49. package/lib/module/Date/DatePickerModalContent.js.map +1 -1
  50. package/lib/module/Date/DatePickerModalContentHeader.js +12 -5
  51. package/lib/module/Date/DatePickerModalContentHeader.js.map +1 -1
  52. package/lib/module/Date/DatePickerModalHeader.js +43 -43
  53. package/lib/module/Date/DatePickerModalHeader.js.map +1 -1
  54. package/lib/module/Date/DatePickerModalHeaderBackground.js +24 -6
  55. package/lib/module/Date/DatePickerModalHeaderBackground.js.map +1 -1
  56. package/lib/module/Date/Month.js +46 -32
  57. package/lib/module/Date/Month.js.map +1 -1
  58. package/lib/module/Date/Swiper.js +32 -22
  59. package/lib/module/Date/Swiper.js.map +1 -1
  60. package/lib/module/Date/Swiper.native.js +38 -22
  61. package/lib/module/Date/Swiper.native.js.map +1 -1
  62. package/lib/module/Date/SwiperUtils.js.map +1 -1
  63. package/lib/module/Date/YearPicker.js +4 -2
  64. package/lib/module/Date/YearPicker.js.map +1 -1
  65. package/lib/module/Date/weekdayColumns.js +51 -0
  66. package/lib/module/Date/weekdayColumns.js.map +1 -0
  67. package/lib/module/shared/styles.js +3 -0
  68. package/lib/module/shared/styles.js.map +1 -1
  69. package/lib/module/shared/utils.js +8 -0
  70. package/lib/module/shared/utils.js.map +1 -1
  71. package/lib/typescript/Date/AnimatedCrossView.d.ts.map +1 -1
  72. package/lib/typescript/Date/AutoSizer.d.ts.map +1 -1
  73. package/lib/typescript/Date/Calendar.d.ts.map +1 -1
  74. package/lib/typescript/Date/CalendarEdit.d.ts +3 -1
  75. package/lib/typescript/Date/CalendarEdit.d.ts.map +1 -1
  76. package/lib/typescript/Date/CalendarHeader.d.ts +5 -1
  77. package/lib/typescript/Date/CalendarHeader.d.ts.map +1 -1
  78. package/lib/typescript/Date/DatePickerModal.d.ts.map +1 -1
  79. package/lib/typescript/Date/DatePickerModalContent.d.ts.map +1 -1
  80. package/lib/typescript/Date/DatePickerModalContentHeader.d.ts +2 -0
  81. package/lib/typescript/Date/DatePickerModalContentHeader.d.ts.map +1 -1
  82. package/lib/typescript/Date/DatePickerModalHeader.d.ts +2 -0
  83. package/lib/typescript/Date/DatePickerModalHeader.d.ts.map +1 -1
  84. package/lib/typescript/Date/DatePickerModalHeaderBackground.d.ts +3 -1
  85. package/lib/typescript/Date/DatePickerModalHeaderBackground.d.ts.map +1 -1
  86. package/lib/typescript/Date/Month.d.ts.map +1 -1
  87. package/lib/typescript/Date/Swiper.d.ts.map +1 -1
  88. package/lib/typescript/Date/Swiper.native.d.ts.map +1 -1
  89. package/lib/typescript/Date/SwiperUtils.d.ts +1 -0
  90. package/lib/typescript/Date/SwiperUtils.d.ts.map +1 -1
  91. package/lib/typescript/Date/YearPicker.d.ts.map +1 -1
  92. package/lib/typescript/Date/weekdayColumns.d.ts +9 -0
  93. package/lib/typescript/Date/weekdayColumns.d.ts.map +1 -0
  94. package/lib/typescript/shared/styles.d.ts +3 -0
  95. package/lib/typescript/shared/styles.d.ts.map +1 -1
  96. package/lib/typescript/shared/utils.d.ts +1 -0
  97. package/lib/typescript/shared/utils.d.ts.map +1 -1
  98. package/package.json +1 -1
  99. package/src/Date/AnimatedCrossView.tsx +2 -1
  100. package/src/Date/AutoSizer.tsx +33 -9
  101. package/src/Date/Calendar.tsx +5 -4
  102. package/src/Date/CalendarEdit.tsx +60 -51
  103. package/src/Date/CalendarHeader.tsx +38 -6
  104. package/src/Date/DatePickerModal.tsx +5 -13
  105. package/src/Date/DatePickerModalContent.tsx +55 -40
  106. package/src/Date/DatePickerModalContentHeader.tsx +14 -3
  107. package/src/Date/DatePickerModalHeader.tsx +47 -50
  108. package/src/Date/DatePickerModalHeaderBackground.tsx +30 -8
  109. package/src/Date/Month.tsx +73 -44
  110. package/src/Date/Swiper.native.tsx +70 -43
  111. package/src/Date/Swiper.tsx +44 -19
  112. package/src/Date/SwiperUtils.ts +1 -0
  113. package/src/Date/YearPicker.tsx +14 -2
  114. package/src/Date/weekdayColumns.ts +75 -0
  115. package/src/shared/styles.tsx +3 -0
  116. package/src/shared/utils.ts +6 -0
@@ -1,8 +1,13 @@
1
- import { Animated, StyleSheet } from 'react-native'
2
- import { Appbar, Button, useTheme } from 'react-native-paper'
1
+ import { StyleSheet, View } from 'react-native'
2
+ import { Button, IconButton, useTheme } from 'react-native-paper'
3
3
  import { useHeaderTextColor } from '../shared/utils'
4
4
  import { getTranslation } from '../translations/utils'
5
- import { useSafeAreaInsets } from 'react-native-safe-area-context'
5
+ import { sharedStyles } from '../shared/styles'
6
+ import type { DisableWeekDaysType } from './dateUtils'
7
+ import {
8
+ alignIconToFirstWeekday,
9
+ alignTextToLastWeekday,
10
+ } from './weekdayColumns'
6
11
 
7
12
  export interface DatePickerModalHeaderProps {
8
13
  saveLabel?: string
@@ -12,68 +17,60 @@ export interface DatePickerModalHeaderProps {
12
17
  onSave: () => void
13
18
  locale: string | undefined
14
19
  closeIcon?: string
20
+ disableWeekDays?: DisableWeekDaysType
15
21
  }
16
22
 
17
23
  export default function DatePickerModalHeader(
18
24
  props: DatePickerModalHeaderProps
19
25
  ) {
20
- const { locale, closeIcon = 'close' } = props
26
+ const { locale, closeIcon = 'close', disableWeekDays } = props
21
27
  const saveLabel = props.saveLabel || getTranslation(locale, 'save')
22
28
  const color = useHeaderTextColor()
23
- const insets = useSafeAreaInsets()
24
-
25
29
  const theme = useTheme()
26
30
 
27
31
  return (
28
- <>
29
- <Animated.View
30
- style={[
31
- styles.animated,
32
- {
33
- paddingLeft: insets.left,
34
- paddingRight: insets.right,
35
- },
36
- ]}
37
- >
38
- <Appbar style={styles.appbarHeader}>
39
- <Appbar.Action
40
- icon={closeIcon}
41
- accessibilityLabel={getTranslation(locale, 'close')}
42
- onPress={props.onDismiss}
43
- color={color}
44
- testID="react-native-paper-dates-close"
45
- />
46
- <Button
47
- textColor={theme.colors.primary}
48
- onPress={props.onSave}
49
- disabled={props.saveLabelDisabled ?? false}
50
- uppercase={props.uppercase ?? true}
51
- contentStyle={styles.buttonStyle}
52
- mode="text"
53
- labelStyle={styles.buttonLabel}
54
- testID="react-native-paper-dates-save"
55
- >
56
- {saveLabel}
57
- </Button>
58
- </Appbar>
59
- </Animated.View>
60
- </>
32
+ <View style={styles.headerBar}>
33
+ <IconButton
34
+ icon={closeIcon}
35
+ accessibilityLabel={getTranslation(locale, 'close')}
36
+ onPress={props.onDismiss}
37
+ iconColor={color}
38
+ testID="react-native-paper-dates-close"
39
+ style={[styles.closeButton, alignIconToFirstWeekday(disableWeekDays)]}
40
+ />
41
+ <View style={sharedStyles.root} />
42
+ <View style={alignTextToLastWeekday(disableWeekDays)}>
43
+ <Button
44
+ textColor={theme.colors.primary}
45
+ onPress={props.onSave}
46
+ disabled={props.saveLabelDisabled ?? false}
47
+ uppercase={props.uppercase ?? true}
48
+ compact
49
+ mode="text"
50
+ testID="react-native-paper-dates-save"
51
+ style={styles.saveButton}
52
+ >
53
+ {saveLabel}
54
+ </Button>
55
+ </View>
56
+ </View>
61
57
  )
62
58
  }
63
59
 
64
60
  const styles = StyleSheet.create({
65
- animated: {
66
- elevation: 4,
67
- },
68
- appbarHeader: {
69
- elevation: 0,
70
- backgroundColor: 'transparent',
71
- justifyContent: 'space-between',
61
+ headerBar: {
62
+ flexDirection: 'row',
63
+ alignItems: 'center',
64
+ width: '100%',
65
+ paddingTop: 12,
72
66
  },
73
- buttonStyle: {
74
- paddingHorizontal: 8,
67
+ closeButton: {
68
+ marginTop: 0,
69
+ marginBottom: 0,
70
+ marginEnd: 0,
75
71
  },
76
- buttonLabel: {
77
- flexGrow: 1,
72
+ saveButton: {
73
+ marginVertical: 0,
74
+ marginEnd: 0,
78
75
  },
79
76
  })
@@ -1,26 +1,48 @@
1
- import { Animated } from 'react-native'
1
+ import { Animated, StyleSheet, useWindowDimensions, View } from 'react-native'
2
2
  import { Divider } from 'react-native-paper'
3
- import { useHeaderBackgroundColor } from '../shared/utils'
3
+ import { useHeaderBackgroundColor, useIsLargeScreen } from '../shared/utils'
4
4
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
5
+ import type { DisableWeekDaysType } from './dateUtils'
6
+ import { weekdaySpan, weekdaySpanOvershoot } from './weekdayColumns'
5
7
 
6
8
  export default function DatePickerModalHeaderBackground({
7
9
  children,
10
+ disableWeekDays,
8
11
  }: {
9
12
  children: any
13
+ disableWeekDays?: DisableWeekDaysType
10
14
  }) {
11
15
  const backgroundColor = useHeaderBackgroundColor()
12
16
  const insets = useSafeAreaInsets()
17
+ const { width, height } = useWindowDimensions()
18
+ const isLargeScreen = useIsLargeScreen()
19
+ const isPhoneLandscape = width > height && !isLargeScreen
13
20
 
14
21
  return (
15
22
  <Animated.View
16
- style={{
17
- backgroundColor,
18
- paddingLeft: insets.left,
19
- paddingRight: insets.right,
20
- }}
23
+ style={[
24
+ styles.background,
25
+ {
26
+ backgroundColor,
27
+ paddingLeft: insets.left,
28
+ paddingRight: insets.right,
29
+ },
30
+ ]}
21
31
  >
22
32
  {children}
23
- <Divider />
33
+ {isPhoneLandscape ? (
34
+ <View style={weekdaySpan(disableWeekDays)}>
35
+ <Divider style={weekdaySpanOvershoot} />
36
+ </View>
37
+ ) : (
38
+ <Divider />
39
+ )}
24
40
  </Animated.View>
25
41
  )
26
42
  }
43
+
44
+ const styles = StyleSheet.create({
45
+ background: {
46
+ width: '100%',
47
+ },
48
+ })
@@ -1,4 +1,4 @@
1
- import { StyleSheet, View } from 'react-native'
1
+ import { Platform, ScrollView, StyleSheet, View } from 'react-native'
2
2
  import { Icon, Text, TouchableRipple, useTheme } from 'react-native-paper'
3
3
  import Day, { EmptyDay } from './Day'
4
4
 
@@ -19,6 +19,7 @@ import {
19
19
  showWeekDay,
20
20
  useRangeChecker,
21
21
  } from './dateUtils'
22
+ import { alignTextToFirstWeekday } from './weekdayColumns'
22
23
  import { getCalendarHeaderHeight } from './CalendarHeader'
23
24
  import type { StyleProp, ViewStyle } from 'react-native'
24
25
  import type {
@@ -272,17 +273,54 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
272
273
 
273
274
  const iconSource = selectingYear ? 'menu-up' : 'menu-down'
274
275
 
276
+ const weeks = grid.map(({ weekIndex, generatedDays }) => (
277
+ <View style={styles.week} key={weekIndex}>
278
+ {generatedDays
279
+ .filter((gd) => showWeekDay(gd.dayIndex, disableWeekDays))
280
+ .map((gd) =>
281
+ gd.beforeWeekDay || gd.afterWeekDay ? (
282
+ <EmptyDay key={gd.dayIndex} />
283
+ ) : (
284
+ <Day
285
+ key={gd.dayIndex}
286
+ theme={theme}
287
+ day={gd.dayOfMonth}
288
+ month={gd.month}
289
+ year={gd.year}
290
+ selected={gd.selected}
291
+ inRange={gd.inRange}
292
+ leftCrop={gd.leftCrop}
293
+ rightCrop={gd.rightCrop}
294
+ onPressDate={onPressDate}
295
+ isToday={gd.isToday}
296
+ selectColor={selectColor}
297
+ primaryColor={primaryColor}
298
+ disabled={gd.disabled}
299
+ textColorOnPrimary={textColorOnPrimary}
300
+ dayContent={dayContent}
301
+ dayContentPosition={dayContentPosition}
302
+ dayContentStyle={dayContentStyle}
303
+ />
304
+ )
305
+ )}
306
+ </View>
307
+ ))
308
+
275
309
  return (
276
310
  <View
277
- style={{
278
- height: getMonthHeight(
279
- scrollMode,
280
- index,
281
- startWeekOnMonday,
282
- startYear,
283
- endYear
284
- ),
285
- }}
311
+ style={
312
+ isHorizontal
313
+ ? styles.monthFill
314
+ : {
315
+ height: getMonthHeight(
316
+ scrollMode,
317
+ index,
318
+ startWeekOnMonday,
319
+ startYear,
320
+ endYear
321
+ ),
322
+ }
323
+ }
286
324
  >
287
325
  <View
288
326
  style={[
@@ -305,6 +343,7 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
305
343
  {
306
344
  borderRadius: roundness,
307
345
  },
346
+ alignTextToFirstWeekday(disableWeekDays),
308
347
  ]}
309
348
  >
310
349
  <View
@@ -339,38 +378,26 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
339
378
  </View>
340
379
  </TouchableRipple>
341
380
  </View>
342
- {grid.map(({ weekIndex, generatedDays }) => (
343
- <View style={styles.week} key={weekIndex}>
344
- {generatedDays
345
- .filter((gd) => showWeekDay(gd.dayIndex, disableWeekDays))
346
- .map((gd) =>
347
- gd.beforeWeekDay || gd.afterWeekDay ? (
348
- <EmptyDay key={gd.dayIndex} />
349
- ) : (
350
- <Day
351
- key={gd.dayIndex}
352
- theme={theme}
353
- day={gd.dayOfMonth}
354
- month={gd.month}
355
- year={gd.year}
356
- selected={gd.selected}
357
- inRange={gd.inRange}
358
- leftCrop={gd.leftCrop}
359
- rightCrop={gd.rightCrop}
360
- onPressDate={onPressDate}
361
- isToday={gd.isToday}
362
- selectColor={selectColor}
363
- primaryColor={primaryColor}
364
- disabled={gd.disabled}
365
- textColorOnPrimary={textColorOnPrimary}
366
- dayContent={dayContent}
367
- dayContentPosition={dayContentPosition}
368
- dayContentStyle={dayContentStyle}
369
- />
370
- )
371
- )}
372
- </View>
373
- ))}
381
+ {isHorizontal ? (
382
+ <ScrollView
383
+ alwaysBounceVertical={false}
384
+ directionalLockEnabled
385
+ keyboardShouldPersistTaps="handled"
386
+ nestedScrollEnabled
387
+ style={[
388
+ sharedStyles.root,
389
+ sharedStyles.minHeightZero,
390
+ Platform.OS === 'web'
391
+ ? ({ colorScheme: theme.dark ? 'dark' : 'light' } as ViewStyle)
392
+ : null,
393
+ ]}
394
+ testID="react-native-paper-dates-month-days-scroll"
395
+ >
396
+ {weeks}
397
+ </ScrollView>
398
+ ) : (
399
+ weeks
400
+ )}
374
401
  </View>
375
402
  )
376
403
  }
@@ -387,6 +414,10 @@ const styles = StyleSheet.create({
387
414
  iconWrapper: {
388
415
  padding: 8,
389
416
  },
417
+ monthFill: {
418
+ flex: 1,
419
+ minHeight: 0,
420
+ },
390
421
  monthHeader: {
391
422
  height: montHeaderHeight,
392
423
  justifyContent: 'center',
@@ -403,10 +434,8 @@ const styles = StyleSheet.create({
403
434
  },
404
435
  yearButton: {
405
436
  alignSelf: 'flex-start',
406
- marginLeft: 6,
407
437
  },
408
438
  yearButtonInner: {
409
- paddingLeft: 16,
410
439
  flexDirection: 'row',
411
440
  alignItems: 'center',
412
441
  },
@@ -20,8 +20,9 @@ import {
20
20
  getBeginOffset,
21
21
  } from './dateUtils'
22
22
  import AutoSizer from './AutoSizer'
23
- import { memo, useCallback, useRef, useState } from 'react'
23
+ import { memo, useCallback, useEffect, useRef, useState } from 'react'
24
24
  import { sharedStyles } from '../shared/styles'
25
+ import { verticalScrollbarGutter } from './CalendarHeader'
25
26
 
26
27
  function getVisibleArray(
27
28
  i: number,
@@ -124,10 +125,13 @@ function SwiperInner({
124
125
  }
125
126
  }, [scrollTo, idx, startYear, endYear])
126
127
 
127
- const scrollToInitial = useCallback(() => {
128
+ const scrollToCurrent = useCallback(() => {
128
129
  scrollTo(idx.current, false)
129
130
  }, [scrollTo])
130
131
 
132
+ // onLayout can run against the previous page width during rotation, before
133
+ useEffect(scrollToCurrent, [scrollToCurrent])
134
+
131
135
  const onMomentumScrollEnd = useCallback(
132
136
  (e: NativeSyntheticEvent<NativeScrollEvent>) => {
133
137
  const contentOffset = e.nativeEvent.contentOffset
@@ -164,6 +168,19 @@ function SwiperInner({
164
168
  onNext,
165
169
  }
166
170
 
171
+ const needsMonthScroll =
172
+ isHorizontal &&
173
+ visibleIndexes.some(
174
+ (monthIndex) =>
175
+ getMonthHeight(
176
+ scrollMode,
177
+ monthIndex,
178
+ startWeekOnMonday,
179
+ startYear,
180
+ endYear
181
+ ) > height
182
+ )
183
+
167
184
  useYearChange(
168
185
  (newIndex) => {
169
186
  if (newIndex && isIndexWithinRange(newIndex, startYear, endYear)) {
@@ -185,10 +202,12 @@ function SwiperInner({
185
202
  ref={parentRef}
186
203
  horizontal={isHorizontal}
187
204
  pagingEnabled={isHorizontal}
188
- style={sharedStyles.root}
205
+ nestedScrollEnabled={isHorizontal}
206
+ directionalLockEnabled={isHorizontal}
207
+ style={[sharedStyles.root, sharedStyles.minHeightZero]}
189
208
  onMomentumScrollEnd={onMomentumScrollEnd}
190
209
  onScrollEndDrag={onMomentumScrollEnd}
191
- onLayout={scrollToInitial}
210
+ onLayout={scrollToCurrent}
192
211
  showsHorizontalScrollIndicator={false}
193
212
  showsVerticalScrollIndicator={false}
194
213
  decelerationRate="fast"
@@ -208,48 +227,56 @@ function SwiperInner({
208
227
  ]}
209
228
  >
210
229
  {visibleIndexes
211
- ? new Array(visibleIndexes.length).fill(undefined).map((_, vi) => (
212
- <View
213
- key={vi}
214
- // eslint-disable-next-line react-native/no-inline-styles
215
- style={{
216
- top: isHorizontal
217
- ? 0
218
- : getVerticalMonthsOffset(
219
- visibleIndexes[vi],
220
- startWeekOnMonday,
221
- startYear,
222
- endYear
223
- ),
224
- left: isHorizontal
225
- ? getHorizontalMonthOffset(visibleIndexes[vi], width)
226
- : 0,
227
- right: isHorizontal ? undefined : 0,
228
- bottom: isHorizontal ? 0 : undefined,
229
- position: 'absolute',
230
- width: isHorizontal ? width : undefined,
231
- height: isHorizontal
232
- ? undefined
233
- : getMonthHeight(
234
- scrollMode,
235
- visibleIndexes[vi],
236
- startWeekOnMonday,
237
- startYear,
238
- endYear
239
- ),
240
- }}
241
- >
242
- {renderItem({
243
- index: visibleIndexes[vi],
244
- onPrev: onPrev,
245
- onNext: onNext,
246
- })}
247
- </View>
248
- ))
230
+ ? new Array(visibleIndexes.length).fill(undefined).map((_, vi) => {
231
+ const monthIndex = visibleIndexes[vi]
232
+ const monthHeight = getMonthHeight(
233
+ scrollMode,
234
+ monthIndex,
235
+ startWeekOnMonday,
236
+ startYear,
237
+ endYear
238
+ )
239
+ // Horizontal paging does not scroll inside a month. Bound the
240
+ // page to the dialog so the day grid can scroll in landscape.
241
+ return (
242
+ <View
243
+ key={vi}
244
+ // eslint-disable-next-line react-native/no-inline-styles
245
+ style={{
246
+ top: isHorizontal
247
+ ? 0
248
+ : getVerticalMonthsOffset(
249
+ monthIndex,
250
+ startWeekOnMonday,
251
+ startYear,
252
+ endYear
253
+ ),
254
+ left: isHorizontal
255
+ ? getHorizontalMonthOffset(monthIndex, width)
256
+ : 0,
257
+ right: isHorizontal ? undefined : 0,
258
+ position: 'absolute',
259
+ width: isHorizontal ? width : undefined,
260
+ height: isHorizontal ? height : monthHeight,
261
+ overflow: 'hidden',
262
+ }}
263
+ >
264
+ {renderItem({
265
+ index: monthIndex,
266
+ onPrev: onPrev,
267
+ onNext: onNext,
268
+ })}
269
+ </View>
270
+ )
271
+ })
249
272
  : null}
250
273
  </View>
251
274
  </ScrollView>
252
- {renderHeader && renderHeader(renderProps)}
275
+ {renderHeader &&
276
+ renderHeader({
277
+ ...renderProps,
278
+ endInset: needsMonthScroll ? verticalScrollbarGutter : 0,
279
+ })}
253
280
  {renderFooter && renderFooter(renderProps)}
254
281
  </>
255
282
  )
@@ -1,4 +1,3 @@
1
- import { View } from 'react-native'
2
1
  import { useTheme } from 'react-native-paper'
3
2
  import {
4
3
  getIndexFromVerticalOffset,
@@ -30,7 +29,7 @@ import {
30
29
  useRef,
31
30
  useState,
32
31
  } from 'react'
33
- import { sharedStyles } from '../shared/styles'
32
+ import { verticalScrollbarGutter } from './CalendarHeader'
34
33
 
35
34
  const useIsomorphicLayoutEffect =
36
35
  typeof window !== 'undefined' ? useLayoutEffect : useEffect
@@ -94,26 +93,52 @@ function Swiper({
94
93
 
95
94
  return (
96
95
  <>
97
- {renderHeader && renderHeader(renderProps)}
98
96
  {isHorizontal ? (
99
- <View style={sharedStyles.root}>
100
- {renderItem({ index, onPrev, onNext })}
101
- </View>
102
- ) : (
103
97
  <AutoSizer>
104
- {({ width, height }) => (
105
- <VerticalScroller
106
- width={width}
107
- height={height}
108
- initialIndex={initialIndex}
109
- estimatedHeight={estimatedMonthHeight}
110
- renderItem={renderItem}
111
- startWeekOnMonday={startWeekOnMonday}
112
- startYear={startYear}
113
- endYear={endYear}
114
- />
115
- )}
98
+ {({ height }) => {
99
+ const overflow =
100
+ getMonthHeight(
101
+ 'horizontal',
102
+ index,
103
+ startWeekOnMonday,
104
+ startYear,
105
+ endYear
106
+ ) > height
107
+ return (
108
+ <>
109
+ {renderItem({
110
+ index,
111
+ onPrev,
112
+ onNext,
113
+ })}
114
+ {renderHeader
115
+ ? renderHeader({
116
+ ...renderProps,
117
+ endInset: overflow ? verticalScrollbarGutter : 0,
118
+ })
119
+ : null}
120
+ </>
121
+ )
122
+ }}
116
123
  </AutoSizer>
124
+ ) : (
125
+ <>
126
+ {renderHeader && renderHeader(renderProps)}
127
+ <AutoSizer>
128
+ {({ width, height }) => (
129
+ <VerticalScroller
130
+ width={width}
131
+ height={height}
132
+ initialIndex={initialIndex}
133
+ estimatedHeight={estimatedMonthHeight}
134
+ renderItem={renderItem}
135
+ startWeekOnMonday={startWeekOnMonday}
136
+ startYear={startYear}
137
+ endYear={endYear}
138
+ />
139
+ )}
140
+ </AutoSizer>
141
+ </>
117
142
  )}
118
143
  {renderFooter && renderFooter(renderProps)}
119
144
  </>
@@ -10,6 +10,7 @@ import {
10
10
  import { defaultStartYear, defaultEndYear } from './dateUtils'
11
11
 
12
12
  export type RenderProps = {
13
+ endInset?: number
13
14
  index: number
14
15
  onNext: () => any
15
16
  onPrev: () => any
@@ -1,4 +1,11 @@
1
- import { FlatList, ScrollView, StyleSheet, View } from 'react-native'
1
+ import {
2
+ FlatList,
3
+ Platform,
4
+ ScrollView,
5
+ StyleSheet,
6
+ View,
7
+ type ViewStyle,
8
+ } from 'react-native'
2
9
  import { Text, TouchableRipple, useTheme } from 'react-native-paper'
3
10
  import { range } from '../shared/utils'
4
11
  import { memo, useEffect, useRef } from 'react'
@@ -51,7 +58,12 @@ export default function YearPicker({
51
58
  >
52
59
  <FlatList<number>
53
60
  ref={flatList}
54
- style={sharedStyles.root}
61
+ style={[
62
+ sharedStyles.root,
63
+ Platform.OS === 'web'
64
+ ? ({ colorScheme: theme.dark ? 'dark' : 'light' } as ViewStyle)
65
+ : null,
66
+ ]}
55
67
  data={years}
56
68
  renderScrollComponent={(sProps) => {
57
69
  return <ScrollView {...sProps} />