Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit ad96309

Browse files
committed
fix(xml-inflater): add default implementation for IViewGroup.findNearestChild
1 parent 2cd7bb9 commit ad96309

File tree

1 file changed

+15
-1
lines changed
  • xml-inflater/src/main/java/com/itsaky/androidide/inflater

1 file changed

+15
-1
lines changed

xml-inflater/src/main/java/com/itsaky/androidide/inflater/IViewGroup.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,21 @@ interface IViewGroup : IView, Iterable<IView> {
138138
* existing child views with the given coordinates.
139139
*/
140140
fun findNearestChild(x: Float, y: Float, vertical: Boolean = true
141-
): Pair<IView, Int>?
141+
): Pair<IView, Int>? {
142+
for (i in 0 until childCount) {
143+
val child = get(i)
144+
val rect = child.getViewRect()
145+
if (vertical && (y > rect.top && y < rect.bottom)) {
146+
return child to i
147+
}
148+
149+
if (!vertical && (x > rect.left && x < rect.right)) {
150+
return child to i
151+
}
152+
}
153+
154+
return null
155+
}
142156

143157
/**
144158
* Adds the given hierarchy change listener.

0 commit comments

Comments
 (0)