Skip to content

Commit 1d09d78

Browse files
committed
[feature/#34] 요정 선택 페이저 UI 오류 수정
1 parent a617aa1 commit 1d09d78

File tree

1 file changed

+63
-52
lines changed
  • feature/chatting/src/commonMain/kotlin/com/nexters/emotia/feature/chatting

1 file changed

+63
-52
lines changed

feature/chatting/src/commonMain/kotlin/com/nexters/emotia/feature/chatting/ChattingScreen.kt

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.foundation.clickable
1414
import androidx.compose.foundation.interaction.MutableInteractionSource
1515
import androidx.compose.foundation.layout.Arrangement
1616
import androidx.compose.foundation.layout.Box
17+
import androidx.compose.foundation.layout.BoxWithConstraints
1718
import androidx.compose.foundation.layout.Column
1819
import androidx.compose.foundation.layout.PaddingValues
1920
import androidx.compose.foundation.layout.Spacer
@@ -33,6 +34,7 @@ import androidx.compose.foundation.lazy.LazyColumn
3334
import androidx.compose.foundation.lazy.items
3435
import androidx.compose.foundation.lazy.rememberLazyListState
3536
import androidx.compose.foundation.pager.HorizontalPager
37+
import androidx.compose.foundation.pager.PageSize
3638
import androidx.compose.foundation.pager.rememberPagerState
3739
import androidx.compose.material3.CircularProgressIndicator
3840
import androidx.compose.material3.Text
@@ -297,63 +299,72 @@ fun ChattingScreen(
297299

298300
Spacer(Modifier.height(84.dp))
299301

300-
HorizontalPager(
301-
state = pagerState,
302-
modifier = Modifier
303-
.fillMaxWidth()
304-
.padding(vertical = 28.dp),
305-
contentPadding = PaddingValues(horizontal = 80.dp),
306-
pageSpacing = 24.dp
307-
) { page ->
308-
val fairy = uiState.fairies[page]
309-
val isSelected =
310-
page == pagerState.currentPage
311-
312-
val yOffset by animateFloatAsState(
313-
targetValue = if (isSelected) 0f else 28f,
314-
animationSpec = tween(
315-
durationMillis = 300,
316-
easing = FastOutSlowInEasing
317-
)
302+
BoxWithConstraints {
303+
val cardWidth = 200.dp
304+
val horizontalPadding = maxOf(
305+
0.dp,
306+
(maxWidth - cardWidth) / 2
318307
)
319308

320-
FairyCard(
321-
name = fairy.name,
322-
image = fairy.silhouetteImage,
323-
emotion = fairy.emotion,
324-
emotionDescription = fairy.description,
325-
isSelected = isSelected,
309+
HorizontalPager(
310+
state = pagerState,
326311
modifier = Modifier
327-
.size(
328-
width = 200.dp,
329-
height = 280.dp
312+
.fillMaxWidth()
313+
.padding(vertical = 28.dp),
314+
pageSize = PageSize.Fixed(cardWidth),
315+
pageSpacing = 24.dp,
316+
contentPadding = PaddingValues(horizontal = horizontalPadding)
317+
) { page ->
318+
val fairy = uiState.fairies[page]
319+
val isSelected =
320+
page == pagerState.currentPage
321+
322+
val yOffset by animateFloatAsState(
323+
targetValue = if (isSelected) 0f else 28f,
324+
animationSpec = tween(
325+
durationMillis = 300,
326+
easing = FastOutSlowInEasing
330327
)
331-
.offset(y = yOffset.dp)
332-
.then(
333-
if (isSelected) {
334-
Modifier.onGloballyPositioned { coordinates ->
335-
val position =
336-
coordinates.positionInRoot()
337-
val size =
338-
coordinates.size
339-
fairyCardCenter =
340-
Offset(
341-
x = position.x + size.width / 2,
342-
y = position.y + size.height / 2 - with(
343-
density
344-
) { 50.dp.toPx() }
345-
)
346-
fairyCardSize =
347-
minOf(
348-
size.width,
349-
size.height
350-
) / 2f
328+
)
329+
330+
FairyCard(
331+
name = fairy.name,
332+
image = fairy.silhouetteImage,
333+
emotion = fairy.emotion,
334+
emotionDescription = fairy.description,
335+
isSelected = isSelected,
336+
modifier = Modifier
337+
.size(
338+
width = 200.dp,
339+
height = 280.dp
340+
)
341+
.offset(y = yOffset.dp)
342+
.then(
343+
if (isSelected) {
344+
Modifier.onGloballyPositioned { coordinates ->
345+
val position =
346+
coordinates.positionInRoot()
347+
val size =
348+
coordinates.size
349+
fairyCardCenter =
350+
Offset(
351+
x = position.x + size.width / 2,
352+
y = position.y + size.height / 2 - with(
353+
density
354+
) { 50.dp.toPx() }
355+
)
356+
fairyCardSize =
357+
minOf(
358+
size.width,
359+
size.height
360+
) / 2f
361+
}
362+
} else {
363+
Modifier
351364
}
352-
} else {
353-
Modifier
354-
}
355-
)
356-
)
365+
)
366+
)
367+
}
357368
}
358369

359370
Spacer(Modifier.height(60.dp))

0 commit comments

Comments
 (0)