Skip to content

Commit

Permalink
Merge pull request #325 from chattymin/feature/PreviewParameterProvider
Browse files Browse the repository at this point in the history
[Feature/PreviewParameterProvider] Preview Parameter Provider 추가
  • Loading branch information
taehwandev authored Jun 6, 2024
2 parents c6c8574 + 7cdd4f3 commit 6688976
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.droidknights.app.core.designsystem.theme.KnightsTheme
import com.droidknights.app.core.designsystem.theme.Purple01
Expand Down Expand Up @@ -77,14 +79,25 @@ internal fun BookmarkCard(
}
}

internal class RoomPreviewParameterProvider : PreviewParameterProvider<Room> {
override val values = sequenceOf(
Room.TRACK1,
Room.TRACK2,
Room.TRACK3,
Room.ETC
)
}

@Preview
@Composable
private fun BookmarkCardPreview() {
private fun BookmarkCardPreview(
@PreviewParameter(RoomPreviewParameterProvider::class) room: Room,
) {
KnightsTheme {
Box {
BookmarkCard(
tagLabel = "효율적인 코드 베이스",
room = Room.TRACK2,
room = room,
title = "Jetpack Compose에 있는 것, 없는것",
speaker = "홍길동"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,8 @@ private fun BookMarkItemForPreview(isEditMode: Boolean) {
private fun BookmarkItemPreview() {
KnightsTheme {
Column {
BookMarkItemForPreview(isEditMode = false)
BookMarkItemForPreview(isEditMode = false)
}
}
}

@Preview(showBackground = true, backgroundColor = 0xFFF9F9F9)
@Composable
private fun BookmarkItemEditModePreview() {
KnightsTheme {
Column {
BookMarkItemForPreview(isEditMode = true)
BookMarkItemForPreview(isEditMode = true)
BookMarkItemForPreview(isEditMode = false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand Down Expand Up @@ -265,11 +267,10 @@ private fun Footer(modifier: Modifier = Modifier) {

private const val SHIMMERING_ITEM_COUNT = 4

@Preview
@Composable
private fun ContributorScreenPreview() {
ContributorScreen(
uiState = ContributorsUiState.Contributors(
internal class ContributorPreviewParameterProvider : PreviewParameterProvider<ContributorsUiState> {
override val values = sequenceOf(
ContributorsUiState.Loading,
ContributorsUiState.Contributors(
persistentListOf(
Contributor(
0L,
Expand All @@ -285,16 +286,17 @@ private fun ContributorScreenPreview() {
"https://github.com/droidknights",
),
)
),
onBackClick = {},
)
)
}

@Preview
@Composable
private fun ContributorScreenLoadingPreview() {
private fun ContributorScreenPreview(
@PreviewParameter(ContributorPreviewParameterProvider::class) uiState: ContributorsUiState,
) {
ContributorScreen(
uiState = ContributorsUiState.Loading,
uiState = uiState,
onBackClick = {},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import com.droidknights.app.core.designsystem.component.IconTextChip
import com.droidknights.app.core.designsystem.component.KnightsCard
Expand Down Expand Up @@ -203,30 +205,86 @@ private fun BookmarkImage(
private val CardContentPadding =
PaddingValues(start = 24.dp, top = 16.dp, end = 24.dp, bottom = 24.dp)

@Preview
@Composable
private fun SessionCardPreview() {
val fakeSession = Session(
id = "1",
title = "Jetpack Compose에 있는 것, 없는 것",
content = "",
speakers = listOf(
Speaker(
name = "안성용",
introduction = "안드로이드 개발자",
imageUrl = "https://picsum.photos/200",
internal class SessionPreviewParameterProvider : PreviewParameterProvider<Session> {
override val values = sequenceOf(
Session( // single speaker with out bookmark
id = "1",
title = "Jetpack Compose에 있는 것, 없는 것",
content = "",
speakers = listOf(
Speaker(
name = "안성용",
introduction = "안드로이드 개발자",
imageUrl = "https://picsum.photos/200",
),
),
tags = listOf(
Tag("효율적인 코드베이스")
),
startTime = LocalDateTime(2023, 9, 12, 16, 10, 0),
endTime = LocalDateTime(2023, 9, 12, 16, 45, 0),
room = Room.TRACK1,
isBookmarked = false,
),
Session( // single speaker with bookmark
id = "1",
title = "Jetpack Compose에 있는 것, 없는 것",
content = "",
speakers = listOf(
Speaker(
name = "안성용",
introduction = "안드로이드 개발자",
imageUrl = "https://picsum.photos/200",
),
),
tags = listOf(
Tag("효율적인 코드베이스")
),
startTime = LocalDateTime(2023, 9, 12, 16, 10, 0),
endTime = LocalDateTime(2023, 9, 12, 16, 45, 0),
room = Room.TRACK1,
isBookmarked = true,
),
tags = listOf(
Tag("효율적인 코드베이스")
Session( // multi speakers
id = "1",
title = "Jetpack Compose에 있는 것, 없는 것",
content = "",
speakers = listOf(
Speaker(
name = "안성용",
introduction = "안드로이드 개발자",
imageUrl = "https://picsum.photos/200",
),
Speaker(
name = "안성용",
introduction = "안드로이드 개발자",
imageUrl = "https://picsum.photos/200",
),
Speaker(
name = "안성용",
introduction = "안드로이드 개발자",
imageUrl = "https://picsum.photos/200",
),
),
tags = listOf(
Tag("효율적인 코드베이스"),
Tag("효율적인 코드베이스"),
Tag("효율적인 코드베이스")
),
startTime = LocalDateTime(2023, 9, 12, 16, 10, 0),
endTime = LocalDateTime(2023, 9, 12, 16, 45, 0),
room = Room.TRACK1,
isBookmarked = false,
),
startTime = LocalDateTime(2023, 9, 12, 16, 10, 0),
endTime = LocalDateTime(2023, 9, 12, 16, 45, 0),
room = Room.TRACK1,
isBookmarked = false,
)
}

@Preview
@Composable
private fun SessionCardPreview(
@PreviewParameter(SessionPreviewParameterProvider::class) session: Session,
) {
KnightsTheme {
SessionCard(fakeSession)
SessionCard(session)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.droidknights.app.core.designsystem.component.TextChip
import com.droidknights.app.core.model.Room
import com.droidknights.app.core.ui.textRes
Expand Down Expand Up @@ -33,3 +36,26 @@ internal fun TimeChip(dateTime: LocalDateTime) {
labelColor = MaterialTheme.colorScheme.onTertiaryContainer,
)
}

internal class RoomPreviewParameterProvider : PreviewParameterProvider<Room> {
override val values = sequenceOf(
Room.TRACK1,
Room.TRACK2,
Room.TRACK3,
Room.ETC
)
}

@Preview
@Composable
fun TrackChipPreview(
@PreviewParameter(RoomPreviewParameterProvider::class) room: Room,
) {
TrackChip(room)
}

@Preview
@Composable
fun TimeChipPreview() {
TimeChip(LocalDateTime(2022, 1, 1, 10, 22))
}

0 comments on commit 6688976

Please sign in to comment.