Skip to content

#188: Add support to swiping to dismiss keyboard for UIKitBackend #193

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
merged 4 commits into from
Jun 27, 2025

Conversation

Vitorsilveira31
Copy link
Contributor

@Vitorsilveira31 Vitorsilveira31 commented Jun 24, 2025

Summary

This PR adds support for the .scrollDismissesKeyboard(_:) modifier to TextEditor on iOS, allowing developers to control how the keyboard is dismissed during scroll interactions.

By default, TextEditor now uses .never, meaning it will not dismiss the keyboard when the user scrolls. This aligns with typical multi-line text editing behavior on iOS, and differs from other scrollable views, which may dismiss the keyboard unless configured otherwise.

This change addresses stackotter/swift-cross-ui#188.

UIKitBackend

On TextEditor On ScrollView
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-06-23.at.21.58.28.mov
Simulator.Screen.Recording.-.iPhone.16.Pro.-.2025-06-24.at.13.27.57.mov

@stackotter
Copy link
Owner

Thanks for the PR! This will be a nice quality of life improvement.

I believe that multiline text editing on iOS usually supports the interactive dismissal style. For example the notes app lets you scroll with the keyboard open, but if your finger enters the keyboard while scrolling it begins scrolling away the keyboard. I feel like that should be the default for SwiftCrossUI as well.

In addition to setting the keyboardDismissMode property on text editors in UIKitBackend, I believe you'll have to set it on scroll views(because the way SwiftCrossUI uses text editors means that they never end up being scrollable; it always makes them big enough to fit their content).

@Vitorsilveira31
Copy link
Contributor Author

@stackotter Got it, that makes sense. I’ll take a look at it tomorrow.

@stackotter
Copy link
Owner

stackotter commented Jun 24, 2025

I also meant to mention that this codebase uses indented switch case blocks, so please update that in your PR while you're at it as well.

switch foo {
    case .bar:
        ...
    case .baz:
        ...
}

@Vitorsilveira31
Copy link
Contributor Author

Vitorsilveira31 commented Jun 24, 2025

@stackotter I’ve made the changes. Can you check if it works the way you had in mind? I also included examples in the description using it with TextEditor and ScrollView.

stackotter
stackotter previously approved these changes Jun 25, 2025
Copy link
Owner

@stackotter stackotter left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes 🙏 I just looked through the code and you've done it all basically exactly how I would've done it. It all works well on my phone as well. I've just left a few comments for smaller formatting/documentation things and suggested adding an automatic mode for future proofing.

@Vitorsilveira31
Copy link
Contributor Author

@stackotter all set, I’ve included all the changes in the last commit

Copy link
Owner

@stackotter stackotter left a comment

Choose a reason for hiding this comment

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

Thanks for addressing those comments, looks good now

@stackotter
Copy link
Owner

Will merge once the CI finishes

@Vitorsilveira31
Copy link
Contributor Author

@stackotter Just bringing this PR back to your radar

@stackotter
Copy link
Owner

Ah yep thanks! Forgot that I hadn't merged hahah

@stackotter stackotter merged commit ca8fced into stackotter:main Jun 27, 2025
10 checks passed
@Vitorsilveira31 Vitorsilveira31 deleted the feature/188 branch June 27, 2025 05:32
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.

2 participants