-
Notifications
You must be signed in to change notification settings - Fork 6k
Use preDraw for the Android embedding #27645
Conversation
@@ -18,6 +18,9 @@ | |||
"io.flutter.embedding.android.NormalTheme"; | |||
/* package */ static final String HANDLE_DEEPLINKING_META_DATA_KEY = | |||
"flutter_deeplinking_enabled"; | |||
/* package */ static final String USE_LEGACY_SPLASH_SCREEN_META_DATA_KEY = | |||
"io.flutter.embedding.android.use-legacy-splash-screen"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this meta data is necessary.
It might be worth looking at the case when the user didn't supply a custom drawable. In this case, there's no drawable, so the splash screen is unnecessary.
return null; |
I was thinking that it could be the way to decide whether we install the predraw listener or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will mean that the new behavior with preDraw will not be used by default, and is instead opt-in, which sounds a bit simpler, thanks 🙂 . I'll update the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still need io.flutter.embedding.android.use-legacy-splash-screen
or can it be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, removed it!
…tener after drawing
- Only enable it by default for users who use `FlutterActivity` and `FlutterActivityFragment` - Add checks and disable it by default when it is used with `RenderingMode.texture`
@blasten I updated the PR with what we discussed last Friday, and also to disable it for |
new OnPreDrawListener() { | ||
@Override | ||
public boolean onPreDraw() { | ||
if (isFlutterUiDisplayed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this might run again after you rotate the screen. We might want to run this only once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it locally and registering the callback only happens once. We also deregister the listener the moment isFlutterUiDisplayed
returns true, so it should be safe.
@@ -269,7 +282,8 @@ View onCreateView( | |||
LayoutInflater inflater, | |||
@Nullable ViewGroup container, | |||
@Nullable Bundle savedInstanceState, | |||
int flutterViewId) { | |||
int flutterViewId, | |||
boolean shouldInterceptFirstDraw) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe shouldDelayFirstAndroidViewDraw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better, thanks!
"A splash screen was provided to Flutter, but this is deprecated. See" | ||
+ " flutter.dev/go/android-splash-migration for migration steps."); | ||
FlutterSplashView flutterSplashView = new FlutterSplashView(host.getContext()); | ||
flutterSplashView.setId(ViewUtils.generateViewId(486947586)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor clean up. 486947586
could be a final private static value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done
- Rename to shouldDelayFirstAndroidViewDraw - Static variable for Flutter splash view id - Remove change to FlutterActivityLaunchConfigs - Extract predraw to helper method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- Throw IllegalArgumentException instead of RuntimeException when using TextureView and delaying the first draw - Expose handler with @VisibleForTesting to make it easier to test
Added some unit tests and some minor visibility tweaks to make testing easier, please take another look 🙂 I'll follow up with the deprecation in a separate PR. |
Still LGTM |
shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java
Outdated
Show resolved
Hide resolved
Log.w( | ||
TAG, | ||
"A splash screen was provided to Flutter, but this is deprecated. See" | ||
+ " flutter.dev/go/android-splash-migration for migration steps."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! flutter.dev/go/android-splash-migration returns 404 though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to write this separately along with the deprecation annotations, will follow up
...atform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java
Outdated
Show resolved
Hide resolved
shell/platform/android/io/flutter/embedding/android/FlutterFragment.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
On Android, use the preDraw listener to report that the application is drawn only when Flutter has shown the first frame, when using the V2
FlutterActivity
andFlutterFragmentActivity
.Related issue: flutter/flutter#85292
Changes
FlutterActivity
andFlutterFragmentActivity
, unless:io.flutter.embedding.android.SplashScreenDrawable
/provideSplashScreen
). When this is detected, add log warnings to direct users to a migration guideflutter.dev/go/android-splash-migration
(not written yet)RenderMode.surface
is not used. This is because otherwise,FlutterTextureView
will be used, but a deadlock will be caused because the underlyingSurfaceTexture
will never be available when preDraw returns falseFlutterFragment
directly can enable this behavior through theshouldDelayFirstAndroidViewDraw
builder methodImplementation Notes
FlutterActivityAndFragmentDelegate
instead ofFlutterView
, to avoid the need to add yet another constructor to conditionally trigger this behavior.FlutterActivityAndFragmentDelegate
also knows about the splash screen, and this implementation keeps the splash screen logic consolidatedFlutterActivityAndFragmentDelegate.onCreateView
. I did not add a overload to preserve the old behavior sinceFlutterActivityAndFragmentDelegate
is package privateTested
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.