-
Notifications
You must be signed in to change notification settings - Fork 974
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
FC Playground app - Make keyboard dismissible #3746
Conversation
@@ -176,6 +176,9 @@ struct PlaygroundView: View { | |||
} | |||
.navigationTitle("Playground") | |||
.navigationBarTitleDisplayMode(.inline) | |||
.onAppear { | |||
UIScrollView.appearance().keyboardDismissMode = .interactive |
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.
Does this only affect PlaygroundView
? Or can it also affect the Auth Flow? (if it can affect the auth flow that would be subpar because we always want to test the actual experience the users would have integrating in any app)
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.
According to Claude;
The UIScrollView.appearance().keyboardDismissMode = .interactive
setting made in the .onAppear
block of a SwiftUI view will only have an effect on the behavior of the UIScrollView
instances within that specific SwiftUI view and its subviews. It will not have any effect on UIScrollView
instances outside of that view hierarchy.
The appearance()
method in UIKit is used to set global properties that apply to all instances of a particular class. However, in the context of a SwiftUI view, the changes made using appearance()
are scoped to that view and its subviews.
This means that if you have another SwiftUI view in your app that also contains a UIScrollView
, it will not be affected by the keyboardDismissMode
setting made in the first view. Each SwiftUI view is responsible for configuring its own UIScrollView
instances.
Based on that, I don't think this will have any effects outside of the PlaygroundView
👍
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.
ChatGPT 😅 :
Yes, setting UIScrollView.appearance().keyboardDismissMode = .interactive will affect all instances of UIScrollView within your app. The appearance() proxy is a way to configure default values for UI elements across the entire application, so any scroll view will adopt this keyboard dismiss mode unless it's specifically overridden in an individual scroll view instance.
@mats-stripe If we are to blindly follow LLM's, what would be the explanation of how this works? How would calling UIScrollView.appearance()
magically reference the correct thing? Not saying its impossible, but even the API feels very odd if its globally setting something, yet only affecting one thing?
There's also .scrollDismissesKeyboard(.interactively)
?
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.
This also doesn't increase my confidence that its not global?
https://developer.apple.com/documentation/uikit/uiappearance
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.
I tested this out, and as you guessed, changing the UIScrollView.appearance()
here affects the app behaviour globally 😅
I just pushed a change to dismiss the keyboard when a drag gesture is recognized, which works just as well and is local to only the playground view!
} | ||
|
||
private func hideKeyboard(_ value: DragGesture.Value) { | ||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) |
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.
that's quite clever, and good naming; I guess the value: DragGesture.Value
is "needed" because of the onChanged
definition
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.
That's right!
60c591a
to
0a2db9c
Compare
Summary
This updates the Financial Connections playground app such that the keyboard can now be dismissed interactively. Previously, there was no way to dismiss it, and it would block launching the FC flow.
Motivation
✨
Testing
Screen.Recording.2024-07-03.at.9.52.23.AM.mov
Changelog
N/a