-
Notifications
You must be signed in to change notification settings - Fork 101
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
2/4 Better support for View.findViewTreeOnBackPressedDispatcherOwner
.
#1027
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 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
rjrjr
changed the title
Better support for
2/3 Better support for Jun 14, 2023
View.findViewTreeOnBackPressedDispatcherOwner
.View.findViewTreeOnBackPressedDispatcherOwner
.
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 14, 2023 21:03
8ff77ce
to
7154b36
Compare
rjrjr
force-pushed
the
ray/2-install-on-back-dispatcher
branch
from
June 14, 2023 21:04
d29aea2
to
f62b52f
Compare
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 14, 2023 22:37
7154b36
to
7f258e5
Compare
rjrjr
force-pushed
the
ray/2-install-on-back-dispatcher
branch
3 times, most recently
from
June 15, 2023 16:48
dfe3296
to
faec646
Compare
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 15, 2023 16:48
7f258e5
to
e4f4fe1
Compare
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 15, 2023 17:16
e4f4fe1
to
8d1228d
Compare
rjrjr
force-pushed
the
ray/2-install-on-back-dispatcher
branch
from
June 15, 2023 17:16
faec646
to
78620bb
Compare
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 15, 2023 23:24
8d1228d
to
5973c5b
Compare
rjrjr
force-pushed
the
ray/2-install-on-back-dispatcher
branch
from
June 15, 2023 23:24
78620bb
to
08e8dd3
Compare
rjrjr
changed the title
2/3 Better support for
2/4 Better support for Jun 15, 2023
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) |
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") |
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!
rjrjr
force-pushed
the
ray/2-install-on-back-dispatcher
branch
from
June 21, 2023 20:30
08e8dd3
to
d417e33
Compare
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 21, 2023 20:30
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.
rjrjr
force-pushed
the
ray/1-component-set-dialog
branch
from
June 24, 2023 00:51
a9e7dda
to
6f4712f
Compare
rjrjr
force-pushed
the
ray/2-install-on-back-dispatcher
branch
from
June 24, 2023 00:51
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.setViewTreeSavedStateRegistryOwner
on every view we build.We accomplish this mainly by riding the rails previously laid down via
WorkflowLifecycleOwner.installOn
, which now requires anOnBackPressedDispatcherOwner
parameter. (This is the method used byWorkflowViewStub
et al to ensure that we're managing the JetPack Lifecycle correctly, andOnBackPressedDispatcherOwner
is just another piece of that puzzle.)In aid of that, we introduce a new
ViewEnvironmentKey
,OnBackPressedDispatcherOwnerKey
. It is initialized byWorkflowLayout
, our newComponentDialog.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 thatWorkflowViewStub
and friends will have access to the correctOnBackPressedDispatcherOwner
before they have access to a parent view.@Composable fun BackHandler()
, in both activity and dialog windows.