-
Notifications
You must be signed in to change notification settings - Fork 0
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
[CAT-140] MnTopAppBar 구현 / Icon LocalContentColor로 수정 #42
Changes from all commits
df022ca
b7b3d1b
444f5d0
7f9900a
18be226
7de91a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package com.pomonyang.mohanyang.presentation.designsystem.topappbar | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.WindowInsetsSides | ||
import androidx.compose.foundation.layout.only | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.systemBars | ||
import androidx.compose.foundation.layout.windowInsetsPadding | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.LocalTextStyle | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.Layout | ||
import androidx.compose.ui.layout.layoutId | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.mohanyang.presentation.R | ||
import com.pomonyang.mohanyang.presentation.designsystem.icon.MnMediumIcon | ||
import com.pomonyang.mohanyang.presentation.theme.MnTheme | ||
import com.pomonyang.mohanyang.presentation.util.dpToPx | ||
import com.pomonyang.mohanyang.presentation.util.noRippleClickable | ||
|
||
@Composable | ||
fun MnTopAppBar( | ||
modifier: Modifier = Modifier, | ||
contentStyle: TextStyle = MnTheme.typography.bodySemiBold, | ||
topAppBarColors: MnAppBarColors = MnTopAppBarDefaults.topAppBarColors(), | ||
windowInsets: WindowInsets = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal + WindowInsetsSides.Top), | ||
content: @Composable () -> Unit = {}, | ||
navigationIcon: @Composable () -> Unit = {}, | ||
actions: @Composable () -> Unit = {} | ||
) { | ||
val iconHorizontalPadding = MnTopAppBarDefaults.iconHorizontalPadding.dpToPx().toInt() | ||
val topAppBarHeightToPx = MnTopAppBarDefaults.height.dpToPx().toInt() | ||
Layout( | ||
content = { | ||
Box(Modifier.layoutId(NAVIGATION_ICON)) { | ||
CompositionLocalProvider( | ||
value = LocalContentColor provides topAppBarColors.navigationIconContentColor, | ||
content = navigationIcon | ||
) | ||
} | ||
Box(Modifier.layoutId(ACTIONS)) { | ||
CompositionLocalProvider( | ||
value = LocalContentColor provides topAppBarColors.actionIconContentColor, | ||
content = actions | ||
) | ||
} | ||
Comment on lines
+49
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기하다가 느낀건데 #38 (comment) 이 코멘트 번복해도 될까 👀 막상 컴포넌트 만들면서 Color들 좀 사용 편하게 해주려고 하니까 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. provide 하는 방식으로 구현하면 LocalContentColor 이렇게 바꾸는게 맞을 것 같네요~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그럼 내가 슬쩍 반영해둬도 될까?🧎♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오키오키 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그럼 다른 리뷰 없으면 저거만 수정하고 머지할게! |
||
Box(Modifier.layoutId(CONTENT)) { | ||
CompositionLocalProvider( | ||
LocalContentColor provides topAppBarColors.titleContentColor, | ||
LocalTextStyle provides contentStyle, | ||
content = content | ||
) | ||
} | ||
}, | ||
modifier = modifier | ||
.windowInsetsPadding(windowInsets) | ||
.background(topAppBarColors.containerColor) | ||
) { measurables, constraints -> | ||
val navigationIconPlaceable = measurables.first { it.layoutId == NAVIGATION_ICON }.measure(constraints) | ||
val actionsPlaceable = measurables.first { it.layoutId == ACTIONS }.measure(constraints) | ||
val contentPlaceable = measurables.first { it.layoutId == CONTENT }.measure(constraints) | ||
|
||
layout(constraints.maxWidth, topAppBarHeightToPx) { | ||
navigationIconPlaceable.place(iconHorizontalPadding, (topAppBarHeightToPx - navigationIconPlaceable.height) / 2) | ||
actionsPlaceable.place(constraints.maxWidth - actionsPlaceable.width - iconHorizontalPadding, (topAppBarHeightToPx - actionsPlaceable.height) / 2) | ||
val contentX = (constraints.maxWidth - contentPlaceable.width) / 2 | ||
contentPlaceable.place(contentX, (topAppBarHeightToPx - contentPlaceable.height) / 2) | ||
} | ||
} | ||
} | ||
|
||
private const val NAVIGATION_ICON = "navigationIcon" | ||
private const val ACTIONS = "actions" | ||
private const val CONTENT = "content" | ||
|
||
@Preview | ||
@Composable | ||
private fun MnTopAppBarPreview() { | ||
MnTheme { | ||
val topAppBarColors = MnTopAppBarDefaults.topAppBarColors() | ||
MnTopAppBar( | ||
content = { | ||
Text("Title") | ||
}, | ||
navigationIcon = { | ||
Box( | ||
modifier = Modifier | ||
.size(40.dp) | ||
.noRippleClickable { }, | ||
contentAlignment = Alignment.Center | ||
) { | ||
MnMediumIcon( | ||
resourceId = R.drawable.ic_null, | ||
tint = topAppBarColors.navigationIconContentColor | ||
) | ||
} | ||
Comment on lines
+94
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이거 맞아 padding 디자인 스펙이라 다르면 불편함... 아니면 나 버튼 작업에 끼워 넣을까? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 시간되면 하나 만들어두먼 좋을거 같아! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 디자인팀에 스펙 물어봐서 추가할게요~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엉 고마워~! |
||
}, | ||
actions = { | ||
Box( | ||
modifier = Modifier | ||
.size(40.dp) | ||
.noRippleClickable { }, | ||
contentAlignment = Alignment.Center | ||
) { | ||
MnMediumIcon( | ||
resourceId = R.drawable.ic_null, | ||
tint = topAppBarColors.navigationIconContentColor | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun MnTopAppBarNotUseActionsPreview() { | ||
MnTheme { | ||
val topAppBarColors = MnTopAppBarDefaults.topAppBarColors() | ||
MnTopAppBar( | ||
content = { | ||
Text("Title") | ||
}, | ||
navigationIcon = { | ||
Box( | ||
modifier = Modifier | ||
.size(40.dp) | ||
.noRippleClickable { }, | ||
contentAlignment = Alignment.Center | ||
) { | ||
MnMediumIcon( | ||
resourceId = R.drawable.ic_null, | ||
tint = topAppBarColors.navigationIconContentColor | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun MnTopAppBarNotUseNaivigationPreview() { | ||
MnTheme { | ||
val topAppBarColors = MnTopAppBarDefaults.topAppBarColors() | ||
MnTopAppBar( | ||
content = { | ||
Text("Title") | ||
}, | ||
actions = { | ||
Box( | ||
modifier = Modifier | ||
.size(40.dp) | ||
.noRippleClickable { }, | ||
contentAlignment = Alignment.Center | ||
) { | ||
MnMediumIcon( | ||
resourceId = R.drawable.ic_null, | ||
tint = topAppBarColors.navigationIconContentColor | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HyomK tint 수정하면서 ImageVector 객체를 받는 MnIcon도 추가했어~!