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

FC Playground app - Make keyboard dismissible #3746

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

mats-stripe
Copy link
Collaborator

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

@mats-stripe mats-stripe requested review from a team as code owners July 3, 2024 14:01
@@ -176,6 +176,9 @@ struct PlaygroundView: View {
}
.navigationTitle("Playground")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
UIScrollView.appearance().keyboardDismissMode = .interactive
Copy link
Contributor

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)

Copy link
Collaborator Author

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 👍

Copy link
Contributor

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)?

Copy link
Contributor

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

Screenshot 2024-07-04 at 5 18 18 PM

Copy link
Collaborator Author

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!

kgaidis-stripe
kgaidis-stripe previously approved these changes Jul 3, 2024
}

private func hideKeyboard(_ value: DragGesture.Value) {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's right!

@mats-stripe mats-stripe force-pushed the mats/fc-playground-dismiss-keyboard branch from 60c591a to 0a2db9c Compare July 9, 2024 13:11
@mats-stripe mats-stripe merged commit 2ff997b into master Jul 9, 2024
5 checks passed
@mats-stripe mats-stripe deleted the mats/fc-playground-dismiss-keyboard branch July 9, 2024 13:47
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