-
Notifications
You must be signed in to change notification settings - Fork 1
PrezelSnackBar 구현 #47
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
620c1bf
feat: PrezelSnackBar 컴포넌트 추가
HamBeomJoon f20165b
style: PrezelSnackBar Preview 코드 스타일 수정
HamBeomJoon 098ea6e
Merge remote-tracking branch 'origin/develop' into feat/#33-prezel-sn…
HamBeomJoon 0e682ec
feat: PrezelSnackBar Preview 분리 및 추가
HamBeomJoon 0e1dcba
refactor: PrezelSnackbar 개편 및 SnackbarHost 관련 컴포넌트 추가
HamBeomJoon db516c8
style: PrezelSnackbar 코드 포맷팅 수정
HamBeomJoon 534b6a5
style: PrezelSnackbar.kt 코드 스타일 및 경고 수정
HamBeomJoon b5156b2
Merge remote-tracking branch 'origin/develop' into feat/#33-prezel-sn…
HamBeomJoon 4f18842
refactor: PrezelSnackbar 구성 요소 및 SnackbarHost 확장 함수 개선
HamBeomJoon 2db93d3
refactor: PrezelSnackbar 구성 요소 및 SnackbarHost 확장 함수 개선
HamBeomJoon 14a69f1
refactor: Snackbar 내부 버튼 크기 조정 및 관련 확장 함수 위치 변경
HamBeomJoon f0c9d91
fix: PrezelSnackbar 내 Modifier 참조 오류 수정
HamBeomJoon d867401
chore: PrezelSnackbar 텍스트 레이아웃 수정
HamBeomJoon 1af4cb9
refactor: PrezelSnackbarVisuals 내부의 withDismissAction 필드 수정
HamBeomJoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
...stem/src/main/java/com/team/prezel/core/designsystem/component/snackbar/PrezelSnackbar.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package com.team.prezel.core.designsystem.component.snackbar | ||
|
|
||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.Snackbar | ||
| import androidx.compose.material3.SnackbarData | ||
| import androidx.compose.material3.SnackbarDuration | ||
| import androidx.compose.material3.SnackbarVisuals | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import com.team.prezel.core.designsystem.component.button.PrezelButton | ||
| import com.team.prezel.core.designsystem.component.button.PrezelButtonSize | ||
| import com.team.prezel.core.designsystem.component.button.PrezelButtonStyle | ||
| import com.team.prezel.core.designsystem.component.button.PrezelButtonType | ||
| import com.team.prezel.core.designsystem.foundation.typography.PrezelTextStyles | ||
| import com.team.prezel.core.designsystem.icon.DrawableIcon | ||
| import com.team.prezel.core.designsystem.icon.IconSource | ||
| import com.team.prezel.core.designsystem.icon.PrezelIcons | ||
| import com.team.prezel.core.designsystem.preview.PreviewScaffold | ||
| import com.team.prezel.core.designsystem.preview.ThemePreview | ||
| import com.team.prezel.core.designsystem.theme.PrezelColorScheme | ||
| import com.team.prezel.core.designsystem.theme.PrezelTheme | ||
|
|
||
| @Composable | ||
| fun PrezelSnackbar( | ||
| data: SnackbarData, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| val visuals = data.visuals | ||
| val leadingIcon = visuals.leadingIconOrNull() | ||
| val actionLabel = visuals.actionLabel | ||
|
|
||
| Snackbar( | ||
| modifier = modifier, | ||
| shape = PrezelTheme.shapes.V12, | ||
| containerColor = PrezelColorScheme.Dark.bgMedium, | ||
| contentColor = PrezelColorScheme.Dark.textLarge, | ||
| action = actionLabel?.let { label -> | ||
| { | ||
| PrezelButton( | ||
| text = label, | ||
| onClick = { data.performAction() }, | ||
| style = PrezelButtonStyle(buttonType = PrezelButtonType.GHOST, buttonSize = PrezelButtonSize.SMALL), | ||
| ) | ||
| } | ||
| }, | ||
| ) { | ||
| Row( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { | ||
| leadingIcon?.let { | ||
| PrezelSnackbarLeadingIcon(icon = it) | ||
| Spacer(Modifier.width(PrezelTheme.spacing.V8)) | ||
| } | ||
|
|
||
| Text( | ||
| text = visuals.message, | ||
| style = PrezelTextStyles.Body3Regular.toTextStyle(), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun PrezelSnackbarLeadingIcon( | ||
| icon: IconSource, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| Icon( | ||
| painter = icon.painter(), | ||
| contentDescription = icon.contentDescription(), | ||
| modifier = modifier.size(20.dp), | ||
| tint = PrezelColorScheme.Dark.iconLarge, | ||
| ) | ||
| } | ||
|
|
||
| private fun SnackbarVisuals.leadingIconOrNull(): IconSource? = (this as? PrezelSnackbarVisuals)?.leadingIcon | ||
|
|
||
| @ThemePreview | ||
| @Composable | ||
| private fun PrezelSnackBarPreview_Cases() { | ||
| PrezelTheme { | ||
| PreviewScaffold { | ||
| Text("Action O / Icon O") | ||
| PrezelSnackbar( | ||
| data = previewData(message = "Message", actionLabel = "Action", leadingIcon = DrawableIcon(PrezelIcons.Blank)), | ||
| ) | ||
|
|
||
| Text("Action X / Icon O") | ||
| PrezelSnackbar( | ||
| data = previewData( | ||
| message = "Message Message Message ", | ||
| actionLabel = null, | ||
| leadingIcon = DrawableIcon(PrezelIcons.Blank), | ||
| ), | ||
| ) | ||
|
|
||
| Text("Action O / Icon X") | ||
| PrezelSnackbar( | ||
| data = previewData(message = "Message Message Message Message Message", actionLabel = "Action"), | ||
| ) | ||
|
|
||
| Text("Action X / Icon X") | ||
| PrezelSnackbar( | ||
| data = previewData(message = "Message Message Message Message Message", actionLabel = null), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun previewData( | ||
| message: String, | ||
| actionLabel: String?, | ||
| leadingIcon: IconSource? = null, | ||
| ): SnackbarData = | ||
| PreviewSnackbarData( | ||
| visuals = PrezelSnackbarVisuals( | ||
| message = message, | ||
| actionLabel = actionLabel, | ||
| withDismissAction = false, | ||
| duration = SnackbarDuration.Short, | ||
| leadingIcon = leadingIcon, | ||
| ), | ||
| ) | ||
|
|
||
| @Suppress("EmptyFunctionBlock") | ||
| private class PreviewSnackbarData( | ||
| override val visuals: SnackbarVisuals, | ||
| ) : SnackbarData { | ||
| override fun dismiss() {} | ||
|
|
||
| override fun performAction() {} | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
...system/src/main/java/com/team/prezel/core/designsystem/component/snackbar/SnackbarHost.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package com.team.prezel.core.designsystem.component.snackbar | ||
|
|
||
| import androidx.compose.material3.SnackbarDuration | ||
| import androidx.compose.material3.SnackbarHost | ||
| import androidx.compose.material3.SnackbarHostState | ||
| import androidx.compose.material3.SnackbarResult | ||
| import androidx.compose.material3.SnackbarVisuals | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import com.team.prezel.core.designsystem.icon.IconSource | ||
|
|
||
| internal data class PrezelSnackbarVisuals( | ||
| override val message: String, | ||
| override val actionLabel: String?, | ||
| override val withDismissAction: Boolean = false, | ||
| override val duration: SnackbarDuration, | ||
| val leadingIcon: IconSource?, | ||
| ) : SnackbarVisuals | ||
|
|
||
| suspend fun SnackbarHostState.showPrezelSnackbar( | ||
| message: String, | ||
| leadingIcon: IconSource? = null, | ||
| actionLabel: String? = null, | ||
| duration: SnackbarDuration = SnackbarDuration.Short, | ||
| onAction: (() -> Unit)? = null, | ||
| onDismiss: (() -> Unit)? = null, | ||
| ) { | ||
HamBeomJoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| require((actionLabel == null) == (onAction == null)) { | ||
| "actionLabel과 onAction은 둘 다 있거나 둘 다 없어야 합니다." | ||
| } | ||
|
|
||
| val result = showSnackbar( | ||
| visuals = PrezelSnackbarVisuals( | ||
| message = message, | ||
| actionLabel = actionLabel, | ||
| duration = duration, | ||
| leadingIcon = leadingIcon, | ||
| ), | ||
| ) | ||
|
|
||
| when (result) { | ||
| SnackbarResult.ActionPerformed -> onAction?.invoke() | ||
| SnackbarResult.Dismissed -> onDismiss?.invoke() | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun PrezelSnackbarHost( | ||
| hostState: SnackbarHostState, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| SnackbarHost( | ||
| hostState = hostState, | ||
| modifier = modifier, | ||
| ) { data -> | ||
| PrezelSnackbar(data = data) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.