-
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
List 컴포넌트 구현 #18
Open
kangyuri1114
wants to merge
3
commits into
main
Choose a base branch
from
feat/rein/list
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
List 컴포넌트 구현 #18
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
180 changes: 180 additions & 0 deletions
180
compose/src/main/kotlin/com/yourssu/handy/compose/list/ListItem.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 |
---|---|---|
@@ -0,0 +1,180 @@ | ||
package com.yourssu.handy.compose.list | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.interaction.collectIsPressedAsState | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.yourssu.handy.compose.HandyTheme | ||
import com.yourssu.handy.compose.Icon | ||
import com.yourssu.handy.compose.Text | ||
import com.yourssu.handy.compose.icons.HandyIcons | ||
import com.yourssu.handy.compose.icons.line.ArrowsChevronRight | ||
import com.yourssu.handy.compose.icons.line.User | ||
import org.w3c.dom.Text | ||
|
||
@Composable | ||
fun ListItem( | ||
headline: String, | ||
onClick: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
enabled: Boolean = true, | ||
leadingIcon: ImageVector? = null, | ||
trailingIcon: ImageVector? = null, | ||
containerColor: Color = HandyTheme.colors.listEnabled, | ||
pressedContainerColor: Color = HandyTheme.colors.listPressed, | ||
headlineColor: Color = HandyTheme.colors.textBasicPrimary, | ||
leadingIconColor: Color = HandyTheme.colors.iconBasicPrimary, | ||
tailingIconColor: Color = HandyTheme.colors.iconBasicTertiary, | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() } | ||
) { | ||
val pressed by interactionSource.collectIsPressedAsState() | ||
|
||
val backgroundColor = determineContainerColor(enabled, pressed, containerColor, pressedContainerColor) | ||
|
||
Row( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.height(64.dp) | ||
.clickable( | ||
onClick = onClick, | ||
enabled = enabled, | ||
interactionSource = interactionSource, | ||
indication = null | ||
) | ||
.background(backgroundColor), | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
) { | ||
Row( | ||
modifier = modifier.padding(horizontal = 16.dp, vertical = 20.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
leadingIcon?.let { | ||
Icon( | ||
imageVector = leadingIcon, | ||
contentDescription = "leadingIcon", | ||
tint = determineContentColor(enabled, leadingIconColor), | ||
) | ||
} | ||
|
||
Text( | ||
text = headline, | ||
color = determineContentColor(enabled, headlineColor), | ||
modifier = modifier.padding(horizontal = 16.dp), | ||
overflow = TextOverflow.Ellipsis, | ||
) | ||
} | ||
|
||
trailingIcon?.let { | ||
Icon( | ||
imageVector = trailingIcon, | ||
contentDescription = "trailingIcon", | ||
tint = determineContentColor(enabled, tailingIconColor), | ||
modifier = modifier.padding(end = 16.dp, bottom = 20.dp, top = 20.dp) | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun determineContainerColor( | ||
enabled: Boolean, | ||
pressed: Boolean, | ||
containerColor: Color, | ||
pressedContainerColor: Color | ||
): Color { | ||
return when { | ||
!enabled -> HandyTheme.colors.listDisabled | ||
pressed -> pressedContainerColor | ||
else -> containerColor | ||
} | ||
} | ||
|
||
@Composable | ||
fun determineContentColor( | ||
enabled: Boolean, | ||
contentColor: Color | ||
): Color { | ||
return when { | ||
!enabled -> HandyTheme.colors.textBasicDisabled | ||
else -> contentColor | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview | ||
fun ListItemPreview() { | ||
HandyTheme { | ||
Column( | ||
modifier = Modifier | ||
.background(Color.Red) | ||
.fillMaxWidth(), | ||
verticalArrangement = Arrangement.spacedBy(10.dp) | ||
) { | ||
ListItem( | ||
headline = "Title", | ||
onClick = {}, | ||
leadingIcon = HandyIcons.Line.User, | ||
trailingIcon = HandyIcons.Line.ArrowsChevronRight, | ||
) | ||
|
||
ListItem( | ||
headline = "Title", | ||
onClick = {}, | ||
leadingIcon = HandyIcons.Line.User, | ||
trailingIcon = HandyIcons.Line.ArrowsChevronRight, | ||
enabled = false | ||
) | ||
|
||
ListItem( | ||
headline = "Titleeeeeeeeeeeeeeeeeeeeeeee", | ||
onClick = {}, | ||
leadingIcon = HandyIcons.Line.User, | ||
trailingIcon = HandyIcons.Line.ArrowsChevronRight, | ||
containerColor = HandyTheme.colors.textBrandPrimary, | ||
tailingIconColor = HandyTheme.colors.textStatusNegative, | ||
headlineColor = HandyTheme.colors.textBasicWhite, | ||
leadingIconColor = HandyTheme.colors.iconBasicTertiary | ||
) | ||
|
||
ListItem( | ||
headline = "Titleeeeeeeeeeeeeeeeeeeeeeee", | ||
onClick = {}, | ||
leadingIcon = HandyIcons.Line.User, | ||
trailingIcon = HandyIcons.Line.ArrowsChevronRight, | ||
containerColor = HandyTheme.colors.textBrandPrimary, | ||
tailingIconColor = HandyTheme.colors.textStatusNegative, | ||
headlineColor = HandyTheme.colors.textBasicWhite, | ||
leadingIconColor = HandyTheme.colors.iconBasicTertiary, | ||
pressedContainerColor = HandyTheme.colors.iconBasicTertiary | ||
) | ||
|
||
ListItem( | ||
headline = "Titleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", | ||
onClick = {}, | ||
leadingIcon = HandyIcons.Line.User, | ||
trailingIcon = HandyIcons.Line.ArrowsChevronRight, | ||
containerColor = HandyTheme.colors.textBrandPrimary, | ||
tailingIconColor = HandyTheme.colors.textStatusNegative, | ||
headlineColor = HandyTheme.colors.textBasicWhite, | ||
leadingIconColor = HandyTheme.colors.iconBasicTertiary, | ||
pressedContainerColor = HandyTheme.colors.iconBasicTertiary | ||
) | ||
} | ||
} | ||
} |
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.
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.
leadingIcon과 trailingIcon이 없을때에 디자인이 반영되지 않은 것 같습니당!