@@ -2,20 +2,18 @@ package net.mullvad.mullvadvpn.compose.screen
2
2
3
3
import android.content.Intent
4
4
import android.net.Uri
5
- import androidx.compose.foundation.background
5
+ import androidx.compose.animation.animateContentSize
6
6
import androidx.compose.foundation.layout.Arrangement
7
7
import androidx.compose.foundation.layout.Column
8
8
import androidx.compose.foundation.layout.Spacer
9
+ import androidx.compose.foundation.layout.defaultMinSize
9
10
import androidx.compose.foundation.layout.fillMaxHeight
10
- import androidx.compose.foundation.layout.fillMaxSize
11
11
import androidx.compose.foundation.layout.fillMaxWidth
12
12
import androidx.compose.foundation.layout.height
13
13
import androidx.compose.foundation.layout.padding
14
14
import androidx.compose.foundation.rememberScrollState
15
15
import androidx.compose.foundation.verticalScroll
16
- import androidx.compose.material3.Divider
17
16
import androidx.compose.material3.MaterialTheme
18
- import androidx.compose.material3.Slider
19
17
import androidx.compose.material3.Text
20
18
import androidx.compose.runtime.Composable
21
19
import androidx.compose.runtime.LaunchedEffect
@@ -29,13 +27,13 @@ import androidx.compose.runtime.saveable.rememberSaveable
29
27
import androidx.compose.runtime.setValue
30
28
import androidx.compose.ui.Alignment
31
29
import androidx.compose.ui.Modifier
32
- import androidx.compose.ui.graphics.Color
30
+ import androidx.compose.ui.draw.alpha
31
+ import androidx.compose.ui.layout.onGloballyPositioned
32
+ import androidx.compose.ui.layout.positionInParent
33
33
import androidx.compose.ui.platform.LocalContext
34
34
import androidx.compose.ui.platform.testTag
35
35
import androidx.compose.ui.res.stringResource
36
36
import androidx.compose.ui.tooling.preview.Preview
37
- import androidx.compose.ui.unit.dp
38
- import androidx.constraintlayout.compose.ConstraintLayout
39
37
import com.ramcosta.composedestinations.annotation.Destination
40
38
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
41
39
import com.ramcosta.composedestinations.navigation.popUpTo
@@ -193,40 +191,28 @@ fun ConnectScreen(
193
191
deviceName = uiState.deviceName,
194
192
timeLeft = uiState.daysLeftUntilExpiry
195
193
) {
196
- var bias by remember { mutableFloatStateOf(0.5f ) }
194
+ var progressIndicatorBias by remember { mutableFloatStateOf(0f ) }
195
+
197
196
Map (
198
197
modifier = Modifier .padding(top = it.calculateTopPadding()),
199
198
uiState.animateMap,
200
199
uiState.location?.toLatLong() ? : gothenburgLatLong,
201
200
marker = uiState.tunnelRealState.toMarker(uiState.location),
202
- bias ,
201
+ progressIndicatorBias ,
203
202
)
204
- ConstraintLayout (
205
- modifier = Modifier .padding(top = it.calculateTopPadding()).fillMaxSize()
206
- ) {
207
- val (divider) = createRefs()
208
- Divider (
209
- modifier =
210
- Modifier .background(Color .Cyan ).constrainAs(divider) {
211
- start.linkTo(parent.start)
212
- end.linkTo(parent.end)
213
- top.linkTo(parent.top)
214
- centerVerticallyTo(parent, bias)
215
- }
216
- )
217
- }
203
+
218
204
Column (
219
205
verticalArrangement = Arrangement .Bottom ,
220
206
horizontalAlignment = Alignment .Start ,
221
207
modifier =
222
- Modifier .padding(it)
208
+ Modifier .animateContentSize()
209
+ .padding(top = it.calculateTopPadding())
223
210
.fillMaxHeight()
224
211
.drawVerticalScrollbar(
225
212
scrollState,
226
213
color = MaterialTheme .colorScheme.onPrimary.copy(alpha = AlphaScrollbar )
227
214
)
228
215
.verticalScroll(scrollState)
229
- .padding(bottom = Dimens .screenVerticalMargin)
230
216
.testTag(SCROLLABLE_COLUMN_TEST_TAG )
231
217
) {
232
218
NotificationBanner (
@@ -236,31 +222,34 @@ fun ConnectScreen(
236
222
onClickShowAccount = onManageAccountClick,
237
223
onClickDismissNewDevice = onDismissNewDeviceClick,
238
224
)
239
- Slider (
240
- modifier = Modifier .padding(16 .dp),
241
- value = bias,
242
- onValueChange = { bias = it },
243
- valueRange = 0f .. 1f ,
244
- )
245
- Text (text = " Bias: $bias " )
225
+
246
226
Spacer (modifier = Modifier .weight(1f ))
247
- if (
248
- uiState.tunnelRealState is TunnelState .Connecting ||
249
- uiState.tunnelRealState is TunnelState .Disconnecting
250
- ) {
251
- MullvadCircularProgressIndicatorLarge (
252
- color = MaterialTheme .colorScheme.onPrimary,
253
- modifier =
254
- Modifier .padding(
255
- start = Dimens .sideMargin,
256
- end = Dimens .sideMargin,
257
- top = Dimens .mediumPadding
227
+ MullvadCircularProgressIndicatorLarge (
228
+ color = MaterialTheme .colorScheme.onPrimary,
229
+ modifier =
230
+ Modifier .animateContentSize()
231
+ .padding(
232
+ start = Dimens .sideMargin,
233
+ end = Dimens .sideMargin,
234
+ top = Dimens .mediumPadding
235
+ )
236
+ .alpha(
237
+ if (
238
+ uiState.tunnelRealState is TunnelState .Connecting ||
239
+ uiState.tunnelRealState is TunnelState .Disconnecting
258
240
)
259
- .align(Alignment .CenterHorizontally )
260
- .testTag(CIRCULAR_PROGRESS_INDICATOR )
261
- )
262
- }
263
- Spacer (modifier = Modifier .height(Dimens .mediumPadding))
241
+ 1f
242
+ else 0f
243
+ )
244
+ .align(Alignment .CenterHorizontally )
245
+ .testTag(CIRCULAR_PROGRESS_INDICATOR )
246
+ .onGloballyPositioned {
247
+ val offsetY = it.positionInParent().y + it.size.height / 2
248
+ progressIndicatorBias =
249
+ offsetY / it.parentLayoutCoordinates?.size?.height?.toFloat()!!
250
+ }
251
+ )
252
+ Spacer (modifier = Modifier .defaultMinSize(minHeight = Dimens .mediumPadding).weight(1f ))
264
253
ConnectionStatusText (
265
254
state = uiState.tunnelRealState,
266
255
modifier = Modifier .padding(horizontal = Dimens .sideMargin)
@@ -319,6 +308,9 @@ fun ConnectScreen(
319
308
connectClick = { handleThrottledAction(onConnectClick) },
320
309
reconnectButtonTestTag = RECONNECT_BUTTON_TEST_TAG
321
310
)
311
+ // We need to manually add this padding so we align size with the map
312
+ // component and marker with the progress indicator.
313
+ Spacer (modifier = Modifier .height(it.calculateBottomPadding()))
322
314
}
323
315
}
324
316
}
@@ -342,6 +334,7 @@ fun TunnelState.toMarker(location: GeoIpLocation?): net.mullvad.mullvadvpn.lib.m
342
334
}
343
335
}
344
336
345
- fun GeoIpLocation.toLatLong () = LatLong (Latitude (latitude.toFloat()), Longitude (longitude.toFloat()))
337
+ fun GeoIpLocation.toLatLong () =
338
+ LatLong (Latitude (latitude.toFloat()), Longitude (longitude.toFloat()))
346
339
347
340
val gothenburgLatLong = LatLong (Latitude (57.7065f ), Longitude (11.967f ))
0 commit comments