[core, darwin, android] Add onDidEnterIdle to MapObserver.

didEnterIdle fires whenever render completes and no repaint is scheduled.
This commit is contained in:
Chris Loer
2018-12-06 13:31:42 +02:00
committed by Chris Loer
parent 13e117b501
commit 70c2d5a4ca
14 changed files with 161 additions and 1 deletions

View File

@@ -26,6 +26,8 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
= new CopyOnWriteArrayList<>();
private final List<MapView.OnDidFinishRenderingMapListener> onDidFinishRenderingMapListenerList
= new CopyOnWriteArrayList<>();
private final List<MapView.OnDidEnterIdleListener> onDidEnterIdleListenerList
= new CopyOnWriteArrayList<>();
private final List<MapView.OnDidFinishLoadingStyleListener> onDidFinishLoadingStyleListenerList
= new CopyOnWriteArrayList<>();
private final List<MapView.OnSourceChangedListener> onSourceChangedListenerList = new CopyOnWriteArrayList<>();
@@ -170,6 +172,20 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
}
}
@Override
public void onDidEnterIdle() {
try {
if (!onDidEnterIdleListenerList.isEmpty()) {
for (MapView.OnDidEnterIdleListener listener : onDidEnterIdleListenerList) {
listener.onDidEnterIdle();
}
}
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidEnterIdle", err);
throw err;
}
}
@Override
public void onDidFinishLoadingStyle() {
try {
@@ -278,6 +294,14 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onDidFinishRenderingMapListenerList.remove(listener);
}
void addOnDidEnterIdleListener(MapView.OnDidEnterIdleListener listener) {
onDidEnterIdleListenerList.add(listener);
}
void removeOnDidEnterIdleListener(MapView.OnDidEnterIdleListener listener) {
onDidEnterIdleListenerList.remove(listener);
}
void addOnDidFinishLoadingStyleListener(MapView.OnDidFinishLoadingStyleListener listener) {
onDidFinishLoadingStyleListenerList.add(listener);
}
@@ -305,6 +329,7 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onDidFinishRenderingFrameList.clear();
onWillStartRenderingMapListenerList.clear();
onDidFinishRenderingMapListenerList.clear();
onDidEnterIdleListenerList.clear();
onDidFinishLoadingStyleListenerList.clear();
onSourceChangedListenerList.clear();
}

View File

@@ -691,12 +691,32 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
/**
* Remove a callback that's invoked when the map has finished rendering.
*
* @param listener The callback that's invoked when the map has finished rendering
* @param listener The callback that's invoked when the map has has finished rendering.
*/
public void removeOnDidFinishRenderingMapListener(OnDidFinishRenderingMapListener listener) {
mapChangeReceiver.removeOnDidFinishRenderingMapListener(listener);
}
/**
* Set a callback that's invoked when the map has entered the idle state.
*
* @param listener The callback that's invoked when the map has entered the idle state.
*/
public void addOnDidEnterIdleListener(OnDidEnterIdleListener listener) {
mapChangeReceiver.addOnDidEnterIdleListener(listener);
}
/**
* Remove a callback that's invoked when the map has entered the idle state.
*
* @param listener The callback that's invoked when the map has entered the idle state.
*/
public void removeOnDidEnterIdleListener(OnDidEnterIdleListener listener) {
mapChangeReceiver.removeOnDidEnterIdleListener(listener);
}
/**
/**
* Set a callback that's invoked when the style has finished loading.
*
@@ -870,6 +890,19 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
void onDidFinishRenderingMap(boolean fully);
}
/**
* Interface definition for a callback to be invoked when the map has entered the idle state.
* <p>
* {@link MapView#addOnDidEnterIdleListener(OnDidEnterIdleListener)}
* </p>
*/
public interface OnDidEnterIdleListener {
/**
* Called when the map has entered the idle state.
*/
void onDidEnterIdle();
}
/**
* Interface definition for a callback to be invoked when the map has loaded the style.
* <p>

View File

@@ -1009,6 +1009,11 @@ final class NativeMapView {
}
}
@Keep
private void onDidEnterIdle() {
stateCallback.onDidEnterIdle();
}
@Keep
private void onDidFinishLoadingStyle() {
if (stateCallback != null) {
@@ -1472,6 +1477,8 @@ final class NativeMapView {
void onDidFinishRenderingMap(boolean fully);
void onDidEnterIdle();
void onSourceChanged(String sourceId);
}
}