-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* MyScaffold, Toast 초기 후구현 * 구현 완료 * 리뷰 반영 - 기존 YdsScaffold 대체 - preview 맨 아래로, private 변경 - 기존 다른 파일들도 preview function은 전부 private하게 변경 - 인터페이스, enum 맨 위로 - YdsEasing 사용 - Toast Animation 파일 분리 - 기타 코드 정리 * 리뷰 반영 - 코드수정 - 네이밍 변경 - 주석 작성중. - 이해완료 * 리뷰 반영 - 패키지 변경 - 최소높이 제거 - 네이밍 변경 - 주석 작성 * 디버그 용 함수 제거 * rememberToastHostState 생성 * ToastDuration Enum애 시간 정의 * 텍스트 가운데 정렬 로직 추가 * rememberToastHost -> ToastHost.kt로 이동 * 오타 수정
- Loading branch information
1 parent
5d97d2c
commit 23fde8d
Showing
19 changed files
with
585 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
196 changes: 180 additions & 16 deletions
196
compose/src/main/java/com/yourssu/design/system/compose/base/YdsScaffold.kt
This file contains 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 |
---|---|---|
@@ -1,39 +1,203 @@ | ||
package com.yourssu.design.system.compose.base | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.SubcomposeLayout | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.yourssu.design.system.compose.R | ||
import com.yourssu.design.system.compose.YdsTheme | ||
import com.yourssu.design.system.compose.atom.BoxButton | ||
import com.yourssu.design.system.compose.atom.TopBarButton | ||
import com.yourssu.design.system.compose.component.TopBar | ||
import com.yourssu.design.system.compose.component.toast.ToastDuration | ||
import com.yourssu.design.system.compose.component.toast.ToastHost | ||
import com.yourssu.design.system.compose.component.toast.ToastHostState | ||
import com.yourssu.design.system.compose.component.toast.rememberToastHostState | ||
import com.yourssu.design.system.compose.foundation.LocalContentColor | ||
import kotlinx.coroutines.launch | ||
|
||
private enum class ScaffoldLayoutContent { TopBar, MainContent, Snackbar, BottomBar } | ||
|
||
@Composable | ||
fun YdsScaffold( | ||
modifier: Modifier = Modifier, | ||
toastHostState: ToastHostState = rememberToastHostState(), | ||
topBar: @Composable () -> Unit = {}, | ||
bottomBar: @Composable () -> Unit = {}, | ||
toastHost: @Composable (ToastHostState) -> Unit = { ToastHost(it) }, | ||
backgroundColor: Color = YdsTheme.colors.bgNormal, | ||
contentColor: Color = LocalContentColor.current, | ||
content: @Composable () -> Unit | ||
content: @Composable (PaddingValues) -> Unit | ||
) { | ||
Surface(modifier = modifier, color = backgroundColor, contentColor = contentColor) { | ||
ScaffoldLayout( | ||
topBar = topBar, | ||
bottomBar = bottomBar, | ||
toast = { toastHost(toastHostState) }, | ||
content = content | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun ScaffoldLayout( | ||
topBar: @Composable () -> Unit, | ||
bottomBar: @Composable () -> Unit, | ||
toast: @Composable () -> Unit, | ||
content: @Composable (PaddingValues) -> Unit | ||
) { | ||
// TODO: Toast 추가 | ||
Surface( | ||
modifier = modifier, | ||
color = backgroundColor, | ||
contentColor = contentColor, | ||
) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
verticalArrangement = Arrangement.SpaceBetween, | ||
) { | ||
topBar() | ||
Box(Modifier.weight(1f)) { | ||
content() | ||
} | ||
bottomBar() | ||
val pxValue = LocalDensity.current.run { ToastApartFromBottom.toPx() }.toInt() | ||
|
||
SubcomposeLayout { constraints -> | ||
val layoutWidth = constraints.maxWidth | ||
val layoutHeight = constraints.maxHeight | ||
|
||
val looseConstraints = constraints.copy(minWidth = 0, minHeight = 0) | ||
|
||
layout(layoutWidth, layoutHeight) { | ||
|
||
val topBarPlaceables = subcompose(ScaffoldLayoutContent.TopBar, topBar).map { | ||
it.measure(looseConstraints) | ||
} | ||
|
||
|
||
val topBarHeight = topBarPlaceables.maxByOrNull { it.height }?.height ?: 0 | ||
|
||
val toastPlaceables = subcompose(ScaffoldLayoutContent.Snackbar, toast).map { | ||
it.measure(looseConstraints) | ||
} | ||
|
||
val toastHeight = toastPlaceables.maxByOrNull { it.height }?.height ?: 0 | ||
|
||
val bottomBarPlaceables = subcompose(ScaffoldLayoutContent.BottomBar, bottomBar).map { | ||
it.measure(looseConstraints) | ||
} | ||
|
||
val bottomBarHeight = bottomBarPlaceables.maxByOrNull { it.height }?.height ?: 0 | ||
|
||
val snackbarOffsetFromBottom = if (toastHeight != 0) { | ||
toastHeight + pxValue | ||
} else { | ||
0 | ||
} | ||
|
||
val bodyContentHeight = layoutHeight - topBarHeight | ||
|
||
val bodyContentPlaceables = subcompose(ScaffoldLayoutContent.MainContent) { | ||
val innerPadding = PaddingValues(bottom = bottomBarHeight.toDp()) | ||
content(innerPadding) | ||
}.map { it.measure(looseConstraints.copy(maxHeight = bodyContentHeight)) } | ||
|
||
bodyContentPlaceables.forEach { | ||
it.place(0, topBarHeight) | ||
} | ||
topBarPlaceables.forEach { | ||
it.place(0, 0) | ||
} | ||
toastPlaceables.forEach { | ||
it.place(0, layoutHeight - snackbarOffsetFromBottom) | ||
} | ||
// The bottom bar is always at the bottom of the layout | ||
bottomBarPlaceables.forEach { | ||
it.place(0, layoutHeight - bottomBarHeight) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private val ToastApartFromBottom = 72.dp | ||
|
||
|
||
@Preview | ||
@Composable | ||
private fun YdsScaffoldPreview() { | ||
val toastHostState: ToastHostState = rememberToastHostState() | ||
val scope = rememberCoroutineScope() | ||
|
||
YdsScaffold( | ||
toastHostState = toastHostState, | ||
topBar = { | ||
TopBar( | ||
title = "타이틀", | ||
navigationIcon = { | ||
TopBarButton( | ||
icon = R.drawable.ic_arrow_left_line, | ||
isDisabled = false, | ||
) | ||
}, | ||
actions = { | ||
TopBarButton( | ||
icon = R.drawable.ic_bell_line, | ||
isDisabled = false, | ||
) | ||
TopBarButton( | ||
icon = R.drawable.ic_search_line, | ||
isDisabled = false, | ||
onClick = { | ||
scope.launch { | ||
toastHostState.showToast( | ||
message = "Snackbar", | ||
duration = ToastDuration.SHORT | ||
) | ||
} | ||
} | ||
) | ||
} | ||
) | ||
}, | ||
bottomBar = { | ||
Box( | ||
modifier = Modifier | ||
.size(72.dp) | ||
.background(Color.Black), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
YdsText( | ||
text = "This is 72.dp", | ||
style = YdsTheme.typography.body1, | ||
color = Color.White | ||
) | ||
} | ||
}, | ||
toastHost = { ToastHost(it) }, | ||
content = { | ||
Column( | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
modifier = Modifier.fillMaxSize() | ||
) { | ||
YdsText(text = "content", style = YdsTheme.typography.body1) | ||
BoxButton(onClick = { | ||
scope.launch { | ||
toastHostState.showToast( | ||
message = "잠, 아스라히 노새, 멀듯이, 흙으로 봅니다.", | ||
duration = ToastDuration.SHORT | ||
) | ||
} | ||
}, text = "짧은 토스트 버튼") | ||
BoxButton(onClick = { | ||
scope.launch { | ||
toastHostState.showToast( | ||
message = "잠, 아스라히 노새, 멀듯이, 흙으로 봅니다. 때 불러 가슴속에 나의 풀이 이름과 언덕 오면 가을 봅니다.", | ||
duration = ToastDuration.LONG | ||
) | ||
} | ||
}, text = "긴 토스트 버튼") | ||
} | ||
} | ||
) | ||
} | ||
|
This file contains 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
Oops, something went wrong.