@@ -14,6 +14,7 @@ import androidx.compose.foundation.clickable
1414import androidx.compose.foundation.interaction.MutableInteractionSource
1515import androidx.compose.foundation.layout.Arrangement
1616import androidx.compose.foundation.layout.Box
17+ import androidx.compose.foundation.layout.BoxWithConstraints
1718import androidx.compose.foundation.layout.Column
1819import androidx.compose.foundation.layout.PaddingValues
1920import androidx.compose.foundation.layout.Spacer
@@ -33,6 +34,7 @@ import androidx.compose.foundation.lazy.LazyColumn
3334import androidx.compose.foundation.lazy.items
3435import androidx.compose.foundation.lazy.rememberLazyListState
3536import androidx.compose.foundation.pager.HorizontalPager
37+ import androidx.compose.foundation.pager.PageSize
3638import androidx.compose.foundation.pager.rememberPagerState
3739import androidx.compose.material3.CircularProgressIndicator
3840import 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