Skip to content
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

Support multiplatform BackHandler/PredictiveBackHandler. #1771

Open
wants to merge 6 commits into
base: jb-main
Choose a base branch
from

Conversation

terrakok
Copy link
Member

@terrakok terrakok commented Jan 10, 2025

Support BackHandler/PredictiveBackHandler.

Fixes https://youtrack.jetbrains.com/issue/CMP-4419

Screen.Recording.2025-01-10.at.21.19.40.mov

Testing

  • Test it on a demo project

Release Notes

Highlights - Multiple Platforms

  • Implement multiplatform BackHandler and PredictiveBackHandler. And use them in material3 widgets and androidx-navigation library.

@terrakok terrakok force-pushed the k.tskh/ios-back-gesture branch from e36fb22 to 8ad3ee6 Compare January 13, 2025 17:24
Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that adding it to skikoMain is the right move at the moment. We DO want to make common API for this, but not in compose-ui module

compose/material3/material3/build.gradle Outdated Show resolved Hide resolved
navigation/navigation-compose/build.gradle Outdated Show resolved Hide resolved
@terrakok terrakok force-pushed the k.tskh/ios-back-gesture branch from 54d51a3 to 99c6ebc Compare January 16, 2025 15:07
@terrakok terrakok requested a review from MatkovIvan January 16, 2025 15:19
@terrakok terrakok changed the title K.tskh/ios back gesture Support BackHandler/PredictiveBackHandler. Jan 16, 2025
@terrakok terrakok changed the title Support BackHandler/PredictiveBackHandler. Support multiplatform BackHandler/PredictiveBackHandler. Jan 16, 2025
}

fun setView(rootView: UIView) {
rootView.addGestureRecognizer(leftEdgePanGestureRecognizer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gesture recognizers must be removed from view when they not needed. Currently, I can see 2 events:

  • ComposeHostingViewController.dispose()
  • when window is null in onDidMoveToWindow(window: UIWindow?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed it with @elijah-semyonov and decided it is not needed here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, it creates 2 gesture recognisers per each ComposeHostingViewController and add them to some external view - these recognisers will stay there forever. So I think we need to delete them anyway.

Copy link
Member Author

@terrakok terrakok Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will stay there forever

no. when ComposeHostingViewController is gone, it will be destroyed because a system view keeps a weak reference

velX < -10 -> listener.onCancelled()
//if there is no movement, or the movement is slow,
//but the touch is already more than BACK_GESTURE_SCREEN_SIZE
abs(x) >= size.width * BACK_GESTURE_SCREEN_SIZE -> listener.onCompleted()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On iOS it's a bit more complicated. It looks more like: min(200.dp, bounds.width / 2), or similar..

I think we need to play (in another MR) here a bit to make behavior close to what we have in UINavigationController

@terrakok terrakok force-pushed the k.tskh/ios-back-gesture branch 2 times, most recently from 5653ec4 to 1cd1470 Compare January 17, 2025 16:19
@terrakok terrakok force-pushed the k.tskh/ios-back-gesture branch from 1cd1470 to bcdb1ba Compare January 17, 2025 16:48
@terrakok terrakok force-pushed the k.tskh/ios-back-gesture branch from bcdb1ba to 15aa84a Compare January 17, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants