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

[개선] 공통 모듈에서 사용할 수 있는 UI 파일 분리 #326

Closed
wants to merge 6 commits into from
Closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.droidknights.app.core.designsystem.component

import androidx.annotation.DrawableRes
import androidx.compose.material3.Icon
import androidx.compose.material3.IconToggleButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource

@Composable
fun IconToggleButton(
modifier: Modifier = Modifier,
isChecked: Boolean,
onCheckedChange: (Boolean) -> Unit,
@DrawableRes checkedImageRes: Int,
@DrawableRes uncheckedImageRes: Int
) {
IconToggleButton(
modifier = modifier,
checked = isChecked,
onCheckedChange = onCheckedChange,
) {
Icon(
painter = if (isChecked) {
painterResource(id = checkedImageRes)
} else {
painterResource(id = uncheckedImageRes)
},
contentDescription = null
)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

마지막 줄 엔터가 저희 코드 컨벤션입니다.

  • 해당 컴포넌트에 대한 Preview 추가 부탁드려요.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.droidknights.app.core.designsystem.component

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

@Composable
fun RoundedImage(
imageRes: Int,
onClick: () -> Unit = {},
size: Dp? = null,
roundSize: Dp = 16.dp,
border: BorderStroke? = null,
) {
RoundedImage(
imageRes = imageRes,
onClick = onClick,
width = size,
height = size,
roundSize = roundSize,
border = border,
)
}

@Composable
fun RoundedImage(
imageRes: Int,
onClick: () -> Unit = {},
width: Dp? = null,
height: Dp? = null,
roundSize: Dp = 16.dp,
border: BorderStroke? = null,
) {
val modifier = if (width != null && height != null) {
Modifier.size(width, height)
} else {
Modifier.aspectRatio(1f)
}

Surface(
onClick = onClick,
shape = RoundedCornerShape(roundSize),
border = border,
modifier = modifier
) {
Image(
painter = painterResource(id = imageRes),
contentDescription = null
)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

width가 null이고 rounded 사이즈가 있는 상태인데 함수가 2개일 필요가 있나요? 나머지 내용은 모두 동일한 상태라서
아래꺼 하나로 충분해보입니다.

그리고 이 버튼은 ImageButton을 뜻하는것 같은데 ... 용도와 타이틀도 안맞는것 같네요. 아마 이런 형태가 main 쪽에만 있었는데 공통화 하시면서 그대로 이동한것 같은데. 함수명으로는 click 가능한 이미지 인지이해가 어렵네요.
그리고 사이즈를 바꾸면 Image가 센터로 정렬되지 않습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconToggleButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -38,15 +36,14 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.droidknights.app.core.designsystem.component.IconToggleButton
import com.droidknights.app.core.designsystem.component.KnightsTopAppBar
import com.droidknights.app.core.designsystem.component.NetworkImage
import com.droidknights.app.core.designsystem.component.TextChip
import com.droidknights.app.core.designsystem.component.TopAppBarNavigationType
import com.droidknights.app.core.designsystem.theme.DarkGray
import com.droidknights.app.core.designsystem.theme.Gray
import com.droidknights.app.core.designsystem.theme.KnightsTheme
import com.droidknights.app.core.designsystem.theme.LightGray
import com.droidknights.app.core.designsystem.theme.Purple01
import com.droidknights.app.core.model.Room
import com.droidknights.app.core.model.Session
import com.droidknights.app.core.model.Speaker
Expand Down Expand Up @@ -124,9 +121,11 @@ private fun SessionDetailTopAppBar(
navigationIconContentDescription = null,
navigationType = TopAppBarNavigationType.Back,
actionButtons = {
BookmarkToggleButton(
bookmarked = bookmarked,
onClickBookmark = onClickBookmark
IconToggleButton(
isChecked = bookmarked,
onCheckedChange = onClickBookmark,
checkedImageRes = R.drawable.ic_session_bookmark_filled,
uncheckedImageRes = R.drawable.ic_session_bookmark,
)
},
onNavigationClick = onBackClick,
Expand Down Expand Up @@ -271,28 +270,6 @@ private fun SessionOverview(content: String) {
}
}

@Composable
private fun BookmarkToggleButton(
bookmarked: Boolean,
onClickBookmark: (Boolean) -> Unit,
) {
IconToggleButton(
checked = bookmarked,
onCheckedChange = onClickBookmark
) {
Icon(
painter =
if (bookmarked) {
painterResource(id = R.drawable.ic_session_bookmark_filled)
} else {
painterResource(id = R.drawable.ic_session_bookmark)
},
contentDescription = null,
tint = if (bookmarked) Purple01 else Gray
)
}
}

private val SampleSessionHasContent = Session(
id = "2",
title = "세션 제목은 세션 제목 - 개요 있음",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@ package com.droidknights.app.feature.setting

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Surface
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.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.droidknights.app.core.designsystem.component.KnightsCard
import com.droidknights.app.core.designsystem.component.RoundedImage
import com.droidknights.app.core.designsystem.theme.KnightsTheme
import com.droidknights.app.core.designsystem.theme.LocalDarkTheme
import com.droidknights.app.feature.setting.component.OpenSourceCard
Expand Down Expand Up @@ -109,16 +105,10 @@ private fun ThemeCard(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Surface(
shape = RoundedCornerShape(16.dp),
onClick = onClick,
) {
Image(
painter = painterResource(id = imageRes),
contentDescription = null,
modifier = Modifier.aspectRatio(1f)
)
}
RoundedImage(
imageRes = imageRes,
onClick = onClick
)

Text(
text = stringResource(id = titleRes),
Expand Down
Loading