Skip to content

Commit

Permalink
fix: detect only vertical ScrollView for parentScrollViewTarget (#443)
Browse files Browse the repository at this point in the history
## 馃摐 Description

`parentScrollViewTarget` returns only vertical `ScrollView`.

## 馃挕 Motivation and Context

Actually it was an inconsistency between Android and iOS. On Android we
are checking that instance belongs to `ScrollView`. If it's `<ScrollView
horizontal` then on Android it'll render `HorizontalScrollView` so will
not go into `if (parentView is ScrollView) {` statement.

To achieve a similar behavior on iOS I added a check where compare
`frame` and `contentSize` to assure that `ScrollView` is a vertical.

Closes
#442

## 馃摙 Changelog

### iOS

- compare `frame` and `contentSize` to assure that `ScrollView` is a
vertical for detection `parentScrollViewTarget`;

## 馃 How Has This Been Tested?

Tested on iPhone 14 Pro.

## 馃摳 Screenshots (if appropriate):

|Before|After|
|-------|-----|

|![image](https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/85e46d85-318b-4866-9bb9-0ad669107ea5)|![image](https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/d3b1390a-c074-4f1b-ab2a-fc888901dad9)|

## 馃摑 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
  • Loading branch information
kirillzyusko committed May 14, 2024
1 parent 7577477 commit f572467
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ val EditText.parentScrollViewTarget: Int
val parentView = currentView.parent as? View

if (parentView is ScrollView) {
// If the parent is a ScrollView, return its id
// If the parent is a vertical ScrollView, return its id
return parentView.id
}

Expand Down
10 changes: 8 additions & 2 deletions ios/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ public extension Optional where Wrapped: UIResponder {
var currentResponder: UIResponder? = self

while let currentView = currentResponder {
// If the current responder is a UIScrollView (excluding UITextView), return its tag
if let scrollView = currentView as? UIScrollView, !(currentView is UITextView) {
// If the current responder is a vertical UIScrollView (excluding UITextView), return its tag
if let scrollView = currentView as? UIScrollView,
!(currentView is UITextView),
scrollView.contentSize.height > scrollView.frame.size.height
// it was fixed in swiftlint https://github.com/realm/SwiftLint/issues/3756 but a new release is not available yet
// swiftlint:disable all
{
// swiftlint:enable all
return scrollView.reactViewTag
}

Expand Down

0 comments on commit f572467

Please sign in to comment.