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

[CAT-140] MnTopAppBar 구현 / Icon LocalContentColor로 수정 #42

Merged
merged 6 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private val MnTextColorScheme = MnColorScheme(
)

private val MnBackgroundColorScheme = MnColorScheme(
primary = MnColor.Gray500,
primary = MnColor.Gray50,
secondary = MnColor.Gray100,
tertiary = MnColor.Gray400,
inverse = MnColor.Gray900,
Expand Down
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

여기하다가 느낀건데 #38 (comment) 이 코멘트 번복해도 될까 👀

막상 컴포넌트 만들면서 Color들 좀 사용 편하게 해주려고 하니까 LocalContentColor를 provide 해주고 그것을 컴포넌트에서 쓰는게 편한거 같아서~!

Copy link
Member

Choose a reason for hiding this comment

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

provide 하는 방식으로 구현하면 LocalContentColor 이렇게 바꾸는게 맞을 것 같네요~~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그럼 내가 슬쩍 반영해둬도 될까?🧎‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

오키오키

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IconButton 이라는 선택지도 있는데 M3 Iconbutton은 최소 크기 및 start padding을 내부에서 주는게 있어서 사용이 생각보다 까다로워서 우선 안썼고 직접 만들까 고민중이야

Copy link
Member

@HyomK HyomK Aug 2, 2024

Choose a reason for hiding this comment

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

아 이거 맞아 padding 디자인 스펙이라 다르면 불편함... 아니면 나 버튼 작업에 끼워 넣을까?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

시간되면 하나 만들어두먼 좋을거 같아!

Copy link
Member

Choose a reason for hiding this comment

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

디자인팀에 스펙 물어봐서 추가할게요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
)
}
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.pomonyang.mohanyang.presentation.designsystem.topappbar

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.pomonyang.mohanyang.presentation.designsystem.token.MnColor
import com.pomonyang.mohanyang.presentation.theme.MnTheme

object MnTopAppBarDefaults {
val height = 56.dp
val iconHorizontalPadding = 8.dp

@Composable
fun topAppBarColors(
containerColor: Color = MnColor.Gray50,
navigationIconContentColor: Color = MnTheme.iconColorScheme.primary,
titleContentColor: Color = MnTheme.textColorScheme.primary,
actionIconContentColor: Color = MnTheme.iconColorScheme.primary
) = MnAppBarColors(
containerColor = containerColor,
navigationIconContentColor = navigationIconContentColor,
titleContentColor = titleContentColor,
actionIconContentColor = actionIconContentColor
)
}

@Immutable
data class MnAppBarColors(
val containerColor: Color,
val navigationIconContentColor: Color,
val titleContentColor: Color,
val actionIconContentColor: Color
)