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

[Feature/PreviewParameterProvider] Preview Parameter Provider 추가 #325

Merged
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(
}
}

class RoomPreviewParameterProvider : PreviewParameterProvider<Room> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

모듈 내부에 만 있다보니 internal 키워두 있는것이 좋을것 같네요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 모듈 내부에서 사용하는 모든 PreviewParameterProviderinternal 키워드 추가했습니다 :)

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 @@ -24,6 +24,8 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
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.compose.ui.unit.dp
import com.droidknights.app.core.designsystem.theme.KnightsTheme
Expand Down Expand Up @@ -153,24 +155,19 @@ private fun BookMarkItemForPreview(isEditMode: Boolean) {
)
}

@Preview(showBackground = true, backgroundColor = 0xFFF9F9F9)
@Composable
private fun BookmarkItemPreview() {
KnightsTheme {
Column {
BookMarkItemForPreview(isEditMode = false)
BookMarkItemForPreview(isEditMode = false)
}
}
class IsEditModePreviewParameterProvider : PreviewParameterProvider<Boolean> {
override val values = sequenceOf(true, false)
}

@Preview(showBackground = true, backgroundColor = 0xFFF9F9F9)
@Composable
private fun BookmarkItemEditModePreview() {
private fun BookmarkItemPreview(
@PreviewParameter(IsEditModePreviewParameterProvider::class) isEditMode: Boolean,
) {
KnightsTheme {
Column {
BookMarkItemForPreview(isEditMode = true)
BookMarkItemForPreview(isEditMode = true)
BookMarkItemForPreview(isEditMode = isEditMode)
BookMarkItemForPreview(isEditMode = isEditMode)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분까지 PreviewParameterProvider 까지는 불필요해보이네요.
그리고 하나면 이미 2개가 뜰것 같군요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다!
이전 코드로 롤백시키기 보다는 하나의 Preview내부에서 true하나, false 하나 하여 모든 case를 볼 수 있도록 수정하였습니다. 리뷰 감사합니다 :)

Copy link
Contributor Author

@chattymin chattymin Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가로 BookmarkedPreviewParameterProvider 또한 단순한 true/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(
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",
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,
)
}

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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
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.theme.Graphite
import com.droidknights.app.core.designsystem.theme.KnightsTheme
Expand Down Expand Up @@ -44,11 +46,16 @@ internal fun SessionDetailBookmarkStatePopup(bookmarked: Boolean) {
}
}

class BookmarkedPreviewParameterProvider : PreviewParameterProvider<Boolean> {
override val values = sequenceOf(true, false)
}

@Preview
@Composable
private fun BookmarkStatePopupPreview() {
private fun BookmarkStatePopupPreview(
@PreviewParameter(BookmarkedPreviewParameterProvider::class) bookmarked: Boolean,
) {
Column {
SessionDetailBookmarkStatePopup(bookmarked = true)
SessionDetailBookmarkStatePopup(bookmarked = false)
SessionDetailBookmarkStatePopup(bookmarked = bookmarked)
}
}
Loading