Skip to content

Commit

Permalink
Support BaseMountingView in Traverser test
Browse files Browse the repository at this point in the history
Summary:
While looking at tests that are failing for Vertical Scroll Primitive I noticed that this one was failing.
So changing LithoView -> BaseMountingView to support Nested Litho Trees

Reviewed By: kingsleyadio

Differential Revision: D68214033

fbshipit-source-id: bfc7da5c1b48281d54b9a533fa034df5c1504eca
  • Loading branch information
Anna Powolny authored and facebook-github-bot committed Jan 16, 2025
1 parent 88ce877 commit 7661feb
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.facebook.litho.testing.api

import android.annotation.SuppressLint
import android.view.ViewGroup
import com.facebook.litho.BaseMountingView
import com.facebook.litho.Component
import com.facebook.litho.LithoLayoutResult
import com.facebook.litho.LithoView
Expand Down Expand Up @@ -119,14 +120,12 @@ class LithoViewComponentsTraverser {
}

@SuppressLint("RestrictedApi")
private fun LithoView.extractLayoutResult(isRoot: Boolean): LithoLayoutResult? {
val committedLayoutState = componentTree?.committedLayoutState

check(!isRoot || committedLayoutState != null) {
private fun BaseMountingView.extractLayoutResult(isRoot: Boolean): LithoLayoutResult? {
check(!isRoot || currentLayoutState != null) {
"No ComponentTree/Committed Layout/Layout Root found. Please call render() first"
}

return committedLayoutState?.rootLayoutResult as? LithoLayoutResult
return currentLayoutState?.rootLayoutResult as? LithoLayoutResult
}

private val LithoLayoutResult.childResults: List<LithoLayoutResult>
Expand All @@ -149,13 +148,13 @@ class LithoViewComponentsTraverser {
* found [LithoView] will be used to start a new traversal with [traverse] - which will enable the
* full traverse (even on scenarios of nested [LithoView]
*/
private val ViewGroup.firstLevelInnerLithoViews: List<LithoView>
private val ViewGroup.firstLevelInnerLithoViews: List<BaseMountingView>
get() {
val lithoViews = mutableListOf<LithoView>()
val lithoViews = mutableListOf<BaseMountingView>()

for (i in 0..childCount) {
val child = getChildAt(i)
if (child is LithoView) {
if (child is BaseMountingView) {
lithoViews.add(child)
} else {
(child as? ViewGroup)?.let { lithoViews.addAll(child.firstLevelInnerLithoViews) }
Expand Down

0 comments on commit 7661feb

Please sign in to comment.