11import Color from 'color'
22import {
33 GestureResponderEvent ,
4- LayoutChangeEvent ,
54 PanResponder ,
65 StyleSheet ,
76 View ,
@@ -18,7 +17,7 @@ import {
1817 PossibleClockTypes ,
1918} from './timeUtils'
2019import * as React from 'react'
21- import { useCallback } from 'react'
20+
2221import { useLatest } from '../utils'
2322import AnalogClockHours from './AnalogClockHours'
2423
@@ -55,8 +54,6 @@ function AnalogClock({
5554 const shortPointer = ( hours === 0 || hours > 12 ) && is24Hour
5655
5756 const clockRef = React . useRef < View | null > ( null )
58- const elementX = React . useRef < number > ( 0 )
59- const elementY = React . useRef < number > ( 0 )
6057
6158 // Hooks are nice, sometimes... :-)..
6259 // We need the latest values, since the onPointerMove uses a closure to the function
@@ -68,10 +65,11 @@ function AnalogClock({
6865
6966 const onPointerMove = React . useCallback (
7067 ( e : GestureResponderEvent , final : boolean ) => {
71- let x = e . nativeEvent . pageX - elementX . current
72- let y = e . nativeEvent . pageY - elementY . current
68+ let x = e . nativeEvent . locationX
69+ let y = e . nativeEvent . locationY
7370
7471 let angle = getAngle ( x , y , circleSize )
72+
7573 if ( focusedRef . current === clockTypes . hours ) {
7674 let hours24 = is24HourRef . current
7775 let previousHourType = getHourType ( hoursRef . current )
@@ -107,15 +105,7 @@ function AnalogClock({
107105 }
108106 }
109107 } ,
110- [
111- focusedRef ,
112- is24HourRef ,
113- hoursRef ,
114- onChangeRef ,
115- minutesRef ,
116- elementX ,
117- elementY ,
118- ]
108+ [ focusedRef , is24HourRef , hoursRef , onChangeRef , minutesRef ]
119109 )
120110
121111 const panResponder = React . useRef (
@@ -133,27 +123,12 @@ function AnalogClock({
133123 } )
134124 ) . current
135125
136- const onLayout = useCallback (
137- ( _ : LayoutChangeEvent ) => {
138- if ( ! clockRef . current ) {
139- return
140- }
141-
142- clockRef . current . measureInWindow ( ( x , y ) => {
143- elementX . current = x
144- elementY . current = y
145- } )
146- } ,
147- [ elementX , elementY ]
148- )
149-
150126 const dynamicSize = focused === clockTypes . hours && shortPointer ? 33 : 0
151127 const pointerNumber = focused === clockTypes . hours ? hours : minutes
152128 const degreesPerNumber = focused === clockTypes . hours ? 30 : 6
153129 return (
154130 < View
155131 ref = { clockRef }
156- onLayout = { onLayout }
157132 { ...panResponder . panHandlers }
158133 style = { [
159134 styles . clock ,
0 commit comments