Skip to content

Commit 33a5d7b

Browse files
authored
fix: KeyboardChatScrollView + RefreshControl conflict (#1398)
## 📜 Description Resolveda non-working `KeyboardChatScrollView` if it's used together with `RefreshControl`. ## 💡 Motivation and Context If we use `RefreshControl` on Android it wraps whole `ScrollView`: <img width="490" height="218" alt="image" src="https://github.com/user-attachments/assets/469c257e-ba83-4ff3-9be3-13fc019c1646" /> As a result `getChildAt(0)` will return `RefreshControl` view (not `ScrollView`) and whole decoration approach will fail. To overcome this problem I added a small helper that traverse all children to find a necessary view to apply proper decoration. It fully fixes the problem. Closes #1396 ## 📢 Changelog <!-- High level overview of important changes --> <!-- For example: fixed status bar manipulation; added new types declarations; --> <!-- If your changes don't affect one of platform/language below - then remove this platform/language --> ### Android - added `findScrollView` helper; - use `findScrollView` instead of `this.getChildAt(0)` for more reliable `ScrollView` detection; ## 🤔 How Has This Been Tested? Tested manually on Pixel 9 Pro API 35. ## 📸 Screenshots (if appropriate): |Before|After| |-------|-----| |<img width="239" height="496" alt="image" src="https://github.com/user-attachments/assets/7c938b6b-95d3-48fe-b5d0-3a634c37cc94" />|<img width="236" height="495" alt="image" src="https://github.com/user-attachments/assets/8285a0e0-51b1-4f3d-8f47-30a0de8a4f78" />| ## 📝 Checklist - [x] CI successfully passed - [x] I added new mocks and corresponding unit-tests if library API was changed
1 parent 4a225d7 commit 33a5d7b

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

android/src/main/java/com/reactnativekeyboardcontroller/views/ClippingScrollViewDecoratorView.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.reactnativekeyboardcontroller.views
22

33
import android.annotation.SuppressLint
4+
import android.view.View
45
import android.view.ViewGroup
56
import android.widget.ScrollView
67
import com.facebook.react.uimanager.ThemedReactContext
@@ -37,7 +38,7 @@ class ClippingScrollViewDecoratorView(
3738
}
3839

3940
private fun decorateScrollView() {
40-
val scrollView = getChildAt(0) as? ScrollView ?: return
41+
val scrollView = findScrollView(this) ?: return
4142

4243
scrollView.clipToPadding = false
4344

@@ -66,4 +67,20 @@ class ClippingScrollViewDecoratorView(
6667

6768
appliedTopInsetPx = newTopInsetPx
6869
}
70+
71+
private fun findScrollView(view: View?): ScrollView? {
72+
var result: ScrollView? = null
73+
74+
if (view is ScrollView) {
75+
result = view
76+
} else if (view is ViewGroup) {
77+
var i = 0
78+
while (i < view.childCount && result == null) {
79+
result = findScrollView(view.getChildAt(i))
80+
i++
81+
}
82+
}
83+
84+
return result
85+
}
6986
}

0 commit comments

Comments
 (0)