Skip to content

Commit dc0dc67

Browse files
committed
Date picker updates.
1 parent 34bed5b commit dc0dc67

File tree

9 files changed

+78
-94
lines changed

9 files changed

+78
-94
lines changed

src/Date/Calendar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function Calendar(
101101

102102
const selectColor = useMemo<string>(() => {
103103
if (theme.dark) {
104-
return darkenBy(Color(theme.colors.primary), 0.9).hex()
104+
return darkenBy(Color(theme.colors.primary), 0.1).hex()
105105
}
106106
return lightenBy(Color(theme.colors.primary), 0.9).hex()
107107
}, [theme])

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as React from 'react'
22
import { View, StyleSheet } from 'react-native'
3-
import { IconButton, Text } from 'react-native-paper'
3+
import { IconButton, Text, useTheme } from 'react-native-paper'
44
import type { ModeType } from './Calendar'
55
import type { LocalState } from './DatePickerModalContent'
66
import { useHeaderTextColor } from '../utils'
77
import Color from 'color'
88
import { getTranslation } from '../translations/utils'
9+
import type {
10+
Fonts,
11+
MD3Typescale,
12+
} from 'react-native-paper/lib/typescript/types'
913

1014
export interface HeaderPickProps {
1115
moreLabel?: string
@@ -61,15 +65,22 @@ export default function DatePickerModalContentHeader(
6165
editIcon = 'pencil',
6266
calendarIcon = 'calendar',
6367
} = props
64-
68+
const theme = useTheme()
6569
const label = getLabel(props.locale, props.mode, props.label)
6670

6771
const color = useHeaderTextColor()
6872
const allowEditing = mode !== 'multiple'
73+
74+
let textFont = (theme.fonts as Fonts)?.medium
75+
76+
if (theme.isV3) {
77+
textFont = (theme.fonts as MD3Typescale)?.bodyLarge
78+
}
79+
6980
return (
7081
<View style={[styles.header]}>
7182
<View>
72-
<Text style={[styles.label, { color }]}>
83+
<Text style={[styles.label, { color, ...textFont }]}>
7384
{uppercase ? label.toUpperCase() : label}
7485
</Text>
7586
<View style={styles.headerContentContainer}>

src/Date/DatePickerModalHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default function DatePickerModalHeader(
4242
<Appbar.Content title={''} />
4343
<Button
4444
color={color}
45+
textColor={color}
4546
onPress={props.onSave}
4647
disabled={props.saveLabelDisabled || false}
4748
uppercase={props.uppercase || true}

src/Date/DateRangeInput.tsx

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/Date/Day.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import * as React from 'react'
2-
import { MD3DarkTheme, Text, TouchableRipple } from 'react-native-paper'
2+
import { Theme, Text, TouchableRipple } from 'react-native-paper'
33
import { StyleSheet, View } from 'react-native'
44
import DayRange from './DayRange'
55
import { daySize } from './dateUtils'
6+
import type {
7+
Fonts,
8+
MD3Typescale,
9+
} from 'react-native-paper/lib/typescript/types'
610

711
function EmptyDayPure() {
812
return <View style={styles.empty} />
913
}
1014
export const EmptyDay = React.memo(EmptyDayPure)
1115

1216
function Day(props: {
13-
theme: typeof MD3DarkTheme
17+
theme: Theme
1418
textColorOnPrimary: string
1519
day: number
1620
month: number
@@ -41,7 +45,6 @@ function Day(props: {
4145
textColorOnPrimary,
4246
theme,
4347
} = props
44-
// console.log(month, { day })
4548
const onPress = React.useCallback(() => {
4649
onPressDate(new Date(year, month, day))
4750
}, [onPressDate, year, month, day])
@@ -55,6 +58,12 @@ function Day(props: {
5558
const textColor =
5659
selected || (inRange && theme.dark) ? textColorOnPrimary : undefined
5760

61+
let textFont = (theme.fonts as Fonts)?.medium
62+
63+
if (theme.isV3) {
64+
textFont = (theme.fonts as MD3Typescale)?.bodyMedium
65+
}
66+
5867
return (
5968
<View style={[styles.root, disabled && styles.disabled]}>
6069
<DayRange
@@ -83,7 +92,10 @@ function Day(props: {
8392
]}
8493
>
8594
<Text
86-
style={textColor ? { color: textColor } : undefined}
95+
style={[
96+
textColor ? { color: textColor } : undefined,
97+
{ ...textFont },
98+
]}
8799
selectable={false}
88100
>
89101
{day}

src/Date/DayName.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import * as React from 'react'
22
import { StyleSheet, View } from 'react-native'
3-
import { Text, useTheme } from 'react-native-paper'
3+
import { Text, Theme, useTheme } from 'react-native-paper'
4+
import type {
5+
Fonts,
6+
MD3Typescale,
7+
} from 'react-native-paper/lib/typescript/types'
48

59
function DayName({ label }: { label: string }) {
6-
const theme = useTheme()
10+
const theme: Theme = useTheme()
11+
12+
let textFont = (theme.fonts as Fonts)?.medium
13+
14+
if (theme.isV3) {
15+
textFont = (theme.fonts as MD3Typescale)?.bodyMedium
16+
}
17+
718
return (
819
<View style={styles.dayName}>
9-
<Text
10-
style={[styles.dayNameLabel, theme.fonts.medium]}
11-
selectable={false}
12-
>
20+
<Text style={[styles.dayNameLabel, { ...textFont }]} selectable={false}>
1321
{label}
1422
</Text>
1523
</View>

src/Date/Month.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import type {
2929
} from './Calendar'
3030
import { dayNamesHeight } from './DayNames'
3131
import { useTextColorOnPrimary } from '../utils'
32+
import type {
33+
Fonts,
34+
MD3Typescale,
35+
} from 'react-native-paper/lib/typescript/types'
3236

3337
interface BaseMonthProps {
3438
locale: undefined | string
@@ -244,6 +248,12 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
244248
date,
245249
])
246250

251+
let textFont = (theme.fonts as Fonts)?.medium
252+
253+
if (theme.isV3) {
254+
textFont = (theme.fonts as MD3Typescale)?.bodyMedium
255+
}
256+
247257
return (
248258
<View style={[styles.month, { height: getMonthHeight(scrollMode, index) }]}>
249259
<View
@@ -278,7 +288,7 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
278288
]}
279289
>
280290
<Text
281-
style={[styles.monthLabel, theme.fonts.medium]}
291+
style={[styles.monthLabel, { ...textFont }]}
282292
selectable={false}
283293
>
284294
{monthName} {year}

src/Date/Swiper.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ function VerticalScroller({
157157
right: 0,
158158
position: 'absolute',
159159
height: getMonthHeight('vertical', visibleIndexes[vi]),
160-
// transform: `translateY(${getMonthsOffset('vertical', vi)}px)`,
161160
}}
162161
>
163162
{renderItem({

src/Date/YearPicker.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as React from 'react'
22
import { FlatList, StyleSheet, View } from 'react-native'
33
import { Text, TouchableRipple, useTheme } from 'react-native-paper'
4+
import type {
5+
Fonts,
6+
MD3Typescale,
7+
} from 'react-native-paper/lib/typescript/types'
48
import { range } from '../utils'
59

610
const ITEM_HEIGHT = 62
@@ -20,7 +24,10 @@ export default function YearPicker({
2024
}) {
2125
const theme = useTheme()
2226
const flatList = React.useRef<FlatList<number> | null>(null)
23-
const years = range(isNaN(startYear) ? 1800 : startYear, isNaN(endYear) ? 2200 : endYear)
27+
const years = range(
28+
isNaN(startYear) ? 1800 : startYear,
29+
isNaN(endYear) ? 2200 : endYear
30+
)
2431

2532
// scroll to selected year
2633
React.useEffect(() => {
@@ -31,7 +38,7 @@ export default function YearPicker({
3138
animated: false,
3239
})
3340
}
34-
}, [flatList, selectedYear])
41+
}, [flatList, selectedYear, startYear])
3542

3643
return (
3744
<View
@@ -71,6 +78,13 @@ function YearPure({
7178
onPressYear: (newYear: number) => any
7279
}) {
7380
const theme = useTheme()
81+
82+
let textFont = (theme.fonts as Fonts)?.medium
83+
84+
if (theme.isV3) {
85+
textFont = (theme.fonts as MD3Typescale)?.bodyLarge
86+
}
87+
7488
return (
7589
<View style={styles.year}>
7690
<TouchableRipple
@@ -86,7 +100,11 @@ function YearPure({
86100
]}
87101
>
88102
<Text
89-
style={[styles.yearLabel, selected ? styles.selectedYear : null]}
103+
style={[
104+
styles.yearLabel,
105+
selected ? styles.selectedYear : null,
106+
{ ...textFont },
107+
]}
90108
selectable={false}
91109
>
92110
{year}

0 commit comments

Comments
 (0)