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

[MOB-1873] 토글 이모지 버튼 추가 #66

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -0,0 +1,125 @@
package io.channel.bezier.compose.component.toggle_emoji_button

import androidx.compose.foundation.background
import androidx.compose.foundation.border
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.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.channel.bezier.BezierTheme
import io.channel.bezier.compose.component.emoji.BezierEmoji
import io.channel.bezier.compose.component.emoji.properties.BezierEmojiSize
import io.channel.bezier.compose.component.toggle_emoji_button.properties.BezierToggleEmojiButtonVariant

@Composable
fun BezierToggleEmojiButton(
selected: Boolean,
name: String,
variant: BezierToggleEmojiButtonVariant,
modifier: Modifier = Modifier,
enabled: Boolean = true,
onClick: () -> Unit,
Copy link
Contributor

Choose a reason for hiding this comment

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

onClick 매개변수를 위로 올리는 게 매개변수 순서상 좀 더 일관된다는 느낌을 받는데 어떻게 생각하시나요??

아래 문서에는, trailing lambda가 있는 경우 Composable로 오인할 수 있다.
라는 내용으로 근거삼고 있긴 하네용 Layout 쓰는 경험 생각해보면 그럴 수 있을것 같기도 해요
https://github.com/androidx/androidx/blob/androidx-main/compose/docs/compose-component-api-guidelines.md#parameters-order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아 이건 잘못 쓴게 완전 맞습니다ㅋㅋㅋㅋ

) {
val colorSchemes = variant.getColorSchemes(selected)

val shape = RoundedCornerShape(12.dp)
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()

Box(
modifier = modifier
.clip(shape)
.border(
width = variant.borderWidth,
color = colorSchemes.borderColor().color,
shape = shape,
)
.clickable(
enabled = enabled,
interactionSource = interactionSource,
indication = null,
onClick = onClick,
)
.background(
if (isPressed) {
colorSchemes.pressedBackgroundColor().color
} else {
colorSchemes.backgroundColor().color
},
)
.padding(12.dp),
contentAlignment = Alignment.Center,
) {
BezierEmoji(
name = name,
size = BezierEmojiSize.Size30,
)
}
}

@Preview(showBackground = true)
@Composable
private fun BezierToggleEmojiButtonPreview() {
BezierTheme {
Column(
modifier = Modifier.padding(10.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
var checked1 by remember { mutableStateOf(false) }
var checked2 by remember { mutableStateOf(true) }
var checked3 by remember { mutableStateOf(false) }
var checked4 by remember { mutableStateOf(true) }

Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
BezierToggleEmojiButton(
selected = checked1,
name = "ghost",
variant = BezierToggleEmojiButtonVariant.Primary,
onClick = { checked1 = !checked1 },
)

BezierToggleEmojiButton(
selected = checked2,
name = "innocent",
variant = BezierToggleEmojiButtonVariant.Primary,
onClick = { checked2 = !checked2 },
)
}

Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
BezierToggleEmojiButton(
selected = checked3,
name = "thinking_face",
variant = BezierToggleEmojiButtonVariant.Secondary,
onClick = { checked3 = !checked3 },
)

BezierToggleEmojiButton(
selected = checked4,
name = "+1",
variant = BezierToggleEmojiButtonVariant.Secondary,
onClick = { checked4 = !checked4 },
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.channel.bezier.compose.component.toggle_emoji_button.properties

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.channel.bezier.BezierTheme
import io.channel.bezier.compose.color_v2.BezierColor

enum class BezierToggleEmojiButtonVariant(
internal val borderWidth: Dp,
internal val selectedBackgroundColor: @Composable () -> BezierColor,
internal val selectedBorderColor: @Composable () -> BezierColor,
internal val selectedPressedBackgroundColor: @Composable () -> BezierColor,
internal val unselectedBackgroundColor: @Composable () -> BezierColor,
internal val unselectedBorderColor: @Composable () -> BezierColor,
internal val unselectedPressedBackgroundColor: @Composable () -> BezierColor,
) {
Primary(
borderWidth = 1.dp,
selectedBackgroundColor = { BezierTheme.colorSchemes.bgBlueLightest },
selectedBorderColor = { BezierTheme.colorSchemes.primaryBgNormal },
selectedPressedBackgroundColor = { BezierTheme.colorSchemes.bgBlueLighter },
unselectedBackgroundColor = { BezierTheme.colorSchemes.bgGreyLightest },
unselectedBorderColor = { BezierTheme.colorSchemes.bgBlackDark },
unselectedPressedBackgroundColor = { BezierTheme.colorSchemes.bgGreyLighter },
),
Secondary(
borderWidth = 0.dp,
selectedBackgroundColor = { BezierTheme.colorSchemes.primaryBgLighter },
selectedBorderColor = { BezierTheme.colorSchemes.bgWhiteWhiteAlphaTransparent },
selectedPressedBackgroundColor = { BezierTheme.colorSchemes.primaryBgLight },
unselectedBackgroundColor = { BezierTheme.colorSchemes.bgBlackLightest },
unselectedBorderColor = { BezierTheme.colorSchemes.bgWhiteWhiteAlphaTransparent },
unselectedPressedBackgroundColor = { BezierTheme.colorSchemes.bgBlackLighter },
);

internal fun getColorSchemes(selected: Boolean): BezierToggleEmojiButtonColorSchemes {
return if (selected) {
BezierToggleEmojiButtonColorSchemes(
backgroundColor = selectedBackgroundColor,
pressedBackgroundColor = selectedPressedBackgroundColor,
borderColor = selectedBorderColor,
)
} else {
BezierToggleEmojiButtonColorSchemes(
backgroundColor = unselectedBackgroundColor,
pressedBackgroundColor = unselectedPressedBackgroundColor,
borderColor = unselectedBorderColor,
)
}
}
}

internal class BezierToggleEmojiButtonColorSchemes(
val backgroundColor: @Composable () -> BezierColor,
val pressedBackgroundColor: @Composable () -> BezierColor,
val borderColor: @Composable () -> BezierColor,
)