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

[Feat] 검색 텍스트필드 추가 #251

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
Expand All @@ -24,9 +25,84 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import team.ppac.designsystem.FarmemeTheme
import team.ppac.designsystem.foundation.FarmemeIcon
import team.ppac.designsystem.foundation.FarmemeRadius
import team.ppac.designsystem.util.extension.noRippleClickable

@Composable
fun FarmemeSearchTextField(
modifier: Modifier = Modifier,
text: String,
onTextChanged: (String) -> Unit,
enabled: Boolean = true,
keyboardActions: KeyboardActions = KeyboardActions.Default,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
BasicTextField(
modifier = modifier,
value = text,
onValueChange = onTextChanged,
textStyle = FarmemeTheme.typography.body.large.medium.copy(
color = FarmemeTheme.textColor.primary
),
enabled = enabled,
singleLine = true,
keyboardActions = keyboardActions,
keyboardOptions = keyboardOptions,
cursorBrush = SolidColor(FarmemeTheme.backgroundColor.brand),
interactionSource = interactionSource,
decorationBox = { innerTextField ->
Box(
modifier = Modifier
.fillMaxWidth()
.clip(FarmemeRadius.Radius10.shape)
.background(
color = FarmemeTheme.backgroundColor.assistive,
)
.padding(vertical = 12.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier.size(16.dp))
FarmemeIcon.Search(
modifier = Modifier.size(20.dp),
tint = FarmemeTheme.iconColor.secondary
)
Spacer(modifier = Modifier.size(12.dp))
if (text.isBlank()) {
Text(
modifier = Modifier.fillMaxWidth(),
text = "찾고 싶은 밈 있어?",
style = FarmemeTheme.typography.body.large.medium.copy(
color = FarmemeTheme.textColor.tertiary
)
)
}
Box(modifier = Modifier.weight(1f)) {
innerTextField()
}
Spacer(modifier = Modifier.size(12.dp))
Box(modifier = Modifier) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

요거는 Box에 감싸진 이유가 있을까??

Copy link
Member Author

Choose a reason for hiding this comment

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

입력될 때 delete 버튼을 end 정렬 하려고 넣었숨!

FarmemeIcon.Delete(
modifier = Modifier
.size(20.dp)
.noRippleClickable(
onClick = { onTextChanged("") }
),
)
}
Spacer(modifier = Modifier.size(16.dp))
}
}
}
)
}

@Composable
fun FarmemeTextField(
Expand Down Expand Up @@ -151,6 +227,12 @@ private fun Preview() {
.background(Color.White)
.padding(horizontal = 16.dp)
) {
FarmemeSearchTextField(
modifier = Modifier.fillMaxWidth(),
text = value,
onTextChanged = { value = it },
)
Spacer(modifier = Modifier.size(16.dp))
FarmemeTextField(
modifier = Modifier.fillMaxWidth(),
text = value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@file:OptIn(ExperimentalLayoutApi::class)

package team.ppac.designsystem.component.toolbar

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -12,15 +9,51 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material.Text
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.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import team.ppac.designsystem.FarmemeTheme
import team.ppac.designsystem.component.textfield.FarmemeSearchTextField
import team.ppac.designsystem.foundation.FarmemeIcon
import team.ppac.designsystem.util.extension.noRippleClickable

@Composable
fun FarmemeSearchToolbar(
modifier: Modifier = Modifier,
text: String,
onTextChanged: (String) -> Unit,
navigationIcon: (@Composable () -> Unit)? = null,
) {
Row(
modifier = modifier
.padding(
horizontal = 20.dp,
vertical = 10.dp
)
.statusBarsPadding()
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Box(
modifier = Modifier.size(20.dp)
) {
navigationIcon?.invoke()
}
Spacer(modifier = Modifier.size(12.dp))
FarmemeSearchTextField(
modifier = Modifier.fillMaxWidth(),
text = text,
onTextChanged = onTextChanged
)
}
}

@Composable
fun FarmemeActionToolBar(onClickActionIcon: () -> Unit) {
FarmemeToolbar(
Expand Down Expand Up @@ -87,6 +120,19 @@ internal fun FarmemeToolbar(
}
}

@Preview(showBackground = true)
@Composable
private fun PreviewSearchToolbar() {
var text by remember { mutableStateOf("") }
FarmemeSearchToolbar(
text = text,
onTextChanged = { text = it },
navigationIcon = {
FarmemeIcon.Back()
}
)
}

@Preview(showBackground = true)
@Composable
private fun PreviewBackTitleToolbar() {
Expand Down
20 changes: 10 additions & 10 deletions core/designsystem/src/main/res/drawable/ic_delete_24.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M12,12m-10.5,0a10.5,10.5 0,1 1,21 0a10.5,10.5 0,1 1,-21 0"
android:fillColor="#1E2227"/>
android:pathData="M10,10m-8.75,0a8.75,8.75 0,1 1,17.5 0a8.75,8.75 0,1 1,-17.5 0"
android:fillColor="#BDCAD4"/>
<path
android:pathData="M15.75,8.25L8.25,15.75"
android:strokeWidth="2.4"
android:pathData="M13.125,6.875L6.875,13.125"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
<path
android:pathData="M15.75,15.75L8.25,8.25"
android:strokeWidth="2.4"
android:pathData="M13.125,13.125L6.875,6.875"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
Expand Down