-
Notifications
You must be signed in to change notification settings - Fork 112
2/4 Better support for View.findViewTreeOnBackPressedDispatcherOwner.
#1027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rjrjr
merged 1 commit into
ray/1-component-set-dialog
from
ray/2-install-on-back-dispatcher
Jun 26, 2023
Merged
2/4 Better support for View.findViewTreeOnBackPressedDispatcherOwner.
#1027
rjrjr
merged 1 commit into
ray/1-component-set-dialog
from
ray/2-install-on-back-dispatcher
Jun 26, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
View.findViewTreeOnBackPressedDispatcherOwner.View.findViewTreeOnBackPressedDispatcherOwner.
8ff77ce to
7154b36
Compare
d29aea2 to
f62b52f
Compare
7154b36 to
7f258e5
Compare
dfe3296 to
faec646
Compare
7f258e5 to
e4f4fe1
Compare
e4f4fe1 to
8d1228d
Compare
faec646 to
78620bb
Compare
8d1228d to
5973c5b
Compare
78620bb to
08e8dd3
Compare
View.findViewTreeOnBackPressedDispatcherOwner.View.findViewTreeOnBackPressedDispatcherOwner.
steve-the-edwards
approved these changes
Jun 16, 2023
| contentHolder.show(newOverlay.content, newEnvironment) | ||
| contentHolder.show( | ||
| newOverlay.content, | ||
| newEnvironment + (OnBackPressedDispatcherOwnerKey to this@setContent) |
Contributor
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.
Suggested change
| newEnvironment + (OnBackPressedDispatcherOwnerKey to this@setContent) | |
| // Note we need to add back the OnBackPressedDispatcherOwner each time we receive a new ViewEnvironment. | |
| newEnvironment + (OnBackPressedDispatcherOwnerKey to this@setContent) |
Comment on lines
+167
to
+171
| override fun getLifecycle(): Lifecycle = | ||
| error("To support back press handling extend ComponentDialog: $dialog") | ||
|
|
||
| override fun getOnBackPressedDispatcher(): OnBackPressedDispatcher = | ||
| error("To support back press handling extend ComponentDialog: $dialog") |
Contributor
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!
08e8dd3 to
d417e33
Compare
5973c5b to
a9e7dda
Compare
`fun View.findViewTreeOnBackPressedDispatcherOwner()` is AndroidX's preferred entry point to the exciting new world of `OnBackPressedDispatcherOwner`. With this PR we support it explicitly, in particular taking care to ensure that it can be called by newly constructed views before they have been attached to a parent. That is, we take care to make eager calls `View.setViewTreeSavedStateRegistryOwner` on every view we build. We accomplish this mainly by riding the rails previously laid down via `WorkflowLifecycleOwner.installOn`, which now requires an `OnBackPressedDispatcherOwner` parameter. (This is the method used by `WorkflowViewStub` _et al_ to ensure that we're managing the JetPack Lifecycle correctly, and `OnBackPressedDispatcherOwner` is just another piece of that puzzle.) In aid of that, we introduce a new `ViewEnvironmentKey`, `OnBackPressedDispatcherOwnerKey`. It is initialized by `WorkflowLayout`, our new `ComponentDialog.setContent` extension, and `@Composable fun WorkflowRendering()`. This key is not intended for use by feature code, it's more of an implementation detail that has to stay public to allow custom containers to be built. It ensures that `WorkflowViewStub` and friends will have access to the correct `OnBackPressedDispatcherOwner` before they have access to a parent view. TODO: add tests of `@Composable fun BackHandler()`, in both activity and dialog windows.
a9e7dda to
6f4712f
Compare
d417e33 to
0335e65
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fun View.findViewTreeOnBackPressedDispatcherOwner()is AndroidX's preferred entry point to the exciting new world ofOnBackPressedDispatcherOwner. With this PR we support it explicitly, in particular taking care to ensure that it can be called by newly constructed views before they have been attached to a parent. That is, we take care to make eager callsView.setViewTreeSavedStateRegistryOwneron every view we build.We accomplish this mainly by riding the rails previously laid down via
WorkflowLifecycleOwner.installOn, which now requires anOnBackPressedDispatcherOwnerparameter. (This is the method used byWorkflowViewStubet al to ensure that we're managing the JetPack Lifecycle correctly, andOnBackPressedDispatcherOwneris just another piece of that puzzle.)In aid of that, we introduce a new
ViewEnvironmentKey,OnBackPressedDispatcherOwnerKey. It is initialized byWorkflowLayout, our newComponentDialog.setContentextension, and@Composable fun WorkflowRendering(). This key is not intended for use by feature code, it's more of an implementation detail that has to stay public to allow custom containers to be built. It ensures thatWorkflowViewStuband friends will have access to the correctOnBackPressedDispatcherOwnerbefore they have access to a parent view.@Composable fun BackHandler(), in both activity and dialog windows.