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.
- package/lib/commonjs/Date/AnimatedCrossView.js +2 -2
- package/lib/commonjs/Date/AnimatedCrossView.js.map +1 -1
- package/lib/commonjs/Date/AutoSizer.js +24 -11
- package/lib/commonjs/Date/AutoSizer.js.map +1 -1
- package/lib/commonjs/Date/Calendar.js +5 -3
- package/lib/commonjs/Date/Calendar.js.map +1 -1
- package/lib/commonjs/Date/CalendarEdit.js +70 -61
- package/lib/commonjs/Date/CalendarEdit.js.map +1 -1
- package/lib/commonjs/Date/CalendarHeader.js +30 -15
- package/lib/commonjs/Date/CalendarHeader.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModal.js +5 -11
- package/lib/commonjs/Date/DatePickerModal.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalContent.js +48 -34
- package/lib/commonjs/Date/DatePickerModalContent.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalContentHeader.js +12 -5
- package/lib/commonjs/Date/DatePickerModalContentHeader.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalHeader.js +40 -40
- package/lib/commonjs/Date/DatePickerModalHeader.js.map +1 -1
- package/lib/commonjs/Date/DatePickerModalHeaderBackground.js +22 -4
- package/lib/commonjs/Date/DatePickerModalHeaderBackground.js.map +1 -1
- package/lib/commonjs/Date/Month.js +44 -30
- package/lib/commonjs/Date/Month.js.map +1 -1
- package/lib/commonjs/Date/Swiper.js +31 -21
- package/lib/commonjs/Date/Swiper.js.map +1 -1
- package/lib/commonjs/Date/Swiper.native.js +37 -21
- package/lib/commonjs/Date/Swiper.native.js.map +1 -1
- package/lib/commonjs/Date/SwiperUtils.js.map +1 -1
- package/lib/commonjs/Date/YearPicker.js +3 -1
- package/lib/commonjs/Date/YearPicker.js.map +1 -1
- package/lib/commonjs/Date/weekdayColumns.js +60 -0
- package/lib/commonjs/Date/weekdayColumns.js.map +1 -0
- package/lib/commonjs/shared/styles.js +3 -0
- package/lib/commonjs/shared/styles.js.map +1 -1
- package/lib/commonjs/shared/utils.js +9 -0
- package/lib/commonjs/shared/utils.js.map +1 -1
- package/lib/module/Date/AnimatedCrossView.js +2 -2
- package/lib/module/Date/AnimatedCrossView.js.map +1 -1
- package/lib/module/Date/AutoSizer.js +25 -12
- package/lib/module/Date/AutoSizer.js.map +1 -1
- package/lib/module/Date/Calendar.js +5 -3
- package/lib/module/Date/Calendar.js.map +1 -1
- package/lib/module/Date/CalendarEdit.js +70 -61
- package/lib/module/Date/CalendarEdit.js.map +1 -1
- package/lib/module/Date/CalendarHeader.js +31 -16
- package/lib/module/Date/CalendarHeader.js.map +1 -1
- package/lib/module/Date/DatePickerModal.js +7 -13
- package/lib/module/Date/DatePickerModal.js.map +1 -1
- package/lib/module/Date/DatePickerModalContent.js +48 -34
- package/lib/module/Date/DatePickerModalContent.js.map +1 -1
- package/lib/module/Date/DatePickerModalContentHeader.js +12 -5
- package/lib/module/Date/DatePickerModalContentHeader.js.map +1 -1
- package/lib/module/Date/DatePickerModalHeader.js +43 -43
- package/lib/module/Date/DatePickerModalHeader.js.map +1 -1
- package/lib/module/Date/DatePickerModalHeaderBackground.js +24 -6
- package/lib/module/Date/DatePickerModalHeaderBackground.js.map +1 -1
- package/lib/module/Date/Month.js +46 -32
- package/lib/module/Date/Month.js.map +1 -1
- package/lib/module/Date/Swiper.js +32 -22
- package/lib/module/Date/Swiper.js.map +1 -1
- package/lib/module/Date/Swiper.native.js +38 -22
- package/lib/module/Date/Swiper.native.js.map +1 -1
- package/lib/module/Date/SwiperUtils.js.map +1 -1
- package/lib/module/Date/YearPicker.js +4 -2
- package/lib/module/Date/YearPicker.js.map +1 -1
- package/lib/module/Date/weekdayColumns.js +51 -0
- package/lib/module/Date/weekdayColumns.js.map +1 -0
- package/lib/module/shared/styles.js +3 -0
- package/lib/module/shared/styles.js.map +1 -1
- package/lib/module/shared/utils.js +8 -0
- package/lib/module/shared/utils.js.map +1 -1
- package/lib/typescript/Date/AnimatedCrossView.d.ts.map +1 -1
- package/lib/typescript/Date/AutoSizer.d.ts.map +1 -1
- package/lib/typescript/Date/Calendar.d.ts.map +1 -1
- package/lib/typescript/Date/CalendarEdit.d.ts +3 -1
- package/lib/typescript/Date/CalendarEdit.d.ts.map +1 -1
- package/lib/typescript/Date/CalendarHeader.d.ts +5 -1
- package/lib/typescript/Date/CalendarHeader.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModal.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModalContent.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModalContentHeader.d.ts +2 -0
- package/lib/typescript/Date/DatePickerModalContentHeader.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModalHeader.d.ts +2 -0
- package/lib/typescript/Date/DatePickerModalHeader.d.ts.map +1 -1
- package/lib/typescript/Date/DatePickerModalHeaderBackground.d.ts +3 -1
- package/lib/typescript/Date/DatePickerModalHeaderBackground.d.ts.map +1 -1
- package/lib/typescript/Date/Month.d.ts.map +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 +1 -0
- package/lib/typescript/Date/SwiperUtils.d.ts.map +1 -1
- package/lib/typescript/Date/YearPicker.d.ts.map +1 -1
- package/lib/typescript/Date/weekdayColumns.d.ts +9 -0
- package/lib/typescript/Date/weekdayColumns.d.ts.map +1 -0
- package/lib/typescript/shared/styles.d.ts +3 -0
- package/lib/typescript/shared/styles.d.ts.map +1 -1
- package/lib/typescript/shared/utils.d.ts +1 -0
- package/lib/typescript/shared/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Date/AnimatedCrossView.tsx +2 -1
- package/src/Date/AutoSizer.tsx +33 -9
- package/src/Date/Calendar.tsx +5 -4
- package/src/Date/CalendarEdit.tsx +60 -51
- package/src/Date/CalendarHeader.tsx +38 -6
- package/src/Date/DatePickerModal.tsx +5 -13
- package/src/Date/DatePickerModalContent.tsx +55 -40
- package/src/Date/DatePickerModalContentHeader.tsx +14 -3
- package/src/Date/DatePickerModalHeader.tsx +47 -50
- package/src/Date/DatePickerModalHeaderBackground.tsx +30 -8
- package/src/Date/Month.tsx +73 -44
- package/src/Date/Swiper.native.tsx +70 -43
- package/src/Date/Swiper.tsx +44 -19
- package/src/Date/SwiperUtils.ts +1 -0
- package/src/Date/YearPicker.tsx +14 -2
- package/src/Date/weekdayColumns.ts +75 -0
- package/src/shared/styles.tsx +3 -0
- package/src/shared/utils.ts +6 -0
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
backgroundColor: 'transparent',
|
|
71
|
-
justifyContent: 'space-between',
|
|
61
|
+
headerBar: {
|
|
62
|
+
flexDirection: 'row',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
width: '100%',
|
|
65
|
+
paddingTop: 12,
|
|
72
66
|
},
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
closeButton: {
|
|
68
|
+
marginTop: 0,
|
|
69
|
+
marginBottom: 0,
|
|
70
|
+
marginEnd: 0,
|
|
75
71
|
},
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
+
})
|
package/src/Date/Month.tsx
CHANGED
|
@@ -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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
{
|
|
343
|
-
<
|
|
344
|
-
{
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
|
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
|
-
|
|
205
|
+
nestedScrollEnabled={isHorizontal}
|
|
206
|
+
directionalLockEnabled={isHorizontal}
|
|
207
|
+
style={[sharedStyles.root, sharedStyles.minHeightZero]}
|
|
189
208
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
190
209
|
onScrollEndDrag={onMomentumScrollEnd}
|
|
191
|
-
onLayout={
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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 &&
|
|
275
|
+
{renderHeader &&
|
|
276
|
+
renderHeader({
|
|
277
|
+
...renderProps,
|
|
278
|
+
endInset: needsMonthScroll ? verticalScrollbarGutter : 0,
|
|
279
|
+
})}
|
|
253
280
|
{renderFooter && renderFooter(renderProps)}
|
|
254
281
|
</>
|
|
255
282
|
)
|
package/src/Date/Swiper.tsx
CHANGED
|
@@ -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 {
|
|
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
|
-
{({
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
</>
|
package/src/Date/SwiperUtils.ts
CHANGED
package/src/Date/YearPicker.tsx
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
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={
|
|
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} />
|