Skip to content

Commit

Permalink
fix(KLazyListNode): add backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Vacxe committed Jul 24, 2024
1 parent 24cb1ce commit 5b441cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.assert
import io.github.kakaocup.compose.exception.KakaoComposeException
import io.github.kakaocup.compose.utilities.checkNotNull

interface LazyListNodeAssertions : NodeAssertions {
val lengthSemanticsPropertyKey: SemanticsPropertyKey<Int>
val lengthSemanticsPropertyKey: SemanticsPropertyKey<Int>?

/**
* Asserts that the lazy list length contains the given [length].
Expand All @@ -21,7 +23,9 @@ interface LazyListNodeAssertions : NodeAssertions {
private fun hasLazyListLength(length: Int): SemanticsMatcher = SemanticsMatcher(
"The length of the lazy list is expected to be ${length}, but the actual size is different"
) { node ->
val actualLength = node.config.getOrNull(lengthSemanticsPropertyKey) ?: error("Lazy list does not contain $lengthSemanticsPropertyKey modifier")
val actualLength = node.config.getOrNull(
lengthSemanticsPropertyKey ?: throw KakaoComposeException("lengthSemanticsPropertyKey not provided to `KLazyListNode` constructor")
) ?: error("Lazy list does not contain $lengthSemanticsPropertyKey modifier")
return@SemanticsMatcher actualLength == length
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ abstract class BaseNode<out T : BaseNode<T>> constructor(

return semanticsMatcherList.reduce { finalMatcher, matcher -> finalMatcher and matcher }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class KLazyListNode(
nodeMatcher: NodeMatcher,
itemTypeBuilder: KLazyListItemBuilder.() -> Unit,
val positionMatcher: (position: Int) -> SemanticsMatcher,
override val lengthSemanticsPropertyKey: SemanticsPropertyKey<Int>,
override val lengthSemanticsPropertyKey: SemanticsPropertyKey<Int>? = null,
) : BaseNode<KLazyListNode>(semanticsProvider, nodeMatcher),
LazyListNodeAssertions {
val semanticsMatcher = nodeMatcher.matcher
Expand All @@ -45,7 +45,7 @@ class KLazyListNode(
viewBuilderAction: ViewBuilder.() -> Unit,
itemTypeBuilder: KLazyListItemBuilder.() -> Unit,
positionMatcher: (position: Int) -> SemanticsMatcher,
lengthSemanticsPropertyKey: SemanticsPropertyKey<Int>
lengthSemanticsPropertyKey: SemanticsPropertyKey<Int>? = null
) : this(
semanticsProvider = semanticsProvider,
nodeMatcher = ViewBuilder().apply(viewBuilderAction).build(),
Expand Down

0 comments on commit 5b441cc

Please sign in to comment.