I need to be able to do pinch to zoom to scale font sizes, on both Android and iOS. (Not just a regular image per numerous examples I've seen when Googling). Can someone let me know if theres an easy way to do this in Ionic 3?
- Documentation, infers you can use (pinch). But this never works out of the box.
- I know Ionic uses Hammer.JS under the covers... per this source.
Ionic Forums suggests you can enable it using a combination of
@ViewChild
and manually addinglisten
andon
handler.Then for some reason the event never fires on a Macbook Pro with a touchpad, yet when I upload it to Ionic View event fires when I attempt to do pinch to zoom. I wonder if there's some navigator agent selection that doesn't enable things on the Macbook Pro, because the touchpad should facilitate this?
Update: Maybe you need the touch emulator script to do things on a Macbook Pro. I was also reading here
Safari on iOS has no windows, scroll bars, or resize buttons.... The user pans by flicking a finger. The user zooms in by double-tapping and pinch opening, and zooms out by pinch closing—gestures that are not available for Safari on the desktop. Because of the differences in the way users interact with web content, the viewport on the desktop and on iOS are not the same.
So maybe this may be why Hammer doesn't work on a native Macbook Pro..
When searching on Gestures on the Ionic page you also get this page (Haptic/Taptic - which it infers is iOS dependent).
I also thought there might be a connection to the way the viewport is configured in the index.html. But that appears to be a rabbit hole that's not got a clean solution per this thread and once again this appeared to be iPhone specific.
I've also seen:
Gestures - Patterns on Material.io
This blog post on Pinch to Zoom on Android.
Using an alert on the event with JSON.stringify - you get these sort of properties with pinch to Zoom in the iPhone using similar source to the forum.. I manually typed that in by looking at a iPhone alert.. so there may be the odd typo.. and I omitted a lot of the actual values...
Do people tend to use RxJS debounce with pinch events in order to throttle the rate at which you Zoom In/Out?
{"pointers": [{},{}],
"changedPointers": [{}],
"pointerType": "touch",
"srcEvent":{"isTrusted":true},
"isFirst":false,
"isFinal":false,
"eventType":2
"center":{"x":158, "y":302}
"timeStamp":
"deltaTime":
"angle":
"distance":
"deltaX":,
"deltaY":,
"offsetDirection":,
"overallVelocityX":,
"overallVelocityY":,
"overallVelocity":,
"scale":,
"rotation":,
"maxPointers":,
"velocity":,
"direction":,
"target":,
}
I also think there's an "additionalEvent"
property that can be handy for detecting "pinchout" vs "pinchin".. I seems to double fire.
Whilst that method seems fine on an iPhone (except for multiple events firing)... The Android Samsung Galaxy S4 phone I'm testing on seems to more often than not invert that, and throws up many events. I also subsequently tested on a co-workers Samsung Galaxy S8 which has an up to date browser. I thought I may have needed to package an up to date browser. But I don't think that will solve it either. Without exhaustive testing it looks like Android gives correct answer first time, thereafter it inverts stuff. So I wonder if the co-ordinates of each finger are being cached somehow, so subsequent pinch in and out requests are based on stale data. Is there a HammerJS reset configuration setting?
I'm aware of these other libraries too (that don't necessitate jQuery too):
InteractJS Again, their canned pinch to Zoom example failed to work on Macbook Pro with touchpad.
Footnote: The best implementation of pinch to zoom I've seen, that works on both Android and iOS is this version by Michaël CHAIZE. But from analysing the code it looks to be based on a really early implementation of HammerJS 0.5 and doesn't even use pinch as part of the domain language - just things like drag, transform, tap, double_tap, so it must be facilitating this stuff by a lower level abstraction. Unfortunately this was for images.