Skip to content

Commit 8204373

Browse files
committed
Quick AmPmSwitcher test.
1 parent 13d1cef commit 8204373

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/Date/AnimatedCrossView.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,24 @@ import { Animated, StyleSheet, View } from 'react-native'
33
import { useTheme } from 'react-native-paper'
44

55
export default function AnimatedCrossView({
6-
// visible,
76
collapsed,
87
calendar,
98
calendarEdit,
109
}: {
1110
calendar: any
1211
calendarEdit: any
13-
// visible: boolean
1412
collapsed: boolean
1513
}) {
1614
const theme = useTheme()
1715
const calendarOpacity = React.useRef<Animated.Value>(
1816
new Animated.Value(collapsed ? 1 : 0)
1917
)
2018
React.useEffect(() => {
21-
// if (visible) {
2219
Animated.timing(calendarOpacity.current, {
2320
toValue: collapsed ? 1 : 0,
2421
duration: 250,
2522
useNativeDriver: true,
2623
}).start()
27-
// }
2824
}, [collapsed])
2925

3026
return (

src/Date/Calendar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type BaseCalendarProps = {
3434
startYear?: number
3535
endYear?: number
3636

37-
// here they are optional but in final implemenation they are required
37+
// here they are optional but in final implementation they are required
3838
date?: CalendarDate
3939
dates?: CalendarDates
4040
startDate?: CalendarDate

src/Time/AmPmSwitcher.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import * as React from 'react'
22
import { View, StyleSheet } from 'react-native'
3-
import { Text, TouchableRipple, useTheme } from 'react-native-paper'
3+
import { Text, Theme, TouchableRipple, useTheme } from 'react-native-paper'
44
import { useMemo } from 'react'
55
import Color from 'color'
66
import { useSwitchColors } from './timeUtils'
77
import { DisplayModeContext } from './TimePicker'
8+
import type {
9+
Fonts,
10+
MD3Typescale,
11+
} from 'react-native-paper/lib/typescript/types'
812

913
export default function AmPmSwitcher({
1014
onChange,
@@ -14,7 +18,7 @@ export default function AmPmSwitcher({
1418
onChange: (newHours: number) => any
1519
}) {
1620
const { setMode, mode } = React.useContext(DisplayModeContext)
17-
const theme = useTheme()
21+
const theme: Theme = useTheme()
1822
const backgroundColor = useMemo<string>(() => {
1923
if (theme.dark) {
2024
return Color(theme.colors.surface).lighten(1.2).hex()
@@ -71,9 +75,15 @@ function SwitchButton({
7175
selected: boolean
7276
disabled: boolean
7377
}) {
74-
const theme = useTheme()
78+
const theme: Theme = useTheme()
7579
const { backgroundColor, color } = useSwitchColors(selected)
7680

81+
let textFont = (theme.fonts as Fonts)?.medium
82+
83+
if (theme.isV3) {
84+
textFont = (theme.fonts as MD3Typescale)?.bodyMedium
85+
}
86+
7787
return (
7888
<TouchableRipple
7989
onPress={onPress}
@@ -90,9 +100,10 @@ function SwitchButton({
90100
<View style={[styles.switchButtonInner, { backgroundColor }]}>
91101
<Text
92102
selectable={false}
103+
variant="bodyMedium"
93104
style={[
94105
{
95-
...theme.fonts.medium,
106+
...textFont,
96107
color: color,
97108
},
98109
]}

src/Time/timeUtils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import Color from 'color'
3-
import { useTheme } from 'react-native-paper'
3+
import { Theme, useTheme } from 'react-native-paper'
44

55
// 250? when bigger?
66
export const circleSize = 215
@@ -157,7 +157,8 @@ export function getAngle(left: number, top: number, size: number) {
157157
}
158158

159159
export function useSwitchColors(highlighted: boolean) {
160-
const theme = useTheme()
160+
const theme: Theme = useTheme()
161+
161162
const backgroundColor = React.useMemo<string>(() => {
162163
if (theme.dark) {
163164
if (highlighted) {
@@ -176,7 +177,12 @@ export function useSwitchColors(highlighted: boolean) {
176177
if (highlighted && !theme.dark) {
177178
return theme.colors.primary
178179
}
179-
return theme.colors.placeholder
180+
181+
if (theme.isV3) {
182+
return theme.colors.primary
183+
} else {
184+
return theme.colors.placeholder
185+
}
180186
}, [highlighted, theme])
181187

182188
return { backgroundColor, color }

0 commit comments

Comments
 (0)