Skip to content

Commit

Permalink
refacotr : PR 피드백 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Nov 16, 2023
1 parent f2dc37d commit 758034e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
androidTestImplementation(libs.androidx.test.espresso)
}

tasks.getByPath(":app:preBuild").dependsOn("installGitHook")
/*tasks.getByPath(":app:preBuild").dependsOn("installGitHook")
tasks.register<Copy>("installGitHook") {
dependsOn("deletePreviousGitHook")
Expand All @@ -58,4 +58,4 @@ tasks.register<Delete>("deletePreviousGitHook") {
if (file(prePush).exists()) {
delete(prePush)
}
}
}*/
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import androidx.hilt.navigation.compose.hiltViewModel
import com.wap.designsystem.WappTheme
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -27,12 +26,9 @@ class NoticeFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

composeView.setContent {
WappTheme {
NoticeScreen(
viewModel = hiltViewModel(),
)
NoticeScreen()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.wap.wapp.feature.notice

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -36,6 +35,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.layout
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
Expand All @@ -49,17 +49,16 @@ import kotlinx.coroutines.launch
internal fun NoticeScreen(
viewModel: NoticeViewModel = hiltViewModel(),
) {
var expandHeight: Dp by remember { mutableStateOf(0.dp) }
var defaultHeight: Dp by remember { mutableStateOf(0.dp) }

var expandableHeight: Dp by remember { mutableStateOf(0.dp) }
val coroutineScope = rememberCoroutineScope()
val scaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = SheetState(
skipPartiallyExpanded = false,
initialValue = SheetValue.PartiallyExpanded,
skipHiddenState = true,
),
)
val coroutineScope = rememberCoroutineScope()

Column(
modifier = Modifier
Expand All @@ -70,31 +69,16 @@ internal fun NoticeScreen(
scaffoldState = scaffoldState,
sheetContainerColor = WappTheme.colors.black25,
sheetPeekHeight = defaultHeight,
sheetContent = {
Column(
horizontalAlignment = Alignment.Start,
modifier = Modifier.height(expandHeight),
) {
Text(
text = "10.25 수요일",
style = WappTheme.typography.titleBold,
color = WappTheme.colors.white,
modifier = Modifier.padding(start = 15.dp, bottom = 15.dp),
)

NoticeList(getDummyNotices())
}
},
sheetContent = { BottomSheetContent(expandableHeight) },
) {
Column(
modifier = Modifier
.fillMaxWidth()
.background(WappTheme.colors.black25)
.layout { measurable, constriants ->
val placeable = measurable.measure(constriants)

defaultHeight = (constriants.maxHeight - placeable.height).toDp()
.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)

defaultHeight = (constraints.maxHeight - placeable.height).toDp()
layout(placeable.width, placeable.height) {
placeable.placeRelative(0, 0)
}
Expand All @@ -103,25 +87,24 @@ internal fun NoticeScreen(
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(vertical = 10.dp)
.fillMaxWidth()
.layout { measurable, constriants ->
val placeable = measurable.measure(constriants)

expandHeight = (constriants.maxHeight - placeable.height).toDp() - 50.dp
.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
expandableHeight =
constraints.maxHeight.toDp() - (placeable.height.toDp() * 2)
layout(placeable.width, placeable.height) {
placeable.placeRelative(0, 0)
}
},
}
.padding(vertical = 10.dp)
.fillMaxWidth(),
) {
Image(
painter = painterResource(id = R.drawable.ic_threelines),
contentDescription = "공지사항 목록만을 보여줍니다.",
contentDescription =
stringResource(R.string.calendarToggleImageContextDescription),
modifier = Modifier
.clickable {
scaffoldState.bottomSheetState.let { sheetState ->
handleSheetState(coroutineScope, sheetState)
}
handleSheetState(coroutineScope, scaffoldState.bottomSheetState)
}
.padding(start = 16.dp),
)
Expand All @@ -135,7 +118,7 @@ internal fun NoticeScreen(

Image(
painter = painterResource(id = R.drawable.ic_calendar),
contentDescription = "공지사항을 띄워주는 달력입니다.",
contentDescription = stringResource(id = R.string.calendarContextDescription),
contentScale = ContentScale.FillWidth,
modifier = Modifier
.padding(top = 10.dp)
Expand All @@ -146,37 +129,40 @@ internal fun NoticeScreen(
}
}

@OptIn(ExperimentalMaterial3Api::class)
private fun handleSheetState(coroutineScope: CoroutineScope, sheetState: SheetState) {
coroutineScope.launch {
Log.d("test", sheetState.currentValue.toString())

when (sheetState.currentValue) {
SheetValue.Expanded -> sheetState.partialExpand()
SheetValue.PartiallyExpanded -> sheetState.expand()
SheetValue.Hidden -> sheetState.expand()
}
@Composable
private fun BottomSheetContent(expandableHeight: Dp) {
Column(
horizontalAlignment = Alignment.Start,
modifier = Modifier.height(expandableHeight),
) {
Text(
text = "10.25 수요일",
style = WappTheme.typography.titleBold,
color = WappTheme.colors.white,
modifier = Modifier.padding(start = 15.dp, bottom = 15.dp),
)
NoticeList(getDummyNotices())
}
}

@Composable
fun NoticeList(notices: List<Notice>) {
private fun NoticeList(notices: List<Notice>) {
LazyColumn(
contentPadding = PaddingValues(horizontal = 15.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier.fillMaxWidth(),
) {
itemsIndexed(
items = notices,
key = { index, notice -> notice.title },
) { index, notice ->
key = { _, notice -> notice.title },
) { _, notice ->
NoticeItem(notice = notice)
}
}
}

@Composable
fun NoticeItem(notice: Notice) {
private fun NoticeItem(notice: Notice) {
Column {
Row(
modifier = Modifier
Expand Down Expand Up @@ -222,6 +208,20 @@ fun NoticeItem(notice: Notice) {
}
}

@OptIn(ExperimentalMaterial3Api::class)
private fun handleSheetState(
coroutineScope: CoroutineScope,
sheetState: SheetState,
) {
coroutineScope.launch {
when (sheetState.currentValue) {
SheetValue.Expanded -> sheetState.partialExpand()
SheetValue.PartiallyExpanded -> sheetState.expand()
SheetValue.Hidden -> sheetState.expand()
}
}
}

// forTest
private fun getDummyNotices(): List<Notice> = listOf(
Notice(
Expand Down
6 changes: 3 additions & 3 deletions feature/notice/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
<string name="calendarToggleImageContextDescription">공지사항 목록만을 보여주거나, 캘린더를 다시 보여줍니다.</string>
<string name="calendarContextDescription">공지사항을 보여주는 달력입니다.</string>
</resources>

0 comments on commit 758034e

Please sign in to comment.