material-components / material-components/material-components-android

[Predicive Back] Unify backpressed behaviour for different platforms.

Open
#3,453 0 comments 0 reactions 1 assignee View on GitHub

@hunterstich is already working on this.

Since Jul 6, 2023.

feature request
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.