import * as React from 'react' import { View, StyleSheet } from 'react-native' import { MD2Theme, Text, TouchableRipple, useTheme } from 'react-native-paper' import { useMemo } from 'react' import Color from 'color' import { inputTypes, PossibleInputTypes, useSwitchColors } from './timeUtils' import { DisplayModeContext } from './TimePicker' export default function AmPmSwitcher({ onChange, hours, inputType, }: { hours: number onChange: (newHours: number) => any inputType: PossibleInputTypes }) { const { setMode, mode } = React.useContext(DisplayModeContext) const theme = useTheme() const backgroundColor = useMemo(() => { if (theme.isV3) { return theme.colors.outline } return Color( theme.dark ? Color(theme.colors.surface).lighten(1.2).hex() : theme.colors.surface ) .darken(0.1) .hex() }, [theme]) const isAM = mode === 'AM' return ( { setMode('AM') if (hours - 12 >= 0) { onChange(hours - 12) } }} selected={isAM} disabled={isAM} /> { setMode('PM') if (hours + 12 <= 24) { onChange(hours + 12) } }} selected={!isAM} disabled={!isAM} /> ) } function SwitchButton({ label, onPress, selected, disabled, }: { label: string onPress: (() => any) | undefined selected: boolean disabled: boolean }) { const theme = useTheme() const { backgroundColor, color } = useSwitchColors(selected) let textFont = theme?.isV3 ? theme.fonts.titleMedium : (theme as any as MD2Theme).fonts.medium return ( {label} ) } const styles = StyleSheet.create({ root: { width: 52, borderWidth: 1, overflow: 'hidden', }, switchSeparator: { height: 1, width: 52, }, switchButton: { flex: 1, }, switchButtonInner: { flex: 1, alignItems: 'center', justifyContent: 'center', }, })