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

Fix issue (#122) withscrollToRevealFirstResponder #136

Merged
merged 2 commits into from
Sep 27, 2019

Conversation

nataliq
Copy link
Contributor

@nataliq nataliq commented Sep 25, 2019

#122

I was struggling to understand why this issue is happening (probably something around the usage of frame vs bounds).. We were getting weird negative offset in few cases causing glitches when switching between fields. We ended up re-writing some of the logic together with @enhorn . Now we're comparing only the vertical positions taking into account scroll view offset and insets.

Will run couple of more manual tests on devices but so far everything looks good. Let me know what do you think.

Copy link
Contributor

@PhilippOtto89 PhilippOtto89 left a comment

Choose a reason for hiding this comment

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

Great fix!

@@ -150,33 +150,58 @@ private extension UIScrollView {
}
}

func adjustContentOffset(_ adjustInsets: (UIView) -> UIEdgeInsets) {
guard let firstResponder = firstResponder as? UIView else { return }
func adjustContentOffsetToRevealFirstResponder(_ adjustInsets: (_ firstResponder: UIView) -> UIEdgeInsets) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good renaming, makes the function a lot clearer 👍

@@ -150,33 +150,58 @@ private extension UIScrollView {
}
}

func adjustContentOffset(_ adjustInsets: (UIView) -> UIEdgeInsets) {
guard let firstResponder = firstResponder as? UIView else { return }
func adjustContentOffsetToRevealFirstResponder(_ adjustInsets: (_ firstResponder: UIView) -> UIEdgeInsets) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I didnt understand the adjustInsets parameter the first time I saw it. Thought it is a bool. Would a renaming make sense here to state it is actually a closure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is part of the public API so I don't feel like changing it in this bug fix PR, it will require a deprecation etc. It has documentation on the public method, I agree that it probably could have been more clear but you know, naming is hard : }

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see, is fine for me :)

}
}

func targetVisibleRectToRevealFirstResponder(_ adjustInsets: (_ firstResponder: UIView) -> UIEdgeInsets) -> CGRect? {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It is just for discussion. In my previous team we had the rule that every function should start with a verb. I'm used to that and therefore have a hard time reading this function because target is also a verb. In my previous team this would have been getTargetVisibleRectToRevealFirstResponder. If you ask me this makes function calls a lot clearer most of the time. Was something like this discussed earlier here? If everyone is used to it I think I can also get used to it ✌️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting suggestion, let's discuss this internally

@nataliq nataliq merged commit a16876e into master Sep 27, 2019
@nataliq nataliq deleted the fix-scroll-to-reveal-first-responder branch September 27, 2019 12:37
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