@@ -12,18 +12,17 @@ import {
1212 getAngle ,
1313 getHours ,
1414 getHourType ,
15+ getHourTypeFromOffset ,
1516 getMinutes ,
17+ hourTypes ,
1618 PossibleClockTypes ,
1719} from './timeUtils'
1820import * as React from 'react'
19-
2021import { useLatest } from '../utils'
2122import AnalogClockHours from './AnalogClockHours'
22-
2323import AnimatedClockSwitcher from './AnimatedClockSwitcher'
2424import AnalogClockMinutes from './AnalogClockMinutes'
2525import { DisplayModeContext } from './TimePicker'
26-
2726function AnalogClock ( {
2827 hours,
2928 minutes,
@@ -45,9 +44,7 @@ function AnalogClock({
4544 const { mode } = React . useContext ( DisplayModeContext )
4645 // used to make pointer shorter if hours are selected and above 12
4746 const shortPointer = ( hours === 0 || hours > 12 ) && is24Hour
48-
4947 const clockRef = React . useRef < View | null > ( null )
50-
5148 // Hooks are nice, sometimes... :-)..
5249 // We need the latest values, since the onPointerMove uses a closure to the function
5350 const hoursRef = useLatest ( hours )
@@ -56,31 +53,35 @@ function AnalogClock({
5653 const focusedRef = useLatest ( focused )
5754 const is24HourRef = useLatest ( is24Hour )
5855 const modeRef = useLatest ( mode )
59-
6056 const onPointerMove = React . useCallback (
6157 ( e : GestureResponderEvent , final : boolean ) => {
6258 let x = e . nativeEvent . locationX
6359 let y = e . nativeEvent . locationY
64-
6560 let angle = getAngle ( x , y , circleSize )
66-
6761 if ( focusedRef . current === clockTypes . hours ) {
6862 let hours24 = is24HourRef . current
6963 let previousHourType = getHourType ( hoursRef . current )
7064 let pickedHours = getHours ( angle , previousHourType )
7165
72- let hours12AndPm = ! hours24 && modeRef . current === 'PM'
66+ let hours12AndPm = ! hours24 && modeRef . current === 'AM'
67+
68+ let hourTypeFromOffset = getHourTypeFromOffset ( x , y , circleSize )
69+ let hours24AndPM = hours24 && hourTypeFromOffset === hourTypes . pm
7370
7471 // Avoiding the "24h"
7572 // Should be 12h for 12 hours and PM mode
76- if ( ( hours12AndPm || hours24 ) && pickedHours + 12 < 24 ) {
73+
74+ if ( hours12AndPm || hours24AndPM ) {
7775 pickedHours += 12
7876 }
7977 if ( modeRef . current === 'AM' && pickedHours === 12 ) {
8078 pickedHours = 0
8179 }
8280
83- if ( pickedHours === 24 ) {
81+ if (
82+ ( ! hours24 && modeRef . current === 'AM' && pickedHours === 12 ) ||
83+ pickedHours === 24
84+ ) {
8485 pickedHours = 0
8586 }
8687
@@ -103,13 +104,11 @@ function AnalogClock({
103104 } ,
104105 [ focusedRef , is24HourRef , hoursRef , onChangeRef , minutesRef , modeRef ]
105106 )
106-
107107 const panResponder = React . useRef (
108108 PanResponder . create ( {
109109 onPanResponderGrant : ( e ) => onPointerMove ( e , false ) ,
110110 onPanResponderMove : ( e ) => onPointerMove ( e , false ) ,
111111 onPanResponderRelease : ( e ) => onPointerMove ( e , true ) ,
112-
113112 onStartShouldSetPanResponder : returnTrue ,
114113 onStartShouldSetPanResponderCapture : ( ) => false ,
115114 onMoveShouldSetPanResponder : returnTrue ,
@@ -118,7 +117,6 @@ function AnalogClock({
118117 onShouldBlockNativeResponder : returnTrue ,
119118 } )
120119 ) . current
121-
122120 const dynamicSize = focused === clockTypes . hours && shortPointer ? 33 : 0
123121 const pointerNumber = focused === clockTypes . hours ? hours : minutes
124122 const degreesPerNumber = focused === clockTypes . hours ? 30 : 6
@@ -178,7 +176,6 @@ function AnalogClock({
178176 </ View >
179177 )
180178}
181-
182179const styles = StyleSheet . create ( {
183180 clock : {
184181 height : circleSize ,
@@ -204,15 +201,12 @@ const styles = StyleSheet.create({
204201 } ,
205202 line : {
206203 position : 'absolute' ,
207-
208204 marginBottom : - 1 ,
209205 height : 2 ,
210206 borderRadius : 4 ,
211207 } ,
212208} )
213-
214209function returnTrue ( ) {
215210 return true
216211}
217-
218212export default React . memo ( AnalogClock )
0 commit comments