react-native-paper-dates 0.24.1 → 0.24.2

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 (46) hide show
  1. package/lib/commonjs/Date/AutoSizer.js +3 -2
  2. package/lib/commonjs/Date/AutoSizer.js.map +1 -1
  3. package/lib/commonjs/Date/Calendar.js +3 -1
  4. package/lib/commonjs/Date/Calendar.js.map +1 -1
  5. package/lib/commonjs/Date/DatePickerModal.js +28 -1
  6. package/lib/commonjs/Date/DatePickerModal.js.map +1 -1
  7. package/lib/commonjs/Date/DatePickerModalContent.js +22 -2
  8. package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
  9. package/lib/commonjs/Date/Swiper.js +4 -1
  10. package/lib/commonjs/Date/Swiper.js.map +1 -1
  11. package/lib/commonjs/Date/Swiper.native.js +17 -0
  12. package/lib/commonjs/Date/Swiper.native.js.map +1 -1
  13. package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
  14. package/lib/module/Date/AutoSizer.js +3 -2
  15. package/lib/module/Date/AutoSizer.js.map +1 -1
  16. package/lib/module/Date/Calendar.js +3 -1
  17. package/lib/module/Date/Calendar.js.map +1 -1
  18. package/lib/module/Date/DatePickerModal.js +30 -3
  19. package/lib/module/Date/DatePickerModal.js.map +1 -1
  20. package/lib/module/Date/DatePickerModalContent.js +23 -3
  21. package/lib/module/Date/DatePickerModalContent.js.map +1 -1
  22. package/lib/module/Date/Swiper.js +4 -1
  23. package/lib/module/Date/Swiper.js.map +1 -1
  24. package/lib/module/Date/Swiper.native.js +17 -0
  25. package/lib/module/Date/Swiper.native.js.map +1 -1
  26. package/lib/module/Date/SwiperUtils.js.map +1 -1
  27. package/lib/typescript/Date/AutoSizer.d.ts +3 -1
  28. package/lib/typescript/Date/AutoSizer.d.ts.map +1 -1
  29. package/lib/typescript/Date/Calendar.d.ts +9 -0
  30. package/lib/typescript/Date/Calendar.d.ts.map +1 -1
  31. package/lib/typescript/Date/DatePickerModal.d.ts.map +1 -1
  32. package/lib/typescript/Date/DatePickerModalContent.d.ts +8 -0
  33. package/lib/typescript/Date/DatePickerModalContent.d.ts.map +1 -1
  34. package/lib/typescript/Date/Swiper.d.ts +1 -1
  35. package/lib/typescript/Date/Swiper.d.ts.map +1 -1
  36. package/lib/typescript/Date/Swiper.native.d.ts.map +1 -1
  37. package/lib/typescript/Date/SwiperUtils.d.ts +4 -0
  38. package/lib/typescript/Date/SwiperUtils.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/Date/AutoSizer.tsx +4 -1
  41. package/src/Date/Calendar.tsx +8 -0
  42. package/src/Date/DatePickerModal.tsx +36 -1
  43. package/src/Date/DatePickerModalContent.tsx +24 -1
  44. package/src/Date/Swiper.native.tsx +22 -1
  45. package/src/Date/Swiper.tsx +3 -2
  46. package/src/Date/SwiperUtils.ts +1 -0
@@ -17,7 +17,7 @@ import CalendarEdit from './CalendarEdit'
17
17
  import DatePickerModalHeaderBackground from './DatePickerModalHeaderBackground'
18
18
  import DatePickerModalStatusBar from './DatePickerModalStatusBar'
19
19
  import { memo, useCallback, useEffect, useState } from 'react'
20
- import { View } from 'react-native'
20
+ import { LayoutChangeEvent, Platform, View } from 'react-native'
21
21
  import { useSafeAreaInsets } from 'react-native-safe-area-context'
22
22
  import { sharedStyles } from '../shared/styles'
23
23
 
@@ -40,6 +40,12 @@ interface DatePickerModalContentBaseProps {
40
40
  disableSafeTop?: boolean
41
41
  disableStatusBar?: boolean
42
42
  statusBarOnTopOfBackdrop?: boolean
43
+
44
+ /**
45
+ * Called with the calendar's measured size. `DatePickerModal` uses it to
46
+ * draw the calendar immediately the next time it opens.
47
+ */
48
+ onCalendarLayout?: (layout: { width: number; height: number }) => void
43
49
  }
44
50
 
45
51
  export interface DatePickerModalContentRangeProps
@@ -92,6 +98,8 @@ export function DatePickerModalContent(
92
98
  dayContent,
93
99
  dayContentPosition,
94
100
  dayContentStyle,
101
+ initialLayout,
102
+ onCalendarLayout,
95
103
  } = props
96
104
  const anyProps = props as any
97
105
  const defaultUppercase = false
