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

Commit 906fc04

Browse files
committed
[android] - hook into onGlobalLayout to start creating the surface and as a result create the map object
1 parent a282280 commit 906fc04

File tree

1 file changed

+14
-3
lines changed
  • platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps

1 file changed

+14
-3
lines changed

platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Canvas;
55
import android.graphics.PointF;
66
import android.graphics.SurfaceTexture;
7+
import android.os.Build;
78
import android.os.Bundle;
89
import android.support.annotation.CallSuper;
910
import android.support.annotation.IntDef;
@@ -21,6 +22,7 @@
2122
import android.view.TextureView;
2223
import android.view.View;
2324
import android.view.ViewGroup;
25+
import android.view.ViewTreeObserver;
2426
import android.widget.FrameLayout;
2527
import android.widget.ImageView;
2628
import android.widget.ZoomButtonsController;
@@ -122,6 +124,18 @@ private void initialise(@NonNull final Context context, @NonNull final MapboxMap
122124
// add accessibility support
123125
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
124126
setWillNotDraw(false);
127+
128+
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
129+
@Override
130+
public void onGlobalLayout() {
131+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
132+
getViewTreeObserver().removeOnGlobalLayoutListener(this);
133+
} else {
134+
getViewTreeObserver().removeGlobalOnLayoutListener(this);
135+
}
136+
initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
137+
}
138+
});
125139
}
126140

127141
private void initialiseMap() {
@@ -553,9 +567,6 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
553567
if (isInEditMode()) {
554568
return;
555569
}
556-
if (visibility == View.VISIBLE && nativeMapView == null) {
557-
initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
558-
}
559570

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

0 commit comments

Comments
 (0)