Skip to content

Commit 8ed56d8

Browse files
committed
[REFACTOR]#223 : 쪽지 작성 페이지, 기존 레이아웃 쌓는 구조에서 subComposeLayout을 활용해 버튼 최하단에 배치하도록 수정
1 parent 7be391e commit 8ed56d8

File tree

1 file changed

+73
-60
lines changed

1 file changed

+73
-60
lines changed

feature/message/src/main/kotlin/com/bff/wespot/message/screen/send/MessageWriteScreen.kt

+73-60
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package com.bff.wespot.message.screen.send
22

33
import androidx.compose.foundation.clickable
44
import androidx.compose.foundation.layout.Arrangement
5-
import androidx.compose.foundation.layout.Box
65
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.PaddingValues
77
import androidx.compose.foundation.layout.Row
88
import androidx.compose.foundation.layout.Spacer
9-
import androidx.compose.foundation.layout.fillMaxSize
109
import androidx.compose.foundation.layout.fillMaxWidth
1110
import androidx.compose.foundation.layout.padding
1211
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -21,6 +20,7 @@ import androidx.compose.runtime.setValue
2120
import androidx.compose.ui.Alignment
2221
import androidx.compose.ui.Modifier
2322
import androidx.compose.ui.focus.FocusRequester
23+
import androidx.compose.ui.layout.SubcomposeLayout
2424
import androidx.compose.ui.platform.LocalContext
2525
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
2626
import androidx.compose.ui.res.stringResource
@@ -96,79 +96,92 @@ fun MessageWriteScreen(
9696
)
9797
},
9898
) {
99-
Column(
99+
SubcomposeLayout(
100100
modifier = Modifier
101101
.padding(it)
102102
.padding(horizontal = 20.dp),
103-
) {
104-
Text(
105-
modifier = Modifier
106-
.fillMaxWidth()
107-
.padding(horizontal = 3.dp),
108-
text = stringResource(R.string.message_write_title),
109-
style = StaticTypeScale.Default.header1,
110-
color = WeSpotThemeManager.colors.txtTitleColor,
111-
)
103+
) { constraints ->
104+
val buttonPlaceable = subcompose("button") {
105+
WSButton(
106+
onClick = {
107+
if (state.isReservedMessage) {
108+
navigator.navigateUp()
109+
} else {
110+
navigator.navigateMessageEditScreen(EditMessageScreenArgs())
111+
}
112+
},
113+
paddingValues = PaddingValues(0.dp),
114+
enabled = state.messageInput.length in 1..MESSAGE_MAX_LENGTH && state.hasProfanity.not(),
115+
text = stringResource(
116+
if (navArgs.isEditing) R.string.edit_done else R.string.write_done,
117+
),
118+
content = { it() },
119+
)
120+
}.first().measure(constraints)
112121

113-
Spacer(modifier = Modifier.padding(top = 16.dp))
122+
val contentMaxHeight = constraints.maxHeight - buttonPlaceable.height
123+
val contentPlaceable = subcompose("content") {
124+
Column {
125+
Text(
126+
modifier = Modifier
127+
.fillMaxWidth()
128+
.padding(horizontal = 3.dp),
129+
text = stringResource(R.string.message_write_title),
130+
style = StaticTypeScale.Default.header1,
131+
color = WeSpotThemeManager.colors.txtTitleColor,
132+
)
114133

115-
WsTextField(
116-
value = state.messageInput,
117-
onValueChange = { text ->
118-
action(SendAction.OnMessageChanged(text))
119-
},
120-
placeholder = stringResource(R.string.message_write_text_holder),
121-
isError = false,
122-
focusRequester = focusRequester,
123-
textFieldType = WsTextFieldType.Message,
124-
)
134+
Spacer(modifier = Modifier.padding(top = 16.dp))
135+
136+
WsTextField(
137+
value = state.messageInput,
138+
onValueChange = { text ->
139+
action(SendAction.OnMessageChanged(text))
140+
},
141+
placeholder = stringResource(R.string.message_write_text_holder),
142+
isError = false,
143+
focusRequester = focusRequester,
144+
textFieldType = WsTextFieldType.Message,
145+
)
125146

126-
Row(
127-
modifier = Modifier.fillMaxWidth(),
128-
verticalAlignment = Alignment.CenterVertically,
129-
horizontalArrangement = Arrangement.SpaceBetween,
130-
) {
131-
val warningMessage = when {
132-
state.messageInput.length > MESSAGE_MAX_LENGTH -> {
133-
stringResource(R.string.message_length_limit)
147+
Row(
148+
modifier = Modifier.fillMaxWidth(),
149+
verticalAlignment = Alignment.CenterVertically,
150+
horizontalArrangement = Arrangement.SpaceBetween,
151+
) {
152+
val warningMessage = when {
153+
state.messageInput.length > MESSAGE_MAX_LENGTH -> {
154+
stringResource(R.string.message_length_limit)
155+
}
156+
157+
state.hasProfanity -> {
158+
stringResource(com.bff.wespot.designsystem.R.string.has_profanity)
159+
}
160+
else -> ""
161+
}
162+
163+
Text(
164+
modifier = Modifier.padding(top = 5.dp, start = 10.dp, end = 10.dp),
165+
text = warningMessage,
166+
style = StaticTypeScale.Default.body7,
167+
color = WeSpotThemeManager.colors.dangerColor,
168+
)
169+
170+
LetterCountIndicator(currentCount = state.messageInput.length, maxCount = 200)
134171
}
135172

136-
state.hasProfanity -> {
137-
stringResource(com.bff.wespot.designsystem.R.string.has_profanity)
138-
}
139-
else -> ""
173+
Spacer(modifier = Modifier.weight(1f))
140174
}
175+
}.first().measure(constraints.copy(maxHeight = contentMaxHeight))
141176

142-
Text(
143-
modifier = Modifier.padding(top = 5.dp, start = 10.dp, end = 10.dp),
144-
text = warningMessage,
145-
style = StaticTypeScale.Default.body7,
146-
color = WeSpotThemeManager.colors.dangerColor,
147-
)
177+
layout(constraints.maxWidth, constraints.maxHeight) {
178+
contentPlaceable.placeRelative(0, 0)
148179

149-
LetterCountIndicator(currentCount = state.messageInput.length, maxCount = 200)
180+
buttonPlaceable.placeRelative(0, contentMaxHeight)
150181
}
151182
}
152183
}
153184

154-
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
155-
WSButton(
156-
onClick = {
157-
if (state.isReservedMessage) {
158-
navigator.navigateUp()
159-
} else {
160-
navigator.navigateMessageEditScreen(EditMessageScreenArgs())
161-
}
162-
},
163-
enabled = state.messageInput.length in 1..MESSAGE_MAX_LENGTH && state.hasProfanity.not(),
164-
text = stringResource(
165-
if (navArgs.isEditing) R.string.edit_done else R.string.write_done,
166-
),
167-
) {
168-
it()
169-
}
170-
}
171-
172185
if (dialogState) {
173186
SendExitDialog(
174187
isReservedMessage = state.isReservedMessage,

0 commit comments

Comments
 (0)