material-components / material-components/material-components-android
[Predicive Back] Unify backpressed behaviour for different platforms.
@hunterstich is already working on this.
Since Jul 6, 2023.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Currently we intercept back gesture through MaterialBackOrchestrator, but it is no-op below API 33 since we have no OnBackInvokedDispatcher on these platforms.
What about convert to use OnBackPressedCallback(from androidx: activity)
We find the activity with such code
private Activity getActivity() {
Context context = getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity)context;
}
context = ((ContextWrapper)context).getBaseContext();
}
return null;
}
And try cast it to ComponentActivity then get the OnBackPressedDispatcher.
Otherwise, it is very inelegant to handle it separately on the app side for API32 and below platforms.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.