1515import android .view .LayoutInflater ;
1616import android .view .View ;
1717import android .view .ViewGroup ;
18- import android .view .ViewTreeObserver .OnPreDrawListener ;
1918import androidx .annotation .NonNull ;
2019import androidx .annotation .Nullable ;
2120import androidx .annotation .VisibleForTesting ;
6867 private static final String TAG = "FlutterActivityAndFragmentDelegate" ;
6968 private static final String FRAMEWORK_RESTORATION_BUNDLE_KEY = "framework" ;
7069 private static final String PLUGINS_RESTORATION_BUNDLE_KEY = "plugins" ;
71- private static final int FLUTTER_SPLASH_VIEW_FALLBACK_ID = 486947586 ;
7270
7371 // The FlutterActivity or FlutterFragment that is delegating most of its calls
7472 // to this FlutterActivityAndFragmentDelegate.
7573 @ NonNull private Host host ;
7674 @ Nullable private FlutterEngine flutterEngine ;
75+ @ Nullable private FlutterSplashView flutterSplashView ;
7776 @ Nullable private FlutterView flutterView ;
7877 @ Nullable private PlatformPlugin platformPlugin ;
79- @ VisibleForTesting @ Nullable OnPreDrawListener activePreDrawListener ;
8078 private boolean isFlutterEngineFromHost ;
81- private boolean isFlutterUiDisplayed ;
8279
8380 @ NonNull
8481 private final FlutterUiDisplayListener flutterUiDisplayListener =
8582 new FlutterUiDisplayListener () {
8683 @ Override
8784 public void onFlutterUiDisplayed () {
8885 host .onFlutterUiDisplayed ();
89- isFlutterUiDisplayed = true ;
9086 }
9187
9288 @ Override
9389 public void onFlutterUiNoLongerDisplayed () {
9490 host .onFlutterUiNoLongerDisplayed ();
95- isFlutterUiDisplayed = false ;
9691 }
9792 };
9893
@@ -259,16 +254,6 @@ void onAttach(@NonNull Context context) {
259254 *
260255 * <p>{@code inflater} and {@code container} may be null when invoked from an {@code Activity}.
261256 *
262- * <p>{@code shouldDelayFirstAndroidViewDraw} determines whether to set up an {@link
263- * android.view.ViewTreeObserver.OnPreDrawListener}, which will defer the current drawing pass
264- * till after the Flutter UI has been displayed. This results in more accurate timings reported
265- * with Android tools, such as "Displayed" timing printed with `am start`.
266- *
267- * <p>Note that it should only be set to true when {@code Host#getRenderMode()} is {@code
268- * RenderMode.surface}. This parameter is also ignored, disabling the delay should the legacy
269- * {@code Host#provideSplashScreen()} be non-null. See <a
270- * href="https://flutter.dev/go/android-splash-migration">Android Splash Migration</a>.
271- *
272257 * <p>This method:
273258 *
274259 * <ol>
@@ -284,8 +269,7 @@ View onCreateView(
284269 LayoutInflater inflater ,
285270 @ Nullable ViewGroup container ,
286271 @ Nullable Bundle savedInstanceState ,
287- int flutterViewId ,
288- boolean shouldDelayFirstAndroidViewDraw ) {
272+ int flutterViewId ) {
289273 Log .v (TAG , "Creating FlutterView." );
290274 ensureAlive ();
291275
@@ -314,28 +298,15 @@ View onCreateView(
314298 // Add listener to be notified when Flutter renders its first frame.
315299 flutterView .addOnFirstFrameRenderedListener (flutterUiDisplayListener );
316300
301+ flutterSplashView = new FlutterSplashView (host .getContext ());
302+ flutterSplashView .setId (ViewUtils .generateViewId (486947586 ));
303+ flutterSplashView .displayFlutterViewWithSplash (flutterView , host .provideSplashScreen ());
304+
317305 Log .v (TAG , "Attaching FlutterEngine to FlutterView." );
318306 flutterView .attachToFlutterEngine (flutterEngine );
319307 flutterView .setId (flutterViewId );
320308
321- SplashScreen splashScreen = host .provideSplashScreen ();
322-
323- if (splashScreen != null ) {
324- Log .w (
325- TAG ,
326- "A splash screen was provided to Flutter, but this is deprecated. See"
327- + " flutter.dev/go/android-splash-migration for migration steps." );
328- FlutterSplashView flutterSplashView = new FlutterSplashView (host .getContext ());
329- flutterSplashView .setId (ViewUtils .generateViewId (FLUTTER_SPLASH_VIEW_FALLBACK_ID ));
330- flutterSplashView .displayFlutterViewWithSplash (flutterView , splashScreen );
331-
332- return flutterSplashView ;
333- }
334-
335- if (shouldDelayFirstAndroidViewDraw ) {
336- delayFirstAndroidViewDraw (flutterView );
337- }
338- return flutterView ;
309+ return flutterSplashView ;
339310 }
340311
341312 void onRestoreInstanceState (@ Nullable Bundle bundle ) {
@@ -444,38 +415,6 @@ private String maybeGetInitialRouteFromIntent(Intent intent) {
444415 return null ;
445416 }
446417
447- /**
448- * Delays the first drawing of the {@code flutterView} until the Flutter first has been displayed.
449- */
450- private void delayFirstAndroidViewDraw (FlutterView flutterView ) {
451- if (host .getRenderMode () != RenderMode .surface ) {
452- // Using a TextureView will cause a deadlock, where the underlying SurfaceTexture is never
453- // available since it will wait for drawing to be completed first. At the same time, the
454- // preDraw listener keeps returning false since the Flutter Engine waits for the
455- // SurfaceTexture to be available.
456- throw new IllegalArgumentException (
457- "Cannot delay the first Android view draw when the render mode is not set to"
458- + " `RenderMode.surface`." );
459- }
460-
461- if (activePreDrawListener != null ) {
462- flutterView .getViewTreeObserver ().removeOnPreDrawListener (activePreDrawListener );
463- }
464-
465- activePreDrawListener =
466- new OnPreDrawListener () {
467- @ Override
468- public boolean onPreDraw () {
469- if (isFlutterUiDisplayed && activePreDrawListener != null ) {
470- flutterView .getViewTreeObserver ().removeOnPreDrawListener (this );
471- activePreDrawListener = null ;
472- }
473- return isFlutterUiDisplayed ;
474- }
475- };
476- flutterView .getViewTreeObserver ().addOnPreDrawListener (activePreDrawListener );
477- }
478-
479418 /**
480419 * Invoke this from {@code Activity#onResume()} or {@code Fragment#onResume()}.
481420 *
@@ -557,10 +496,6 @@ void onDestroyView() {
557496 Log .v (TAG , "onDestroyView()" );
558497 ensureAlive ();
559498
560- if (activePreDrawListener != null ) {
561- flutterView .getViewTreeObserver ().removeOnPreDrawListener (activePreDrawListener );
562- activePreDrawListener = null ;
563- }
564499 flutterView .detachFromFlutterEngine ();
565500 flutterView .removeOnFirstFrameRenderedListener (flutterUiDisplayListener );
566501 }
0 commit comments