@@ -11,8 +11,10 @@ import {
1111 clockTypes ,
1212 getAngle ,
1313 getHours ,
14+ getHourType ,
15+ getHourTypeFromOffset ,
1416 getMinutes ,
15- isPM ,
17+ hourTypes ,
1618 PossibleClockTypes ,
1719} from './timeUtils'
1820import * as React from 'react'
@@ -23,6 +25,7 @@ import AnalogClockHours from './AnalogClockHours'
2325import AnimatedClockSwitcher from './AnimatedClockSwitcher'
2426import AnalogClockMinutes from './AnalogClockMinutes'
2527
28+ // 250? when bigger?
2629export const circleSize = 215
2730
2831function AnalogClock ( {
@@ -48,11 +51,14 @@ function AnalogClock({
4851} ) {
4952 const theme = useTheme ( )
5053
54+ // used to make pointer shorter if hours are selected and above 12
55+ const shortPointer = hours > 12 && is24Hour
56+
5157 const clockRef = React . useRef < View | null > ( null )
5258 const elementX = React . useRef < number > ( 0 )
5359 const elementY = React . useRef < number > ( 0 )
5460
55- // Hooks are nice, sometimes :-)..
61+ // Hooks are nice, sometimes... :-)..
5662 // We need the latest values, since the onPointerMove uses a closure to the function
5763 const hoursRef = useLatest ( hours )
5864 const onChangeRef = useLatest ( onChange )
@@ -67,8 +73,15 @@ function AnalogClock({
6773
6874 let angle = getAngle ( x , y , circleSize )
6975 if ( focusedRef . current === clockTypes . hours ) {
70- let pickedHours = getHours ( angle )
71- if ( is24HourRef . current && isPM ( x , y , circleSize ) ) {
76+ let previousHourType = getHourType ( hoursRef . current )
77+ let pickedHours = getHours ( angle , previousHourType )
78+
79+ // TODO: check which mode is switched on am/pm
80+ if (
81+ ( is24HourRef . current &&
82+ getHourTypeFromOffset ( x , y , circleSize ) === hourTypes . pm ) ||
83+ ( ! is24HourRef . current && previousHourType === hourTypes . pm )
84+ ) {
7285 pickedHours += 12
7386 }
7487 if ( hoursRef . current !== pickedHours || final ) {
@@ -120,8 +133,7 @@ function AnalogClock({
120133 [ elementX , elementY ]
121134 )
122135
123- // used to make pointer shorter if hours are selected and above 12
124- const dynamicSize = focused === clockTypes . hours && hours > 12 ? 33 : 0
136+ const dynamicSize = focused === clockTypes . hours && shortPointer ? 33 : 0
125137 const pointerNumber = focused === clockTypes . hours ? hours : minutes
126138 const degreesPerNumber = focused === clockTypes . hours ? 30 : 6
127139 return (
0 commit comments