@@ -145,6 +153,19 @@ export function DatePickerModalContent(
145
153
  setCollapsed((prev) => !prev)
146
154
  }, [setCollapsed])
147
155
 
156
+ // The calendar fills this view inside the inset padding. Not on web, where
157
+ // the range calendar's header sits above the part that sizes itself.
158
+ const onCalendarContainerLayout = useCallback(
159
+ (event: LayoutChangeEvent) => {
160
+ const { width, height } = event.nativeEvent.layout
161
+ const calendarWidth = width - insets.left - insets.right
162
+ if (onCalendarLayout && calendarWidth > 0 && height > 0) {
163
+ onCalendarLayout({ width: calendarWidth, height })
164
+ }
165
+ },
166
+ [onCalendarLayout, insets.left, insets.right]
167
+ )
168
+
148
169
  return (
149
170
  <>
150
171
  <DatePickerModalHeaderBackground disableWeekDays={disableWeekDays}>
@@ -188,6 +209,7 @@ export function DatePickerModalContent(
188
209
  sharedStyles.minHeightZero,
189
210
  { paddingLeft: insets.left, paddingRight: insets.right },
190
211
  ]}
212
+ onLayout={Platform.OS === 'web' ? undefined : onCalendarContainerLayout}
191
213
  >
192
214
  <AnimatedCrossView
193
215
  collapsed={collapsed}
@@ -209,6 +231,7 @@ export function DatePickerModalContent(
209
231
  dayContent={dayContent}
210
232
  dayContentPosition={dayContentPosition}
211
233
  dayContentStyle={dayContentStyle}
234
+ initialLayout={initialLayout}
212
235
  />
213
236
  }
214
237
  calendarEdit={
@@ -36,7 +36,7 @@ function getVisibleArray(
36
36
 
37
37
  function Swiper(props: SwiperProps) {
38
38
  return (
39
- <AutoSizer>
39
+ <AutoSizer initialLayout={props.initialLayout}>
40
40
  {({ width, height }) => (
41
41
  <SwiperInner {...props} width={width} height={height} />
42
42
  )}
@@ -65,6 +65,26 @@ function SwiperInner({
65
65
 
66
66
  const parentRef = useRef<ScrollView | null>(null)
67
67
 
68
+ // Start on the current month instead of at 0 (where no month is rendered)
69
+ // and then jumping there after mount. Later moves go through scrollTo.
70
+ const [initialContentOffset] = useState(() => {
71
+ if (!isIndexWithinRange(initialIndex, startYear, endYear)) {
72
+ return undefined
73
+ }
74
+ return isHorizontal
75
+ ? { x: getHorizontalMonthOffset(initialIndex, width), y: 0 }
76
+ : {
77
+ x: 0,
78
+ y:
79
+ getVerticalMonthsOffset(
80
+ initialIndex,
81
+ startWeekOnMonday,
82
+ startYear,
83
+ endYear
84
+ ) - montHeaderHeight,
85
+ }
86
+ })
87
+
68
88
  const scrollTo = useCallback(
69
89
  (index: number, animated: boolean) => {
70
90
  if (!isIndexWithinRange(index, startYear, endYear)) {
@@ -208,6 +228,7 @@ function SwiperInner({
208
228
  onMomentumScrollEnd={onMomentumScrollEnd}
209
229
  onScrollEndDrag={onMomentumScrollEnd}
210
230
  onLayout={scrollToCurrent}
231
+ contentOffset={initialContentOffset}
211
232
  showsHorizontalScrollIndicator={false}
212
233
  showsVerticalScrollIndicator={false}
213
234
  decelerationRate="fast"
@@ -44,6 +44,7 @@ function Swiper({
44
44
  startWeekOnMonday,
45
45
  startYear,
46
46
  endYear,
47
+ initialLayout,
47
48
  }: SwiperProps) {
48
49
  const isHorizontal = scrollMode === 'horizontal'
49
50
 
@@ -94,7 +95,7 @@ function Swiper({
94
95
  return (
95
96
  <>
96
97
  {isHorizontal ? (
97
- <AutoSizer>
98
+ <AutoSizer initialLayout={initialLayout}>
98
99
  {({ height }) => {
99
100
  const overflow =
100
101
  getMonthHeight(
@@ -124,7 +125,7 @@ function Swiper({
124
125
  ) : (
125
126
  <>
126
127
  {renderHeader && renderHeader(renderProps)}
127
- <AutoSizer>
128
+ <AutoSizer initialLayout={initialLayout}>
128
129
  {({ width, height }) => (
129
130
  <VerticalScroller
130
131
  width={width}
@@ -26,6 +26,7 @@ export type SwiperProps = {
26
26
  startWeekOnMonday: boolean
27
27
  startYear?: number
28
28
  endYear?: number
29
+ initialLayout?: { width: number; height: number }
29
30
  }
30
31
 
31
32
  // Helper function to get the minimum allowed index based on startYear