Skip to content

Commit

Permalink
Merge branch 'feature/#15-common-textfield-ui' of https://github.com/…
Browse files Browse the repository at this point in the history
  • Loading branch information
youjin09222 committed Jan 8, 2025
2 parents e1514a2 + 9c885e5 commit 7eecf4c
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 151 deletions.
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
implementation(libs.kotlin)
implementation(libs.core.ktx)
implementation(libs.material)
implementation(libs.activity.compose)

// Test
testImplementation(libs.junit)
Expand All @@ -58,4 +59,5 @@ dependencies {
// Third Party
implementation(libs.coil.compose)
implementation(libs.lottie.compose)
implementation(libs.bundles.landscapist.glide)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun NoostakBottomButton(
Button(
modifier = modifier
.fillMaxWidth()
.padding(dimensionResource(id = R.dimen.bottom_padding))
.padding(bottom = dimensionResource(id = R.dimen.bottom_padding))
.run {
if (isEnabled) {
noRippleClickable(onClick = onButtonClick)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopt.presentation.groupCreate.component
package com.sopt.core.designsystem.component.image

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
Expand All @@ -16,19 +16,19 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.glide.GlideImage
import com.sopt.core.R
import com.sopt.core.designsystem.theme.NoostakAndroidTheme
import com.sopt.core.extension.noRippleClickable
import com.sopt.presentation.R

@Composable
fun GroupProfileImagePicker(
fun ProfileImagePicker(
selectedImageUri: String?,
onCameraBtnClick: () -> Unit,
modifier: Modifier = Modifier
) {
Box(modifier = modifier) {
GlideImage(
imageModel = { selectedImageUri ?: R.drawable.ic_group_create_profile },
imageModel = { selectedImageUri ?: R.drawable.ic_profile },
imageOptions = ImageOptions(
contentScale = ContentScale.Crop,
alignment = Alignment.Center
Expand All @@ -37,11 +37,11 @@ fun GroupProfileImagePicker(
.size(112.dp)
.aspectRatio(1f)
.clip(CircleShape),
previewPlaceholder = painterResource(id = R.drawable.ic_group_create_profile)
previewPlaceholder = painterResource(id = R.drawable.ic_profile)
)
Image(
painter = painterResource(id = R.drawable.ic_group_create_camera),
contentDescription = stringResource(R.string.image_group_profile_image_picker_description),
painter = painterResource(id = R.drawable.ic_profile_camera),
contentDescription = stringResource(R.string.image_profile_image_picker_description),
modifier = Modifier
.size(35.dp)
.align(Alignment.BottomEnd)
Expand All @@ -54,8 +54,8 @@ fun GroupProfileImagePicker(

@Preview(showBackground = true)
@Composable
fun GroupProfileImagePickerPreview() {
fun ProfileImagePickerPreview() {
NoostakAndroidTheme {
GroupProfileImagePicker(selectedImageUri = null, onCameraBtnClick = {})
ProfileImagePicker(selectedImageUri = null, onCameraBtnClick = {})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package com.sopt.core.designsystem.component.textfield

import androidx.compose.foundation.border
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.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
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.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.sopt.core.R
import com.sopt.core.designsystem.theme.NoostakAndroidTheme
import com.sopt.core.designsystem.theme.NoostakTheme
import com.sopt.core.type.TextFieldType

@Composable
fun NoostakTextField(
textFieldType: TextFieldType,
value: String = "",
onValueChange: (String) -> Unit = { _ -> },
placeholderColor: Color = NoostakTheme.colors.gray600,
textStyle: TextStyle = NoostakTheme.typography.b5Regular,
shape: Shape = RoundedCornerShape(6.dp),
cursorColor: Color = NoostakTheme.colors.gray600,
focusedBorderColor: Color = NoostakTheme.colors.gray900,
unfocusedWithInputBorderColor: Color = NoostakTheme.colors.gray700,
unfocusedBorderColor: Color = NoostakTheme.colors.gray500,
maxLength: Int = 30,
modifier: Modifier = Modifier,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default
) {
var isFocused by remember { mutableStateOf(false) }

Column {
Box(
modifier = Modifier
.fillMaxWidth()
.border(
width = 1.dp,
color = when {
isFocused -> focusedBorderColor // 포커스된 경우
value.isNotEmpty() -> unfocusedWithInputBorderColor // 텍스트가 입력되고 포커스 안된 경우
else -> unfocusedBorderColor // 포커스되지 않은 경우
},
shape = shape
)
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
TextField(
value = value,
textStyle = textStyle,
onValueChange = { newValue ->
if (newValue.replace(" ", "").length <= maxLength) {
onValueChange(
newValue
)
}
},
placeholder = {
Text(
text = stringResource(id = textFieldType.placeholder),
color = placeholderColor,
style = textStyle
)
},
modifier = Modifier
.weight(1f)
.onFocusChanged { focusState ->
isFocused = focusState.isFocused
},
colors = TextFieldDefaults.colors(
cursorColor = cursorColor,
disabledContainerColor = Color.Transparent,
focusedContainerColor = Color.Transparent,
errorContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent
),
singleLine = true,
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions
)

if (textFieldType != TextFieldType.CALENDAR && value.isNotEmpty()) {
IconButton(
modifier = Modifier
.padding(end = 12.dp)
.size(24.dp),
onClick = { onValueChange("") }
) {
Icon(
painter = painterResource(id = R.drawable.ic_text_field_delete),
contentDescription = stringResource(R.string.icon_noostak_text_field_descrition),
tint = Color.Unspecified
)
}
}
}
}

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = if (textFieldType == TextFieldType.SIGNUP) stringResource(R.string.text_noostak_text_field_sign_up_example) else "",
color = NoostakTheme.colors.gray800,
style = NoostakTheme.typography.b5Regular,
modifier = modifier.padding(top = 6.dp),
maxLines = 1
)

Text(
text = stringResource(
R.string.text_noostak_text_field_count,
value.length,
maxLength
),
color = NoostakTheme.colors.gray800,
style = NoostakTheme.typography.b5Regular,
modifier = modifier.padding(top = 6.dp),
maxLines = 1
)
}
}
}

@Preview(showBackground = true)
@Composable
fun NoostakTextFieldPreview() {
NoostakAndroidTheme {
Column {
NoostakTextField(textFieldType = TextFieldType.GROUP, value = "누스탁")
}
}
}
17 changes: 17 additions & 0 deletions core/src/main/java/com/sopt/core/extension/ContextExt.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.sopt.core.extension

import android.content.Context
import android.os.Build
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes

fun Context.toast(@StringRes message: Int) {
Expand All @@ -15,3 +19,16 @@ fun Context.stringToast(message: String) {
fun Context.longToast(@StringRes message: Int) {
Toast.makeText(this, getString(message), Toast.LENGTH_SHORT).show()
}

fun Context.launchImagePicker(
galleryLauncher: ActivityResultLauncher<String>,
photoPickerLauncher: ActivityResultLauncher<PickVisualMediaRequest>
) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
// API 33 미만: 갤러리 실행
galleryLauncher.launch("image/*")
} else {
// API 33 이상: 포토피커 실행 (이미지만 선택)
photoPickerLauncher.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))
}
}
18 changes: 18 additions & 0 deletions core/src/main/java/com/sopt/core/type/TextFieldType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sopt.core.type

import androidx.annotation.StringRes
import com.sopt.core.R

enum class TextFieldType(
@StringRes val placeholder: Int
) {
SIGNUP(
placeholder = R.string.tf_sign_up_placeholder
),
GROUP(
placeholder = R.string.tf_group_create_placeholder
),
CALENDAR(
placeholder = R.string.tf_calendar_info_placeholder
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopt.presentation.groupCreate.permission
package com.sopt.core.util.permission

import android.net.Uri
import androidx.activity.compose.ManagedActivityResultLauncher
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@
<!-- Noostak Close App Bar -->
<string name="icon_noostak_close_appbar_description">Icon Delete On AppBar</string>

<!-- test -->
<string name="test">test</string>

<!-- Sign Up -->
<string name="tf_sign_up_placeholder">이름을 입력해주세요</string>

<!-- Group Create -->
<string name="tf_group_create_placeholder">그룹명을 입력해주세요</string>

<!-- Calendar Info -->
<string name="tf_calendar_info_placeholder">이름을 입력해주세요</string>

<!-- Noostak Text Field -->
<string name="text_noostak_text_field_sign_up_example">예) 홍길동</string>
<string name="text_noostak_text_field_count">%1$s/%2$s</string>
<string name="icon_noostak_text_field_descrition">Delete Profile Name</string>

<!-- Profile Image Picker -->
<string name="image_profile_image_picker_description">Add Profile Image By Camera Button</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ fun GroupFloatingActionButtonItem(
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.width(122.dp)
.width(134.dp)
.noRippleClickable { onItemClick() }
) {
Image(
painter = painter,
contentDescription = null,
modifier = Modifier
.padding(end = 8.dp)
.padding(start = 6.dp, end = 8.dp, top = 6.dp, bottom = 6.dp)
.size(24.dp)
.aspectRatio(1f)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ fun GroupFloatingActionDialog(
shape = RoundedCornerShape(12.dp)
)
) {
Column(modifier = Modifier.padding(horizontal = 17.dp, vertical = 18.dp)) {
Column(modifier = Modifier.padding(horizontal = 11.dp, vertical = 13.dp)) {
GroupFloatingActionButtonItem(
painter = painterResource(id = R.drawable.ic_launcher_background),
text = stringResource(R.string.text_group_create_title)
) {
onCreateGroupClick()
}
Spacer(modifier = Modifier.height(12.dp))
GroupFloatingActionButtonItem(
painter = painterResource(id = R.drawable.ic_launcher_background),
text = stringResource(R.string.text_group_fab_enter)
Expand Down
Loading

0 comments on commit 7eecf4c

Please sign in to comment.