-
Notifications
You must be signed in to change notification settings - Fork 6k
Change visibility of FlutterView when onStop/onStart #30897
Change visibility of FlutterView when onStop/onStart #30897
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| if (flutterSurfaceView != null) { | ||
| flutterSurfaceView.setVisibility(View.VISIBLE); | ||
| } | ||
| } | ||
|
|
||
| // Invoke this from {@code FlutterActivityAndFragmentDelegate#onStop()} | ||
| /* package */ void onStop() { | ||
| if (flutterSurfaceView != null) { | ||
| flutterSurfaceView.setVisibility(View.GONE); | ||
| } | ||
| } | ||
|
|
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.
We've tried to resist adding API like this historically because it's likely to get missed when you don't use the FlutterActivityAndFragmentDelegate class, IIRC. @xster or @blasten wdyt?
I'm curious about where the view is getting the wrong visibility set and why this helps. I'm also curious if we're getting calls on View.invalidateDrawable at some point here that might help us - if we can take advantage of the View's own lifecycle it'd be better.
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.
Or alternatively if we're getting calls to onDraw or onWindowVisibilityChanged/onAttachedToWindow.
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 guess these methods might not work. In this scenario, the onStart and onStop of the Activity are correct, but the visibility of the window/view tree is still visible after onStop.
dnfield
left a comment
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.
Would like to better understand if we can avoid the View hooking Activity/Fragment lifecycle.
| if (flutterSurfaceView != null) { | ||
| flutterSurfaceView.setVisibility(View.VISIBLE); | ||
| } | ||
| } | ||
|
|
||
| // Invoke this from {@code FlutterActivityAndFragmentDelegate#onStop()} | ||
| /* package */ void onStop() { | ||
| if (flutterSurfaceView != null) { | ||
| flutterSurfaceView.setVisibility(View.GONE); | ||
| } | ||
| } | ||
|
|
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.
Or alternatively if we're getting calls to onDraw or onWindowVisibilityChanged/onAttachedToWindow.
802ef43 to
644f990
Compare
|
I changed the code to set the |
dnfield
left a comment
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 think this is fine to at least work around the bug for now, but it would be better if we could find some way to avoid needing this.
| Log.v(TAG, "onStart()"); | ||
| ensureAlive(); | ||
| doInitialFlutterViewRun(); | ||
| flutterView.setVisibility(View.VISIBLE); |
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.
nit: please add some comment(s) here and below about why we're doing this, with a link to the bug
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.
Done
|
when will it be merged into stable |
|
There is a work around posted on the bug that you can patch into your own app. I don't think we should go through the process of cherry picking for this. |
| // screen when unlocked. We can work around this by changing the visibility of FlutterView in | ||
| // onStart and onStop. | ||
| // See https://github.com/flutter/flutter/issues/93276 | ||
| flutterView.setVisibility(View.VISIBLE); |
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 meet an issue because of this edit. My use case is I use FlutterFragment as a tab in Activity, when user switched to other tabs, I will hide the FlutterFragment. After this commit, every time Activity resumed, the flutterView will be foreced to visible, even the FlutterFragment is set to hide.
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.
Please file a new issue with minimum reproducible code, thank you.
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.
Please file a new issue with minimum reproducible code, thank you.
this merge doest fix the issue;
this is my code to reproduce,
|
we have started facing an issue because of this change in our add to app approach when we recently migrated from flutter 2.10.3 -> 3.13.4. we have a tab holder fragment in native where centre tab is native and adjacent two tabs are flutter. |
|
Still Showing Black Screen on Samsung s21fe android 14. After Updating the app. Fixed the issue by clearing the data of app. [√] Flutter (Channel stable, 3.24.4, on Microsoft Windows [Version 10.0.26100.2605], locale en-US) Got this Black Screen Error After Updating the app. Unless you do clear data. |
Some OnePlus phones can still update the view tree after locking the screen in some cases, which causes the
surfaceCreatedmethod ofSurfaceView.Holdercan be called when the screen is turned off, andsurfaceCreatedwill not be called when the screen is turned on. And changing the visibility of FlutterSurfaceView in onStart and onStop can fix this problem.detail
flutter/flutter#93276 (comment)
PS: Setting the visibility of FlutterView directly at onStart and onStop can also solve this problem. However based on my current investigations TextureView shouldn't have this problem (it doesn't call onSurfaceTextureDestroyed when the screen is off, so no need to call
onSurfaceTextureAvailablewhen the screen is on), Please let me know if you guys think it makes more sense to change the visibility of FlutterView.Fix flutter/flutter#93276, flutter/flutter#94921.
Pre-launch Checklist
writing and running engine tests.
///).