Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Post animation callback instead of animation itself #10664

Merged
merged 1 commit into from
Dec 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -710,19 +710,21 @@ public final void moveCamera(CameraUpdate update) {
* @param callback the callback to be invoked when an animation finishes or is canceled
*/
public final void moveCamera(final CameraUpdate update, final MapboxMap.CancelableCallback callback) {
new Handler().post(new Runnable() {
@Override
public void run() {
transform.moveCamera(MapboxMap.this, update, callback);
// MapChange.REGION_DID_CHANGE_ANIMATED is not called for `jumpTo`
// invalidate camera position to provide OnCameraChange event.
invalidateCameraPosition();

if (callback != null) {
callback.onFinish();
transform.moveCamera(MapboxMap.this, update, callback);
// MapChange.REGION_DID_CHANGE_ANIMATED is not called for `jumpTo`
// invalidate camera position to provide OnCameraChange event.
invalidateCameraPosition();

if (callback != null) {
new Handler().post(new Runnable() {
@Override
public void run() {
if (callback != null) {
callback.onFinish();
}
}
}
});
});
}
}

/**
Expand Down Expand Up @@ -846,12 +848,7 @@ public final void easeCamera(final CameraUpdate update, final int durationMs, fi
if (durationMs <= 0) {
throw new IllegalArgumentException("Null duration passed into easeCamera");
}
new Handler().post(new Runnable() {
@Override
public void run() {
transform.easeCamera(MapboxMap.this, update, durationMs, easingInterpolator, callback, isDismissable);
}
});
transform.easeCamera(MapboxMap.this, update, durationMs, easingInterpolator, callback, isDismissable);
}

/**
Expand Down Expand Up @@ -921,12 +918,8 @@ public final void animateCamera(final CameraUpdate update, final int durationMs,
if (durationMs <= 0) {
throw new IllegalArgumentException("Null duration passed into animageCamera");
}
new Handler().post(new Runnable() {
@Override
public void run() {
transform.animateCamera(MapboxMap.this, update, durationMs, callback);
}
});

transform.animateCamera(MapboxMap.this, update, durationMs, callback);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.maps;

import android.graphics.PointF;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
Expand Down Expand Up @@ -82,8 +83,15 @@ public void onMapChanged(@MapView.MapChange int change) {
if (change == REGION_DID_CHANGE_ANIMATED) {
updateCameraPosition(invalidateCameraPosition());
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onFinish();
cameraCancelableCallback = null;
new Handler().post(new Runnable() {
@Override
public void run() {
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onFinish();
cameraCancelableCallback = null;
}
}
});
}
cameraChangeDispatcher.onCameraIdle();
mapView.removeOnMapChangedListener(this);
Expand Down Expand Up @@ -175,8 +183,15 @@ void cancelTransitions() {
// notify animateCamera and easeCamera about cancelling
if (cameraCancelableCallback != null) {
cameraChangeDispatcher.onCameraIdle();
cameraCancelableCallback.onCancel();
cameraCancelableCallback = null;
new Handler().post(new Runnable() {
@Override
public void run() {
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onCancel();
cameraCancelableCallback = null;
}
}
});
}

// cancel ongoing transitions
Expand Down