Skip to content

Commit

Permalink
Allowed MapFragment's onCreateView() to be overridden
Browse files Browse the repository at this point in the history
Resolves: #10
  • Loading branch information
SupasinTatiyanupanwong committed Aug 22, 2021
1 parent cd0184c commit b19b468
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.view.ViewGroup;
import android.view.ViewTreeObserver;

import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
Expand Down Expand Up @@ -59,14 +60,31 @@ public static MapFragment newInstance() {
return new MapFragment();
}

// Used to verify that subclasses call through to super.onCreateView().
private boolean mOnCreateViewCalled = false;

@CallSuper
@Override
public final @NonNull View onCreateView(
public @NonNull View onCreateView(
@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
mOnCreateViewCalled = true;
return inflater.inflate(MapsPlatform.get().getFragmentLayoutId(), container, false);
}

@CallSuper
@Override
public void onStart() {
// FM enforced super.onStart() to be called if overridden, checking our view first.
if (!mOnCreateViewCalled) {
throw new IllegalStateException("MapFragment " + this
+ " did not call through to super.onCreateView()");
}

super.onStart();
}

/**
* Sets a callback object which will be triggered when the {@link MapClient} instance is ready
* to be used.
Expand Down Expand Up @@ -100,6 +118,7 @@ public void onFragmentViewCreated(
*
* @param callback The callback object that will be triggered when the map has undergone layout
* and ready to be used.
* @since 2.0.0
*/
public final void getMapAsync(final MapKit.OnMapAndViewReadyCallback callback) {
getMapAsync(new OnMapAndViewReadyCallbackImpl(this, callback));
Expand Down

0 comments on commit b19b468

Please sign in to comment.