Skip to content

Commit 0c95855

Browse files
committed
removeChildAt reuse
1 parent 3694de4 commit 0c95855

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

korge/src/korlibs/korge/view/Container.kt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,7 @@ open class Container(
177177
@KorgeUntested
178178
fun getChildByName(name: String): View? = __children.firstOrNull { it.name == name }
179179

180-
fun removeChildAt(index: Int): Boolean {
181-
require(index >= 0) { "Index should be greater than or equal to 0" }
182-
require(index < numChildren) { "Index should be less than numChildren: $numChildren, but was: $index" }
183-
184-
val view = getChildAt(index)
185-
view.parent = null
186-
view.index = -1
187-
188-
__children.removeAt(index)
189-
190-
for (i in index until numChildren) __children[i].index = i
191-
192-
invalidateZIndexChildren()
193-
invalidateContainer()
194-
invalidateLocalBounds()
195-
196-
return true
197-
}
180+
fun removeChildAt(index: Int) = removeChildAt(index, 1) == 1
198181

199182
fun removeChildAt(index: Int, count: Int): Int {
200183
if (count <= 0 || index < 0) return 0
@@ -483,9 +466,7 @@ open class Container(
483466
* Remarks: If the parent of [view] is not this container, this function doesn't do anything.
484467
*/
485468
fun removeChild(view: View?): Boolean {
486-
require(view != null) { "Removed view should not be null" }
487-
require(view.parent === this) { "View $view is not a child of this container" }
488-
check(getChildAt(view.index) === view) { "View at index ${view.index} is not $view" }
469+
if (view?.parent !== this) return false
489470

490471
return removeChildAt(view.index)
491472
}

0 commit comments

Comments
 (0)