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.
- package/lib/commonjs/Date/AutoSizer.js +3 -2
- package/lib/commonjs/Date/AutoSizer.js.map +1 -1
- package/lib/commonjs/Date/Calendar.js +3 -1
- package/lib/commonjs/Date/Calendar.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModal.js +28 -1
- package/lib/commonjs/Date/DatePickerModal.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalContent.js +22 -2
- package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
- package/lib/commonjs/Date/Swiper.js +4 -1
- package/lib/commonjs/Date/Swiper.js.map +1 -1
- package/lib/commonjs/Date/Swiper.native.js +17 -0
- package/lib/commonjs/Date/Swiper.native.js.map +1 -1
- package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
- package/lib/module/Date/AutoSizer.js +3 -2
- package/lib/module/Date/AutoSizer.js.map +1 -1
- package/lib/module/Date/Calendar.js +3 -1
- package/lib/module/Date/Calendar.js.map +1 -1
- package/lib/module/Date/DatePickerModal.js +30 -3
- package/lib/module/Date/DatePickerModal.js.map +1 -1
- package/lib/module/Date/DatePickerModalContent.js +23 -3
- package/lib/module/Date/DatePickerModalContent.js.map +1 -1
- package/lib/module/Date/Swiper.js +4 -1
- package/lib/module/Date/Swiper.js.map +1 -1
- package/lib/module/Date/Swiper.native.js +17 -0
- package/lib/module/Date/Swiper.native.js.map +1 -1
- package/lib/module/Date/SwiperUtils.js.map +1 -1
- package/lib/typescript/Date/AutoSizer.d.ts +3 -1
- package/lib/typescript/Date/AutoSizer.d.ts.map +1 -1
- package/lib/typescript/Date/Calendar.d.ts +9 -0
- package/lib/typescript/Date/Calendar.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModal.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModalContent.d.ts +8 -0
- package/lib/typescript/Date/DatePickerModalContent.d.ts.map +1 -1
- package/lib/typescript/Date/Swiper.d.ts +1 -1
- package/lib/typescript/Date/Swiper.d.ts.map +1 -1
- package/lib/typescript/Date/Swiper.native.d.ts.map +1 -1
- package/lib/typescript/Date/SwiperUtils.d.ts +4 -0
- package/lib/typescript/Date/SwiperUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Date/AutoSizer.tsx +4 -1
- package/src/Date/Calendar.tsx +8 -0
- package/src/Date/DatePickerModal.tsx +36 -1
- package/src/Date/DatePickerModalContent.tsx +24 -1
- package/src/Date/Swiper.native.tsx +22 -1
- package/src/Date/Swiper.tsx +3 -2
- 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"
|
package/src/Date/Swiper.tsx
CHANGED
|
@@ -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}
|
package/src/Date/SwiperUtils.ts
CHANGED