From 03b3d93bfce8ae638656ff7a1d7d3d0baac6290c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 May 2017 13:19:38 +0530 Subject: [PATCH] Fix pinch to change font size not working on Safari --- src/pyj/read_book/touch.pyj | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pyj/read_book/touch.pyj b/src/pyj/read_book/touch.pyj index f522833026..176a4be4e1 100644 --- a/src/pyj/read_book/touch.pyj +++ b/src/pyj/read_book/touch.pyj @@ -109,6 +109,11 @@ def tap_on_link(gesture): return False +def touch_id(touch): + # On Safari using touch.identifier as dict key yields a key of "NaN" for some reason + return touch.identifier + '' + + class TouchHandler: def __init__(self): @@ -162,7 +167,7 @@ class TouchHandler: ev.preventDefault(), ev.stopPropagation() self.prune_expired_touches() for touch in ev.changedTouches: - self.ongoing_touches[touch.identifier] = copy_touch(touch) + self.ongoing_touches[touch_id(touch)] = copy_touch(touch) if self.gesture_id is None: nonlocal gesture_id gesture_id += 1 @@ -180,7 +185,7 @@ class TouchHandler: def handle_touchmove(self, ev): ev.preventDefault(), ev.stopPropagation() for touch in ev.changedTouches: - t = self.ongoing_touches[touch.identifier] + t = self.ongoing_touches[touch_id(touch)] if t: self.update_touch(t, touch) self.dispatch_gesture() @@ -188,7 +193,7 @@ class TouchHandler: def handle_touchend(self, ev): ev.preventDefault(), ev.stopPropagation() for touch in ev.changedTouches: - t = self.ongoing_touches[touch.identifier] + t = self.ongoing_touches[touch_id(touch)] if t: t.active = False self.update_touch(t, touch)