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

onGlobalLayout hook for map creation #9607

Merged
merged 1 commit into from
Jul 25, 2017
Merged
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 @@ -4,6 +4,7 @@
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.SurfaceTexture;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.IntDef;
Expand All @@ -21,6 +22,7 @@
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ZoomButtonsController;
Expand Down Expand Up @@ -122,6 +124,18 @@ private void initialise(@NonNull final Context context, @NonNull final MapboxMap
// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
setWillNotDraw(false);

getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
}
});
}

private void initialiseMap() {
Expand Down Expand Up @@ -553,9 +567,6 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
if (isInEditMode()) {
return;
}
if (visibility == View.VISIBLE && nativeMapView == null) {
initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
}

if (mapZoomButtonController != null && nativeMapView != null) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
Expand Down