Skip to content

Commit 6a312cc

Browse files
author
farfromrefug
committed
fix(zoomimage): android fix for current zoom being reset on updateImageUri
1 parent f90b080 commit 6a312cc

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

packages/zoomimage/platforms/android/java/com/facebook/samples/zoomable/DefaultZoomableController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public interface ImageBoundsListener {
7272
private final RectF mTempRect = new RectF();
7373
private boolean mWasTransformCorrected;
7474

75+
// used to not reset transform on updateImageUri ( controller update )
76+
public boolean ignoreNextResetUntilEnabled = false;
77+
78+
7579
public static DefaultZoomableController newInstance() {
7680
return new DefaultZoomableController(TransformGestureDetector.newInstance());
7781
}
@@ -83,6 +87,9 @@ public DefaultZoomableController(TransformGestureDetector gestureDetector) {
8387

8488
/** Rests the controller. */
8589
public void reset() {
90+
if (ignoreNextResetUntilEnabled) {
91+
return;
92+
}
8693
mGestureDetector.reset();
8794
mPreviousTransform.reset();
8895
mActiveTransform.reset();
@@ -101,6 +108,8 @@ public void setEnabled(boolean enabled) {
101108
mIsEnabled = enabled;
102109
if (!enabled) {
103110
reset();
111+
} else {
112+
ignoreNextResetUntilEnabled = false;
104113
}
105114
}
106115

src/zoomimage/index.android.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export class ZoomImg extends ZoomImageBase {
1818
return this.nativeViewProtected?.getZoomableController() as com.facebook.samples.zoomable.DefaultZoomableController;
1919
}
2020

21+
updateImageUri() {
22+
// this prevents the controller from reseting the current transform
23+
this.getController().ignoreNextResetUntilEnabled = true;
24+
return super.updateImageUri();
25+
}
2126
[zoomScaleProperty.setNative](scale: number) {
2227
//possible?
2328
// if (this.nativeViewProtected) {

src/zoomimage/typings/android.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ declare namespace com {
213213
public static LIMIT_TRANSLATION_Y: number = 2;
214214
public static LIMIT_SCALE: number = 4;
215215
public static LIMIT_ALL: number = 7;
216+
public ignoreNextResetUntilEnabled : boolean;
216217
public mapViewToImage(param0: globalAndroid.graphics.PointF): globalAndroid.graphics.PointF;
217218
public isIdentity(): boolean;
218219
public wasTransformCorrected(): boolean;

0 commit comments

Comments
 (0)