Skip to content

Commit b26e96f

Browse files
authored
refactor: drop support for material 2 (#513)
1 parent 4f61c2e commit b26e96f

17 files changed

Lines changed: 87 additions & 308 deletions

example/src/App.tsx

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import {
2222
Provider as PaperProvider,
2323
MD3DarkTheme,
2424
MD3LightTheme,
25-
MD2DarkTheme,
26-
MD2LightTheme,
2725
} from 'react-native-paper'
2826
import {
2927
DatePickerModal,
@@ -102,13 +100,7 @@ locales.forEach((locale) => {
102100
registerTranslation(locale[0], locale[1])
103101
})
104102

105-
function Example({
106-
materialYouEnabled,
107-
setMaterialYouEnabled,
108-
}: {
109-
materialYouEnabled: boolean
110-
setMaterialYouEnabled: (enabled: boolean) => void
111-
}) {
103+
function Example() {
112104
const theme = useTheme()
113105
const insets = useSafeAreaInsets()
114106

@@ -294,32 +286,6 @@ function Example({
294286
View documentation
295287
</Button>
296288
</View>
297-
<Divider style={styles.marginVerticalEight} />
298-
<Text
299-
maxFontSizeMultiplier={maxFontSizeMultiplier}
300-
style={[styles.marginVerticalEight, styles.bold]}
301-
>
302-
Material theme
303-
</Text>
304-
<View style={styles.chipContainer}>
305-
<Chip
306-
compact
307-
selected={materialYouEnabled}
308-
onPress={() => setMaterialYouEnabled(true)}
309-
style={styles.chip}
310-
>
311-
Material You
312-
</Chip>
313-
<Chip
314-
compact
315-
selected={!materialYouEnabled}
316-
onPress={() => setMaterialYouEnabled(false)}
317-
style={styles.chip}
318-
>
319-
Material Design 2
320-
</Chip>
321-
</View>
322-
323289
<Divider style={styles.marginVerticalEight} />
324290
<Text
325291
maxFontSizeMultiplier={maxFontSizeMultiplier}
@@ -585,19 +551,14 @@ function Example({
585551

586552
export default function App() {
587553
const colorScheme = useColorScheme()
588-
const [materialYouEnabled, setMaterialYouEnabled] = useState(true)
589-
const m3Theme = colorScheme === 'dark' ? MD3DarkTheme : MD3LightTheme
590-
const m2Theme = colorScheme === 'dark' ? MD2DarkTheme : MD2LightTheme
554+
const theme = colorScheme === 'dark' ? MD3DarkTheme : MD3LightTheme
591555

592556
return (
593557
<SafeAreaProvider>
594-
<PaperProvider theme={materialYouEnabled ? m3Theme : m2Theme}>
558+
<PaperProvider theme={theme}>
595559
<StatusBar style="auto" />
596560

597-
<Example
598-
materialYouEnabled={materialYouEnabled}
599-
setMaterialYouEnabled={setMaterialYouEnabled}
600-
/>
561+
<Example />
601562
</PaperProvider>
602563
</SafeAreaProvider>
603564
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.22.57",
2+
"version": "0.23.0",
33
"author": "Richard Lindhout <info@webridge.nl> (https://github.com/web-ridge)",
44
"bugs": {
55
"url": "https://github.com/web-ridge/react-native-paper-dates/issues"

src/Date/Calendar.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import {
1010
} from './dateUtils'
1111

1212
import CalendarHeader from './CalendarHeader'
13-
import { memo, useCallback, useMemo, useState } from 'react'
13+
import { memo, useCallback, useState } from 'react'
1414
import YearPicker from './YearPicker'
15-
import Color from 'color'
1615
import { useTheme } from 'react-native-paper'
17-
import { darkenBy, lightenBy, useLatest } from '../shared/utils'
16+
import { useLatest } from '../shared/utils'
1817
import { sharedStyles } from '../shared/styles'
1918
import { defaultStartYear, defaultEndYear } from './dateUtils'
2019

@@ -162,15 +161,7 @@ function Calendar(
162161
[mode, dateMode, onChangeRef, startDateRef, endDateRef, datesRef]
163162
)
164163

165-
const selectColor = useMemo<string>(() => {
166-
if (theme.isV3) {
167-
return theme.colors.primaryContainer
168-
}
169-
if (theme.dark) {
170-
return darkenBy(Color(theme.colors.primary), 0.1).hex()
171-
}
172-
return lightenBy(Color(theme.colors.primary), 0.9).hex()
173-
}, [theme])
164+
const selectColor = theme.colors.primaryContainer
174165

175166
return (
176167
<View style={sharedStyles.root}>

src/Date/DatePickerModalContent.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import DatePickerModalContentHeader, {
1515
} from './DatePickerModalContentHeader'
1616
import CalendarEdit from './CalendarEdit'
1717
import DatePickerModalHeaderBackground from './DatePickerModalHeaderBackground'
18-
import { useTheme } from 'react-native-paper'
1918
import DatePickerModalStatusBar from './DatePickerModalStatusBar'
2019
import { memo, useCallback, useEffect, useState } from 'react'
2120

@@ -94,9 +93,8 @@ export function DatePickerModalContent(
9493
statusBarOnTopOfBackdrop,
9594
startWeekOnMonday,
9695
} = props
97-
const theme = useTheme()
9896
const anyProps = props as any
99-
const defaultUppercase = !theme.isV3
97+
const defaultUppercase = false
10098

10199
// use local state to add only onConfirm state changes
102100
const [state, setState] = useState<LocalState>({

src/Date/DatePickerModalContentHeader.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StyleSheet, View } from 'react-native'
2-
import { IconButton, MD2Theme, Text, useTheme } from 'react-native-paper'
2+
import { IconButton, Text, useTheme } from 'react-native-paper'
33
import type { ModeType } from './Calendar'
44
import type { LocalState } from './DatePickerModalContent'
55
import { useHeaderTextColor } from '../shared/utils'
@@ -70,14 +70,10 @@ export default function DatePickerModalContentHeader(
7070
const label = getLabel(props.locale, props.mode, props.label)
7171
const color = useHeaderTextColor()
7272
const isEditingEnabled = allowEditing && mode !== 'multiple'
73-
const supportingTextColor = theme.isV3 ? theme.colors.onSurfaceVariant : color
74-
const textFont = theme?.isV3
75-
? theme.fonts.labelMedium
76-
: (theme as any as MD2Theme).fonts.medium
77-
const collapsedIcon = theme.isV3 ? 'pencil-outline' : 'pencil'
78-
const expandedIcon = theme.isV3 ? 'calendar-blank' : 'calendar'
79-
const finalCollapsedIcon = editIcon ?? collapsedIcon
80-
const finalExpandedIcon = calendarIcon ?? expandedIcon
73+
const supportingTextColor = theme.colors.onSurfaceVariant
74+
const textFont = theme.fonts.labelMedium
75+
const finalCollapsedIcon = editIcon ?? 'pencil-outline'
76+
const finalExpandedIcon = calendarIcon ?? 'calendar-blank'
8177

8278
return (
8379
<View style={styles.header}>
@@ -113,7 +109,7 @@ export default function DatePickerModalContentHeader(
113109
? getTranslation(props.locale, 'typeInDate')
114110
: getTranslation(props.locale, 'pickDateFromCalendar')
115111
}
116-
iconColor={theme.isV3 ? theme.colors.onSurface : color}
112+
iconColor={theme.colors.onSurface}
117113
onPress={onToggle}
118114
/>
119115
) : null}
@@ -130,11 +126,7 @@ export function HeaderContentSingle({
130126
const theme = useTheme()
131127

132128
const lighterColor = Color(color).fade(0.5).rgb().toString()
133-
const dateColor = state.date
134-
? theme.isV3
135-
? theme.colors.onSurface
136-
: color
137-
: lighterColor
129+
const dateColor = state.date ? theme.colors.onSurface : lighterColor
138130

139131
const formatter = useMemo(() => {
140132
return new Intl.DateTimeFormat(locale, {
@@ -164,11 +156,7 @@ export function HeaderContentMulti({
164156

165157
const dateCount = state.dates?.length || 0
166158
const lighterColor = Color(color).fade(0.5).rgb().toString()
167-
const dateColor = dateCount
168-
? theme.isV3
169-
? theme.colors.onSurface
170-
: color
171-
: lighterColor
159+
const dateColor = dateCount ? theme.colors.onSurface : lighterColor
172160

173161
const formatter = useMemo(() => {
174162
return new Intl.DateTimeFormat(locale, {
@@ -208,8 +196,8 @@ export function HeaderContentRange({
208196
const theme = useTheme()
209197

210198
const lighterColor = Color(color).fade(0.5).rgb().toString()
211-
const startColorFilled = theme.isV3 ? theme.colors.onSurface : color
212-
const endColorFilled = theme.isV3 ? theme.colors.onSurface : color
199+
const startColorFilled = theme.colors.onSurface
200+
const endColorFilled = theme.colors.onSurface
213201
const startColor = state.startDate ? startColorFilled : lighterColor
214202
const endColor = state.endDate ? endColorFilled : lighterColor
215203

src/Date/DatePickerModalHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function DatePickerModalHeader(
4444
testID="react-native-paper-dates-close"
4545
/>
4646
<Button
47-
textColor={theme.isV3 ? theme.colors.primary : color}
47+
textColor={theme.colors.primary}
4848
onPress={props.onSave}
4949
disabled={props.saveLabelDisabled ?? false}
5050
uppercase={props.uppercase ?? true}

src/Date/Day.tsx

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MD2Theme, Text, TouchableRipple } from 'react-native-paper'
1+
import { Text, TouchableRipple } from 'react-native-paper'
22
import { StyleSheet, View } from 'react-native'
33
import DayRange from './DayRange'
44
import { daySize } from './dateUtils'
@@ -41,54 +41,33 @@ function Day(props: {
4141
selectColor,
4242
isToday,
4343
disabled,
44-
textColorOnPrimary,
4544
theme,
4645
} = props
47-
const borderColorFallback = theme.dark ? '#fff' : '#000'
48-
const selectedOrInRangeDarkMode = selected || (inRange && theme.dark)
49-
const v2BorderColor = selectedOrInRangeDarkMode
50-
? textColorOnPrimary
51-
: borderColorFallback
52-
const borderColor = theme.isV3 ? theme.colors.primary : v2BorderColor
46+
const borderColor = theme.colors.primary
5347

5448
const onPress = useCallback(() => {
5549
onPressDate(new Date(year, month, day))
5650
}, [onPressDate, year, month, day])
5751

58-
// TODO: check if this can be simplified
59-
// converted with Chat-GPT for now from enormous conditional to if-else
52+
// Determine text colors for M3
6053
let baseTextColor
6154
let finalTextColor
6255

63-
if (theme.isV3) {
64-
// Theme V3 specific logic for base text color
65-
if (selected) {
66-
baseTextColor = theme.colors.onPrimary
67-
} else if (inRange && theme.dark) {
68-
baseTextColor = theme.colors.onPrimaryContainer
69-
} else {
70-
baseTextColor = theme.colors.onSurface
71-
}
56+
if (selected) {
57+
baseTextColor = theme.colors.onPrimary
58+
} else if (inRange && theme.dark) {
59+
baseTextColor = theme.colors.onPrimaryContainer
60+
} else {
61+
baseTextColor = theme.colors.onSurface
62+
}
7263

73-
// Theme V3 specific logic for final text color
74-
if (isToday) {
75-
finalTextColor = selected ? baseTextColor : theme.colors.primary
76-
} else {
77-
finalTextColor = baseTextColor
78-
}
64+
if (isToday) {
65+
finalTextColor = selected ? baseTextColor : theme.colors.primary
7966
} else {
80-
// Logic for themes other than V3
81-
if (selected || (inRange && theme.dark)) {
82-
baseTextColor = textColorOnPrimary
83-
}
84-
// Since there's no additional logic provided for non-V3 themes in the step 2,
85-
// the final text color for non-V3 themes will simply be the base text color.
8667
finalTextColor = baseTextColor
8768
}
8869

89-
let textFont = theme?.isV3
90-
? theme.fonts.bodySmall
91-
: (theme as any as MD2Theme).fonts.medium
70+
const textFont = theme.fonts.bodySmall
9271

9372
return (
9473
<View style={[styles.root, disabled && styles.disabled]}>

src/Date/DayName.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { memo } from 'react'
22
import { StyleSheet, View } from 'react-native'
3-
import { MD2Theme, Text, useTheme } from 'react-native-paper'
3+
import { Text, useTheme } from 'react-native-paper'
44

55
function DayName({ label }: { label: string }) {
66
const theme = useTheme()
77

8-
let textFont = theme?.isV3
9-
? theme.fonts.bodySmall
10-
: (theme as any as MD2Theme).fonts.medium
8+
const textFont = theme.fonts.bodySmall
119

1210
return (
1311
<View style={styles.dayName}>

src/Date/Month.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { StyleSheet, View } from 'react-native'
2-
import {
3-
Icon,
4-
MD2Theme,
5-
Text,
6-
TouchableRipple,
7-
useTheme,
8-
} from 'react-native-paper'
2+
import { Icon, Text, TouchableRipple, useTheme } from 'react-native-paper'
93
import Day, { EmptyDay } from './Day'
104

115
import {
@@ -263,17 +257,11 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
263257
endYear,
264258
])
265259

266-
let textFont = theme?.isV3
267-
? theme.fonts.titleSmall
268-
: (theme as any as MD2Theme).fonts.medium
260+
const textFont = theme.fonts.titleSmall
269261

270-
const iconColor = theme.isV3
271-
? theme.colors.onSurfaceVariant
272-
: theme.colors.onSurface
262+
const iconColor = theme.colors.onSurfaceVariant
273263

274-
const iconSourceV3 = selectingYear ? 'menu-up' : 'menu-down'
275-
const iconSourceV2 = selectingYear ? 'chevron-up' : 'chevron-down'
276-
const iconSource = theme.isV3 ? iconSourceV3 : iconSourceV2
264+
const iconSource = selectingYear ? 'menu-up' : 'menu-down'
277265

278266
return (
279267
<View
@@ -324,9 +312,7 @@ function Month(props: MonthSingleProps | MonthRangeProps | MonthMultiProps) {
324312
styles.monthLabel,
325313
{
326314
...textFont,
327-
color: theme.isV3
328-
? theme.colors.onSurfaceVariant
329-
: theme.colors.onSurface,
315+
color: theme.colors.onSurfaceVariant,
330316
},
331317
]}
332318
selectable={false}

src/Date/YearPicker.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FlatList, ScrollView, StyleSheet, View } from 'react-native'
2-
import { MD2Theme, Text, TouchableRipple, useTheme } from 'react-native-paper'
2+
import { Text, TouchableRipple, useTheme } from 'react-native-paper'
33
import { range } from '../shared/utils'
44
import { memo, useEffect, useRef } from 'react'
55
import { sharedStyles } from '../shared/styles'
@@ -81,9 +81,7 @@ function YearPure({
8181
}) {
8282
const theme = useTheme()
8383

84-
let textFont = theme?.isV3
85-
? theme.fonts.bodyLarge
86-
: (theme as any as MD2Theme).fonts.medium
84+
const textFont = theme.fonts.bodyLarge
8785

8886
return (
8987
<View style={styles.year}>
@@ -104,13 +102,8 @@ function YearPure({
104102
style={[
105103
styles.yearLabel,
106104
selected
107-
? // eslint-disable-next-line react-native/no-inline-styles
108-
{ color: theme.isV3 ? theme.colors.onPrimary : '#fff' }
109-
: {
110-
color: theme.isV3
111-
? theme.colors.onSurfaceVariant
112-
: theme.colors.onSurface,
113-
},
105+
? { color: theme.colors.onPrimary }
106+
: { color: theme.colors.onSurfaceVariant },
114107
{ ...textFont },
115108
]}
116109
selectable={false}

0 commit comments

Comments
 (0)