@nativescript-community/ui-zoomimage
Version:
Zoomable image view based on @nativescript-community/ui-image
78 lines • 2.68 kB
JavaScript
export * from './index-common';
import { ZoomImageBase, maxZoomScaleProperty, minZoomScaleProperty, zoomScaleProperty } from './index-common';
export class ZoomImg extends ZoomImageBase {
createNativeView() {
return new com.nativescript.image.ZoomableMatrixImageView(this._context);
}
initNativeView() {
super.initNativeView();
// Set up TouchImageView zoom listener
const owner = new WeakRef(this);
// TouchImageView has setOnTouchImageViewListener
this.nativeViewProtected.setOnZoomChangeListener(new com.nativescript.image.ZoomableMatrixImageView.OnZoomChangeListener({
onZoomChanged(zoom) {
const instance = owner.get();
if (instance) {
instance.notifyZoomChanged(zoom);
}
}
}));
}
disposeNativeView() {
this.nativeViewProtected.setOnZoomChangeListener(null);
// Clean up
// if (this.nativeViewProtected) {
// this.nativeViewProtected.setOnTouchImageViewListener(null);
// }
super.disposeNativeView();
}
updateImageUri() {
// Prevent zoom reset when updating image URI
if (this.nativeViewProtected) {
this.nativeViewProtected.setIgnoreNextReset(true);
}
return super.updateImageUri();
}
[zoomScaleProperty.setNative](scale) {
this.nativeViewProtected?.zoomTo(scale, false);
}
setZoom(scale, animated = true, point = { x: 0, y: 0 }) {
if (this.nativeViewProtected) {
if (point.x === 0 && point.y === 0) {
// Zoom to center
this.nativeViewProtected.zoomTo(scale, animated);
}
else {
// Zoom to specific point
this.nativeViewProtected.zoomToPoint(scale, point.x, point.y, animated, null);
}
}
}
getZoom() {
if (this.nativeViewProtected) {
return this.nativeViewProtected.getZoom();
}
return 1.0;
}
[minZoomScaleProperty.setNative](scale) {
if (this.nativeViewProtected) {
this.nativeViewProtected.setMinZoom(scale);
}
}
[maxZoomScaleProperty.setNative](scale) {
if (this.nativeViewProtected) {
this.nativeViewProtected.setMaxZoom(scale);
}
}
notifyZoomChanged(scale) {
const eventName = 'zoomChanged';
if (this.hasListeners(eventName)) {
this.notify({
eventName,
object: this,
scale
});
}
}
}
//# sourceMappingURL=index.android.js.map