1
1
package com.trifork.feature.weather.presentation.components
2
2
3
+ import androidx.compose.animation.core.FastOutSlowInEasing
4
+ import androidx.compose.animation.core.tween
3
5
import androidx.compose.foundation.clickable
6
+ import androidx.compose.foundation.gestures.animateScrollBy
4
7
import androidx.compose.foundation.layout.Arrangement
5
8
import androidx.compose.foundation.layout.Column
6
9
import androidx.compose.foundation.layout.Row
@@ -11,23 +14,32 @@ import androidx.compose.foundation.layout.padding
11
14
import androidx.compose.foundation.layout.width
12
15
import androidx.compose.foundation.lazy.LazyRow
13
16
import androidx.compose.foundation.lazy.items
17
+ import androidx.compose.foundation.lazy.rememberLazyListState
14
18
import androidx.compose.material3.MaterialTheme
15
19
import androidx.compose.material3.Text
16
20
import androidx.compose.runtime.Composable
21
+ import androidx.compose.runtime.LaunchedEffect
22
+ import androidx.compose.runtime.getValue
23
+ import androidx.compose.runtime.mutableFloatStateOf
24
+ import androidx.compose.runtime.mutableStateOf
25
+ import androidx.compose.runtime.remember
26
+ import androidx.compose.runtime.setValue
17
27
import androidx.compose.ui.Alignment
18
28
import androidx.compose.ui.Modifier
29
+ import androidx.compose.ui.layout.onGloballyPositioned
30
+ import androidx.compose.ui.platform.LocalConfiguration
19
31
import androidx.compose.ui.platform.LocalContext
32
+ import androidx.compose.ui.platform.LocalDensity
20
33
import androidx.compose.ui.unit.dp
21
34
import androidx.compose.ui.unit.sp
22
- import com.trifork.feature.common.util.MonthString
23
35
import com.trifork.feature.common.util.WeekString
24
36
import com.trifork.feature.weather.domain.model.WeatherData
25
37
import com.trifork.feature.weather.domain.model.WeatherInfo
26
- import com.trifork.feature.weather.presentation.WeatherViewModel
27
38
import com.trifork.feature.weather.presentation.mvi.WeatherEvent
28
39
import kotlinx.collections.immutable.ImmutableList
40
+ import kotlinx.coroutines.delay
41
+ import kotlinx.coroutines.launch
29
42
import java.time.LocalDateTime
30
- import java.util.Locale
31
43
32
44
@Composable
33
45
fun WeatherForecast (
@@ -73,7 +85,13 @@ fun WeatherForecast(
73
85
)
74
86
}
75
87
Spacer (modifier = Modifier .height(16 .dp))
76
- LazyRow (content = {
88
+
89
+ val listState = rememberLazyListState()
90
+ val density = LocalDensity .current
91
+
92
+ LazyRow (
93
+ state = listState
94
+ ) {
77
95
items(perDay.filter { it.time.plusHours(1 ) > LocalDateTime .now() }) { weatherData ->
78
96
HourlyWeatherDisplay (
79
97
weatherData = weatherData,
@@ -93,6 +111,20 @@ fun WeatherForecast(
93
111
}
94
112
)
95
113
}
96
- })
114
+ }
115
+
116
+ if (perDay[0 ].time.dayOfMonth != LocalDateTime .now().dayOfMonth) {
117
+ LaunchedEffect (key1 = perDay) {
118
+ launch {
119
+ delay(500 )
120
+ val componentWidth = with (density) { (40 .dp.roundToPx() + 32 .dp.roundToPx()).toFloat() }
121
+ listState.animateScrollBy(
122
+ value = componentWidth * 11 ,
123
+ animationSpec = tween(3000 , easing = FastOutSlowInEasing )
124
+ )
125
+ listState.animateScrollToItem(10 )
126
+ }
127
+ }
128
+ }
97
129
}
98
130
}
0 commit comments