Skip to content

Commit

Permalink
[REFACTOR]#223 : 쪽지 수신인 페이지, 기존 레이아웃 쌓는 구조에서 subComposeLayout을 활용해 버튼…
Browse files Browse the repository at this point in the history
… 최하단에 배치하도록 수정
  • Loading branch information
jeongjaino committed Jan 16, 2025
1 parent 4120513 commit 11ff383
Showing 1 changed file with 87 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -25,12 +24,14 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.SubcomposeLayout
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.SoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemKey
import coil.compose.AsyncImage
Expand All @@ -45,8 +46,10 @@ import com.bff.wespot.designsystem.theme.WeSpotThemeManager
import com.bff.wespot.message.R
import com.bff.wespot.message.component.SendExitDialog
import com.bff.wespot.message.state.send.SendAction
import com.bff.wespot.message.state.send.SendUiState
import com.bff.wespot.message.viewmodel.SendViewModel
import com.bff.wespot.model.common.KakaoContent
import com.bff.wespot.model.user.response.User
import com.bff.wespot.navigation.Navigator
import com.bff.wespot.ui.component.ListBottomGradient
import com.bff.wespot.ui.component.NetworkDialog
Expand Down Expand Up @@ -175,9 +178,76 @@ fun ReceiverSelectionScreen(
}
}

LazyColumn(
modifier = Modifier.padding(top = 16.dp, bottom = 74.dp),
) {
ReceiverSelectionLayout(
navigator = navigator,
isEditing = navArgs.isEditing,
keyboard = keyboard,
pagingData = pagingData,
state = state,
action = action,
)
}
}

if (dialogState) {
SendExitDialog(
isReservedMessage = state.isReservedMessage,
okButtonClick = {
dialogState = false
navigator.popUpToMessageScreen()
},
cancelButtonClick = { dialogState = false },
)
}

NetworkDialog(context = context, networkState = networkState)

LaunchedEffect(focusRequester) {
focusRequester.requestFocus()
delay(10)
keyboard?.show()
}

LaunchedEffect(Unit) {
action(SendAction.OnReceiverScreenEntered)
}
}

@Composable
private fun ReceiverSelectionLayout(
navigator: ReceiverSelectionNavigator,
isEditing: Boolean,
keyboard: SoftwareKeyboardController?,
pagingData: LazyPagingItems<User>,
state: SendUiState,
action: (SendAction) -> Unit,
) {
SubcomposeLayout { constraints ->
val listGradientPlaceable = subcompose("listGradient") {
ListBottomGradient(height = 124)
}.first().measure(constraints)

val selectButtonPlaceable = subcompose("selectButton") {
WSButton(
onClick = {
if (isEditing) {
navigator.navigateUp()
return@WSButton
}
navigator.navigateMessageWriteScreen(
args = MessageWriteScreenArgs(isEditing = false),
)
},
paddingValues = PaddingValues(0.dp),
enabled = state.selectedUser.name.isNotBlank(),
text = if (isEditing) stringResource(R.string.edit_done) else stringResource(R.string.next),
content = { it() },
)
}.first().measure(constraints)

val receiverListMaxHeight = constraints.maxHeight - selectButtonPlaceable.height
val receiverListPlaceable = subcompose("receiverList") {
LazyColumn(modifier = Modifier.padding(top = 16.dp)) {
items(
pagingData.itemCount,
key = pagingData.itemKey { it.id },
Expand Down Expand Up @@ -209,54 +279,19 @@ fun ReceiverSelectionScreen(
}
}
}
}
}

Box(
modifier = Modifier
.fillMaxSize()
.imePadding()
.zIndex(1f),
contentAlignment = Alignment.BottomCenter,
) {
ListBottomGradient(height = 124)

WSButton(
onClick = {
if (navArgs.isEditing) {
navigator.navigateUp()
return@WSButton
}
navigator.navigateMessageWriteScreen(
args = MessageWriteScreenArgs(isEditing = false),
)
},
enabled = state.selectedUser.name.isNotBlank(),
text = if (navArgs.isEditing) stringResource(R.string.edit_done) else stringResource(R.string.next),
content = { it() },
)
}

if (dialogState) {
SendExitDialog(
isReservedMessage = state.isReservedMessage,
okButtonClick = {
dialogState = false
navigator.popUpToMessageScreen()
},
cancelButtonClick = { dialogState = false },
)
}
}.first().measure(constraints.copy(maxHeight = receiverListMaxHeight))

NetworkDialog(context = context, networkState = networkState)
var yPosition = 0
layout(constraints.maxWidth, constraints.maxHeight) {
receiverListPlaceable.placeRelative(0, yPosition)
yPosition += receiverListMaxHeight

LaunchedEffect(focusRequester) {
focusRequester.requestFocus()
delay(10)
keyboard?.show()
}
listGradientPlaceable.placeRelative(
x = 0,
y = constraints.maxHeight - listGradientPlaceable.height,
)

LaunchedEffect(Unit) {
action(SendAction.OnReceiverScreenEntered)
selectButtonPlaceable.placeRelative(0, yPosition)
}
}
}

0 comments on commit 11ff383

Please sign in to comment.