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

[ADD/#16] Button / 컴포넌트 구현 #21

Merged
merged 22 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
66cdad6
[ADD/#5] TerningButton 파일 추가
leeeyubin Jul 7, 2024
738ac30
Merge branch 'develop' of https://github.com/teamterning/Terning-Andr…
leeeyubin Jul 7, 2024
4f0bff5
[ADD/#16] pull from develop
leeeyubin Jul 7, 2024
9b56e34
[ADD/#16] 프리뷰 라이브러리 core 모듈에 추가
leeeyubin Jul 7, 2024
cb7e768
[FEAT/#16] press 시, 색깔 구현
leeeyubin Jul 7, 2024
54d204a
[FEAT/#16] Button 컴포넌트로 구현
leeeyubin Jul 7, 2024
db426d6
[CHORE/#16] TerningTheme -> TerningPointTheme
leeeyubin Jul 7, 2024
b124445
[ADD/#16] Compose Preview 라이브러리 추가
leeeyubin Jul 7, 2024
d16b53e
[FEAT/#16] core 모듈 안 util 패키징
leeeyubin Jul 7, 2024
195a182
[FEAT/#16] TerningBasicButton 구현
leeeyubin Jul 7, 2024
c06c29d
[FEAT/#16] RoundButton 구현
leeeyubin Jul 7, 2024
c8f3c5b
[FEAT/#16] RectangleButton 구현
leeeyubin Jul 7, 2024
0b7ea2e
[DEL/#16] 불필요한 코드 삭제
leeeyubin Jul 7, 2024
7062258
[FEAT/#16] isEnabled일 때의 상태 구현
leeeyubin Jul 7, 2024
5a860ac
[CHORE/#16] 매개변수 위치 및 함수명 수정
leeeyubin Jul 7, 2024
9c5c0f0
[CHORE/#16] text 타입 Int로 수정
leeeyubin Jul 7, 2024
eaf301b
[CHORE/#16] 파라미터 위치 수정
leeeyubin Jul 8, 2024
6cb7ff2
[FIX/#16] solving conflict
leeeyubin Jul 9, 2024
3d46e51
[FIX/#16] solving conflict
leeeyubin Jul 9, 2024
1d328f2
[DEL/#16] 주석 지우기
leeeyubin Jul 9, 2024
e04ae18
Merge branch 'develop' of https://github.com/teamterning/Terning-Andr…
leeeyubin Jul 9, 2024
37378e6
[CHORE/#16] 코드 수정
leeeyubin Jul 9, 2024
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
3 changes: 3 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ dependencies {
implementation(libs.androidx.foundation.android)
implementation(libs.androidx.material3.android)

// Compose Preview
debugImplementation(libs.compose.ui.tooling)

// Test Dependency
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.terning.core.designsystem.component.button

import androidx.annotation.StringRes
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.terning.core.R
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme

@Composable
fun RectangleButton(
style: TextStyle,
paddingVertical: Dp,
@StringRes text: Int,
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
isEnabled: Boolean = true
) {
TerningBasicButton(
style = style,
paddingVertical = paddingVertical,
text = text,
onButtonClick = onButtonClick,
modifier = modifier,
isEnabled = isEnabled,
shape = RoundedCornerShape(0.dp),
)
}

@Preview(showBackground = true)
@Composable
fun RectangleButtonPreview() {
TerningPointTheme {
RectangleButton(
style = TerningTheme.typography.button0,
text = R.string.button_preview,
paddingVertical = 19.dp,
onButtonClick = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.terning.core.designsystem.component.button

import androidx.annotation.StringRes
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.terning.core.R
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme

@Composable
fun RoundButton(
style: TextStyle,
paddingVertical: Dp,
cornerRadius: Dp,
@StringRes text: Int,
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
isEnabled: Boolean = true,
) {
TerningBasicButton(
modifier = modifier,
style = style,
paddingVertical = paddingVertical,
shape = RoundedCornerShape(cornerRadius),
text = text,
onButtonClick = onButtonClick,
isEnabled = isEnabled,
)
}

@Preview(showBackground = true)
@Composable
fun RoundButtonPreview() {
TerningPointTheme {
RoundButton(
style = TerningTheme.typography.button0,
text = R.string.button_preview,
paddingVertical = 19.dp,
cornerRadius = 10.dp,
onButtonClick = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.terning.core.designsystem.component.button

import androidx.annotation.StringRes
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.terning.core.R
import com.terning.core.designsystem.theme.Black
import com.terning.core.designsystem.theme.Grey150
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningMain2
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.White
import com.terning.core.util.NoRippleTheme

@Composable
fun TerningBasicButton(
shape: Shape,
style: TextStyle,
paddingVertical: Dp,
@StringRes text: Int,
onButtonClick: () -> Unit,
modifier: Modifier = Modifier,
isEnabled: Boolean = true,
) {
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val backgroundColor = if (isPressed) TerningMain2 else TerningMain
Comment on lines +43 to +45
Copy link
Member

Choose a reason for hiding this comment

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

버튼 색상 변경 방법 신기하네요!!
InteractionSource를 알아보다가 말았는데 여기서 배우고 갑니다!!

Copy link
Member

Choose a reason for hiding this comment

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

오호!! 저도 새로운거 알아갑니다~~!!


CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
Copy link
Member

Choose a reason for hiding this comment

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

궁금한거 있습니다!!! 이렇게 선언만 해두면 바로 ripple이 사라지는건가요??????

Copy link
Member Author

Choose a reason for hiding this comment

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

네! 기존에 있던 LocalRippleTheme을 NoRippleTheme으로 바꿔준 겁니당

Button(
modifier = modifier.fillMaxWidth(),
interactionSource = interactionSource,
enabled = isEnabled,
colors = ButtonDefaults.buttonColors(
containerColor = backgroundColor,
contentColor = White,
disabledContainerColor = Grey150,
disabledContentColor = Black
),
shape = shape,
onClick = { onButtonClick() }
) {
Text(
text = stringResource(id = text),
style = style,
modifier = modifier.padding(vertical = paddingVertical)
)
}
}
}

@Preview(showBackground = true)
@Composable
fun TerningBasicButtonPreview() {
TerningPointTheme {
TerningBasicButton(
text = R.string.button_preview,
shape = ButtonDefaults.shape,
style = TerningTheme.typography.button0,
paddingVertical = 19.dp,
onButtonClick = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.runtime.Composable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.foundation.layout.Row
import androidx.compose.material3.Icon
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.terning.core.designsystem.topappbar
package com.terning.core.designsystem.component.topappbar

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.text.style.TextAlign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ val Black = Color(0xFF171717)

// Main Color
val TerningMain = Color(0xFF1EA65E)
val TerningMain2 = Color(0xFF179653)

// Calendar Color
val CalRed = Color(0xFFED4E54)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun ProvideTerningTypography(typography: TerningTypography, content: @Composable
}

@Composable
fun TerningTheme(
fun TerningPointTheme(
Copy link
Member

Choose a reason for hiding this comment

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

우왕 완전 센스쟁이!!

darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ class TerningTypography internal constructor(
}
}


@Composable
fun TerningTypography(): TerningTypography {
return TerningTypography(
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/terning/core/extension/Retrofit.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.terning.core.extension


fun String?.isJsonObject(): Boolean = this?.startsWith("{") == true && this.endsWith("}")

fun String?.isJsonArray(): Boolean = this?.startsWith("[") == true && this.endsWith("]")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.terning.core.util

import androidx.compose.foundation.interaction.Interaction
import androidx.compose.foundation.interaction.MutableInteractionSource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.emptyFlow

object NoRippleInteractionSource : MutableInteractionSource {

override val interactions: Flow<Interaction> = emptyFlow()

override suspend fun emit(interaction: Interaction) {}

override fun tryEmit(interaction: Interaction) = true
}
19 changes: 19 additions & 0 deletions core/src/main/java/com/terning/core/util/NoRippleTheme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.terning.core.util

import androidx.compose.material.ripple.RippleAlpha
import androidx.compose.material.ripple.RippleTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

object NoRippleTheme : RippleTheme {
@Composable
override fun defaultColor() = Color.Unspecified

@Composable
override fun rippleAlpha(): RippleAlpha = RippleAlpha(
draggedAlpha = 0.0f,
focusedAlpha = 0.0f,
hoveredAlpha = 0.0f,
pressedAlpha = 0.0f
)
Comment on lines +13 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

리플테마 적용 감사해용 🥹

}
8 changes: 6 additions & 2 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- ContentDescription-->
<!--ContentDescription-->
<string name="ic_back">뒤로가기 버튼</string>
<string name="ic_logo">탑 바 로고</string>
<string name="ic_20_right">오른쪽 버튼</string>

<!-- MyPage-->
<!-- MyPage-->
<string name="my_page_top_app_bar">프로필 수정</string>

<!-- button-->
<string name="button_preview">button</string>

</resources>
4 changes: 3 additions & 1 deletion feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ dependencies {
// Material Design
implementation(libs.material)
implementation(libs.androidx.material3.android)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.ui.graphics)

// TestDependencies
Expand All @@ -91,6 +90,9 @@ dependencies {
implementation(libs.ossLicense)
implementation(libs.lottie)

// Compose Preview
debugImplementation(libs.compose.ui.tooling)

// KakaoDependencies
implementation(libs.kakao.user)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.TerningPointTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -14,7 +14,7 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()
setContent {
val navigator: MainNavigator = rememberMainNavigator()
TerningTheme {
TerningPointTheme {
MainScreen(navigator)
}
}
Expand Down
Loading
Loading