Skip to content

Commit 34bed5b

Browse files
committed
Time works.
1 parent 8204373 commit 34bed5b

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

src/Time/AmPmSwitcher.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ export default function AmPmSwitcher({
1818
onChange: (newHours: number) => any
1919
}) {
2020
const { setMode, mode } = React.useContext(DisplayModeContext)
21-
const theme: Theme = useTheme()
21+
const theme = useTheme()
2222
const backgroundColor = useMemo<string>(() => {
2323
if (theme.dark) {
2424
return Color(theme.colors.surface).lighten(1.2).hex()
2525
}
26-
return Color(theme.colors.surface).darken(0.1).hex()
26+
return Color(
27+
theme.isV3 ? theme.colors.inverseOnSurface : theme.colors.surface
28+
)
29+
.darken(0.1)
30+
.hex()
2731
}, [theme])
2832

2933
const isAM = mode === 'AM'
@@ -100,7 +104,6 @@ function SwitchButton({
100104
<View style={[styles.switchButtonInner, { backgroundColor }]}>
101105
<Text
102106
selectable={false}
103-
variant="bodyMedium"
104107
style={[
105108
{
106109
...textFont,

src/Time/AnalogClock.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ function AnalogClock({
129129
{
130130
backgroundColor: theme.dark
131131
? Color(theme.colors.surface).lighten(1.2).hex()
132+
: theme.isV3
133+
? Color(theme.colors.outline).lighten(0.9).hex()
132134
: Color(theme.colors.surface).darken(0.1).hex(),
133135
},
134136
]}

src/Time/TimeInputs.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import TimeInput from './TimeInput'
2121
import AmPmSwitcher from './AmPmSwitcher'
2222
import { useLatest } from '../utils'
23+
import Color from 'color'
2324

2425
function TimeInputs({
2526
hours,
@@ -85,6 +86,11 @@ function TimeInputs({
8586
pressed={focused === clockTypes.hours}
8687
onPress={onFocusInput}
8788
inputType={inputType}
89+
selectionColor={
90+
theme.dark
91+
? Color(theme.colors.primary).darken(0.2).hex()
92+
: theme.colors.primary
93+
}
8894
returnKeyType={'next'}
8995
onSubmitEditing={onSubmitStartInput}
9096
blurOnSubmit={false}
@@ -98,7 +104,6 @@ function TimeInputs({
98104
minutes,
99105
})
100106
}}
101-
// onChangeText={onChangeStartInput}
102107
/>
103108
<View style={styles.hoursAndMinutesSeparator}>
104109
<View style={styles.spaceDot} />
@@ -115,6 +120,11 @@ function TimeInputs({
115120
pressed={focused === clockTypes.minutes}
116121
onPress={onFocusInput}
117122
inputType={inputType}
123+
selectionColor={
124+
theme.dark
125+
? Color(theme.colors.primary).darken(0.2).hex()
126+
: theme.colors.primary
127+
}
118128
onSubmitEditing={onSubmitEndInput}
119129
onChanged={(newMinutesFromInput) => {
120130
let newMinutes = newMinutesFromInput

src/Time/TimePicker.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ const styles = StyleSheet.create({
117117
justifyContent: 'center',
118118
width: 24 * 3 + 96 * 2 + 52 + circleSize,
119119
},
120-
rootPortrait: {},
120+
rootPortrait: {
121+
alignItems: 'center',
122+
justifyContent: 'center',
123+
},
121124
clockContainer: { paddingTop: 36, paddingLeft: 12, paddingRight: 12 },
122125
})
123126

src/Time/TimePickerModal.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
} from 'react-native'
1111

1212
import { Button, IconButton, overlay, useTheme } from 'react-native-paper'
13+
import type {
14+
Fonts,
15+
MD3Typescale,
16+
} from 'react-native-paper/lib/typescript/types'
1317
import TimePicker from './TimePicker'
1418
import {
1519
clockTypes,
@@ -59,6 +63,12 @@ export function TimePickerModal({
5963
}) {
6064
const theme = useTheme()
6165

66+
let textFont = (theme.fonts as Fonts)?.medium
67+
68+
if (theme.isV3) {
69+
textFont = (theme.fonts as MD3Typescale)?.bodyMedium
70+
}
71+
6272
const [inputType, setInputType] = React.useState<PossibleInputTypes>(
6373
inputTypes.picker
6474
)
@@ -114,7 +124,7 @@ export function TimePickerModal({
114124
style={[
115125
StyleSheet.absoluteFill,
116126
styles.modalBackground,
117-
{ backgroundColor: theme.colors.backdrop },
127+
{ backgroundColor: theme.colors?.backdrop },
118128
]}
119129
/>
120130
</TouchableWithoutFeedback>
@@ -139,7 +149,17 @@ export function TimePickerModal({
139149
]}
140150
>
141151
<View style={styles.labelContainer}>
142-
<Text style={[styles.label, { color: theme.colors.text }]}>
152+
<Text
153+
style={[
154+
styles.label,
155+
{
156+
...textFont,
157+
color: theme?.isV3
158+
? theme.colors.onBackground
159+
: theme.colors.text,
160+
},
161+
]}
162+
>
143163
{uppercase ? label.toUpperCase() : label}
144164
</Text>
145165
</View>
@@ -225,6 +245,7 @@ const styles = StyleSheet.create({
225245
justifyContent: 'flex-end',
226246
paddingLeft: 24,
227247
paddingRight: 24,
248+
marginTop: 8,
228249
},
229250
label: {
230251
letterSpacing: 1,

src/Time/timeUtils.ts

Lines changed: 27 additions & 6 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 { Theme, useTheme } from 'react-native-paper'
3+
import { useTheme } from 'react-native-paper'
44

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

159159
export function useSwitchColors(highlighted: boolean) {
160-
const theme: Theme = useTheme()
161-
160+
const theme = useTheme()
162161
const backgroundColor = React.useMemo<string>(() => {
163162
if (theme.dark) {
164163
if (highlighted) {
165164
return Color(theme.colors.primary).hex()
166165
}
166+
if (theme.isV3) {
167+
return Color(theme.colors.surface).lighten(1.2).hex()
168+
}
167169
return theme.colors.backdrop
168170
}
169171

170172
if (highlighted) {
173+
if (theme.isV3) {
174+
return theme.colors.primaryContainer
175+
}
176+
171177
return Color(theme.colors.primary).lighten(1).hex()
172178
}
173179
return theme.colors.surface
@@ -177,9 +183,11 @@ export function useSwitchColors(highlighted: boolean) {
177183
if (highlighted && !theme.dark) {
178184
return theme.colors.primary
179185
}
180-
186+
if (highlighted && theme.dark) {
187+
return theme.colors.background
188+
}
181189
if (theme.isV3) {
182-
return theme.colors.primary
190+
return theme.colors.onSurfaceVariant
183191
} else {
184192
return theme.colors.placeholder
185193
}
@@ -199,16 +207,29 @@ export function useInputColors(highlighted: boolean) {
199207
}
200208

201209
if (highlighted) {
210+
if (theme.isV3) {
211+
return Color(theme.colors.primaryContainer).hex()
212+
}
202213
return Color(theme.colors.primary).lighten(1).hex()
203214
}
215+
if (theme.isV3) {
216+
return Color(theme.colors.outline).lighten(0.9).hex()
217+
}
204218
return Color(theme.colors.surface).darken(0.1).hex()
205219
}, [highlighted, theme])
206220

207221
const color = React.useMemo<string>(() => {
208222
if (highlighted && !theme.dark) {
209223
return theme.colors.primary
210224
}
211-
return theme.colors.text
225+
if (theme.isV3) {
226+
if (!highlighted) {
227+
return theme.colors.onBackground
228+
}
229+
return theme.colors.background
230+
} else {
231+
return theme.colors.text
232+
}
212233
}, [highlighted, theme])
213234

214235
return { backgroundColor, color }

0 commit comments

Comments
 (0)