Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(KLazyListNode): add backward compatibility #90

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -37,6 +37,7 @@ class KLazyListNode(
* @param viewBuilderAction ViewBuilder which will result in view's interaction
* @param itemTypeBuilder Lambda with receiver where you pass your item providers
* @param positionMatcher Lambda which finds node by given position
* @param lengthSemanticsPropertyKey SemanticsPropertyKey with length list size
*
* @see ViewBuilder
*/
Expand All @@ -45,7 +46,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
Loading