feat(feed): 피드 크기 계산 계약을 추가한다
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package kr.co.vividnext.sodalive.v2.widget.feed
|
||||
|
||||
data class FeedContentImageSize(
|
||||
val widthDp: Int,
|
||||
val heightDp: Int
|
||||
) {
|
||||
companion object {
|
||||
fun from(widthDp: Int, category: FeedContentCategory): FeedContentImageSize {
|
||||
require(widthDp > 0) { "widthDp must be greater than 0." }
|
||||
val height = (widthDp * category.ratioHeight.toFloat() / category.ratioWidth).toInt()
|
||||
return FeedContentImageSize(widthDp = widthDp, heightDp = height)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package kr.co.vividnext.sodalive.v2.widget.feed
|
||||
|
||||
data class FeedSize(
|
||||
val rootWidthDp: Int
|
||||
) {
|
||||
companion object {
|
||||
private const val FIGMA_ROOT_WIDTH_DP = 374
|
||||
|
||||
fun from(
|
||||
variant: FeedVariant,
|
||||
widthMode: FeedWidthMode,
|
||||
parentAvailableWidthDp: Int,
|
||||
horizontalItemDecorationDp: Int = 0
|
||||
): FeedSize {
|
||||
val width = when (widthMode) {
|
||||
FeedWidthMode.FigmaFixed -> FIGMA_ROOT_WIDTH_DP
|
||||
FeedWidthMode.ParentAvailable -> {
|
||||
require(parentAvailableWidthDp > 0) { "parentAvailableWidthDp must be greater than 0." }
|
||||
require(horizontalItemDecorationDp >= 0) { "horizontalItemDecorationDp must be 0 or greater." }
|
||||
parentAvailableWidthDp - horizontalItemDecorationDp
|
||||
}
|
||||
}
|
||||
require(width > 0) { "rootWidthDp must be greater than 0." }
|
||||
return FeedSize(rootWidthDp = width)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package kr.co.vividnext.sodalive.v2.widget.feed
|
||||
|
||||
enum class FeedWidthMode {
|
||||
FigmaFixed,
|
||||
ParentAvailable
|
||||
}
|
||||
Reference in New Issue
Block a user