Skip to content

Commit b444a14

Browse files
fix: fix time picker on Android
1 parent 5b74529 commit b444a14

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ function App({
330330
/>
331331

332332
<TimePickerModal
333-
// locale={'en'} optional, default: automatic
333+
locale={'nl'} //optional, default: automatic
334334
visible={timeOpen}
335335
onDismiss={onDismissTime}
336336
onConfirm={onConfirmTime}

src/Time/AnalogClock.tsx

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Color from 'color'
22
import {
33
GestureResponderEvent,
4-
LayoutChangeEvent,
54
PanResponder,
65
StyleSheet,
76
View,
@@ -18,7 +17,7 @@ import {
1817
PossibleClockTypes,
1918
} from './timeUtils'
2019
import * as React from 'react'
21-
import { useCallback } from 'react'
20+
2221
import { useLatest } from '../utils'
2322
import 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

Comments
 (0)