Skip to content

Commit ea9bf1f

Browse files
committed
Fix animations and clean up
1 parent 7377e14 commit ea9bf1f

File tree

11 files changed

+62
-66
lines changed

11 files changed

+62
-66
lines changed

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/notificationbanner/NotificationBanner.kt

+18-20
Original file line numberDiff line numberDiff line change
@@ -89,33 +89,31 @@ private fun PreviewNotificationBanner() {
8989

9090
@Composable
9191
fun NotificationBanner(
92+
modifier: Modifier,
9293
notification: InAppNotification?,
9394
isPlayBuild: Boolean,
9495
onClickUpdateVersion: () -> Unit,
9596
onClickShowAccount: () -> Unit,
9697
onClickDismissNewDevice: () -> Unit
9798
) {
98-
99-
// Hack to make sure view expands and contracts when AnimatedVisiblity is used
100-
Box(modifier = Modifier.animateContentSize()) {
101-
// Fix for animating to invisible state
102-
val previous = rememberPrevious(current = notification, shouldUpdate = { _, _ -> true })
103-
AnimatedVisibility(
104-
visible = notification != null,
105-
enter = slideInVertically(initialOffsetY = { -it }),
106-
exit = slideOutVertically(targetOffsetY = { -it }),
107-
) {
108-
val visibleNotification = notification ?: previous
109-
if (visibleNotification != null)
110-
Notification(
111-
visibleNotification.toNotificationData(
112-
isPlayBuild = isPlayBuild,
113-
onClickUpdateVersion,
114-
onClickShowAccount,
115-
onClickDismissNewDevice
116-
)
99+
// Fix for animating to invisible state
100+
val previous = rememberPrevious(current = notification, shouldUpdate = { _, _ -> true })
101+
AnimatedVisibility(
102+
modifier = modifier,
103+
visible = notification != null,
104+
enter = slideInVertically(initialOffsetY = { -it }),
105+
exit = slideOutVertically(targetOffsetY = { -it }),
106+
) {
107+
val visibleNotification = notification ?: previous
108+
if (visibleNotification != null)
109+
Notification(
110+
visibleNotification.toNotificationData(
111+
isPlayBuild = isPlayBuild,
112+
onClickUpdateVersion,
113+
onClickShowAccount,
114+
onClickDismissNewDevice
117115
)
118-
}
116+
)
119117
}
120118
}
121119

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Intent
44
import android.net.Uri
55
import androidx.compose.animation.animateContentSize
66
import androidx.compose.foundation.layout.Arrangement
7+
import androidx.compose.foundation.layout.Box
78
import androidx.compose.foundation.layout.Column
89
import androidx.compose.foundation.layout.Spacer
910
import androidx.compose.foundation.layout.defaultMinSize
@@ -201,6 +202,15 @@ fun ConnectScreen(
201202
progressIndicatorBias,
202203
)
203204

205+
NotificationBanner(
206+
modifier = Modifier.padding(top = it.calculateTopPadding()),
207+
notification = uiState.inAppNotification,
208+
isPlayBuild = uiState.isPlayBuild,
209+
onClickUpdateVersion = onUpdateVersionClick,
210+
onClickShowAccount = onManageAccountClick,
211+
onClickDismissNewDevice = onDismissNewDeviceClick,
212+
)
213+
204214
Column(
205215
verticalArrangement = Arrangement.Bottom,
206216
horizontalAlignment = Alignment.Start,
@@ -215,15 +225,7 @@ fun ConnectScreen(
215225
.verticalScroll(scrollState)
216226
.testTag(SCROLLABLE_COLUMN_TEST_TAG)
217227
) {
218-
NotificationBanner(
219-
notification = uiState.inAppNotification,
220-
isPlayBuild = uiState.isPlayBuild,
221-
onClickUpdateVersion = onUpdateVersionClick,
222-
onClickShowAccount = onManageAccountClick,
223-
onClickDismissNewDevice = onDismissNewDeviceClick,
224-
)
225-
226-
Spacer(modifier = Modifier.weight(1f))
228+
Spacer(modifier = Modifier.defaultMinSize(minHeight = Dimens.mediumPadding).weight(1f))
227229
MullvadCircularProgressIndicatorLarge(
228230
color = MaterialTheme.colorScheme.onPrimary,
229231
modifier =

android/lib/map/src/main/kotlin/net/mullvad/mullvadvpn/lib/map/CameraAnimation.kt

+11-4
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ fun animatedCameraPosition(
6565
targetValue = 1f,
6666
animationSpec =
6767
keyframes {
68-
if (duration < SHORT_ANIMATION_MILLIS) {
68+
if (duration < SHORT_ANIMATION_CUTOFF_MILLIS) {
6969
durationMillis = duration
7070
1f at duration using EaseInOut
7171
} else {
7272
durationMillis = duration
73-
1.25f at duration / 3 using EaseInOut
73+
FAR_ANIMATION_MAX_ZOOM_MULTIPLIER at
74+
(duration * MAX_MULTIPLIER_PEAK_TIMING).toInt() using
75+
EaseInOut
7476
1f at duration using EaseInOut
7577
}
7678
}
@@ -79,11 +81,16 @@ fun animatedCameraPosition(
7981
}
8082

8183
LaunchedEffect(marker?.type) {
82-
launch { secureZoomAnimation.animateTo(targetValue = marker?.type.toZoom(), tween(2000)) }
84+
launch {
85+
secureZoomAnimation.animateTo(
86+
targetValue = marker?.type.toZoom(),
87+
tween(SECURE_ZOOM_ANIMATION_MILLIS)
88+
)
89+
}
8390
}
8491

8592
return CameraPosition(
86-
zoom = secureZoomAnimation.value * zoomOutMultiplier.value * 0.9f,
93+
zoom = secureZoomAnimation.value * zoomOutMultiplier.value,
8794
latLong =
8895
LatLong(
8996
Latitude(latitudeAnimation.value),

android/lib/map/src/main/kotlin/net/mullvad/mullvadvpn/lib/map/Map.kt

+15-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,21 @@ fun MarkerType?.toZoom() =
7979
fun Int.toAnimationDuration() =
8080
(this * DISTANCE_DURATION_SCALE_FACTOR).coerceIn(MIN_ANIMATION_MILLIS, MAX_ANIMATION_MILLIS)
8181

82-
const val SECURE_ZOOM = 1.25f
83-
const val UNSECURE_ZOOM = 1.35f
82+
// Distance to marker when secure/unsecure
83+
const val SECURE_ZOOM = 1.15f
84+
const val UNSECURE_ZOOM = 1.20f
85+
const val SECURE_ZOOM_ANIMATION_MILLIS = 2000
86+
87+
// Constant what will talk the distance in LatLng multiply it to determine the animation duration,
88+
// the result is then confined to the MIN_ANIMATION_MILLIS and MAX_ANIMATION_MILLIS
8489
const val DISTANCE_DURATION_SCALE_FACTOR = 20
85-
const val SHORT_ANIMATION_MILLIS = 1700
8690
const val MIN_ANIMATION_MILLIS = 1300
8791
const val MAX_ANIMATION_MILLIS = 2500
92+
// The cut off where we go from a short animation (camera pans) to a far animation (camera pans +
93+
// zoom out)
94+
const val SHORT_ANIMATION_CUTOFF_MILLIS = 1700
95+
96+
// Multiplier for the zoom out animation
97+
const val FAR_ANIMATION_MAX_ZOOM_MULTIPLIER = 1.30f
98+
// When in the far animation we reach the MAX_ZOOM_MULTIPLIER, value is between 0 and 1
99+
const val MAX_MULTIPLIER_PEAK_TIMING = .35f

android/lib/map/src/main/kotlin/net/mullvad/mullvadvpn/lib/map/internal/Constants.kt

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ package net.mullvad.mullvadvpn.lib.map.internal
22

33
internal const val VERTEX_COMPONENT_SIZE = 3
44
internal const val COLOR_COMPONENT_SIZE = 4
5-
65
internal const val MATRIX_SIZE = 16

android/lib/map/src/main/kotlin/net/mullvad/mullvadvpn/lib/map/internal/GLHelper.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,11 @@ internal fun initIndexBuffer(dataBuffer: Buffer): IndexBufferWithLength {
9898
)
9999
}
100100

101+
internal class IndexBufferWithLength(val indexBuffer: Int, val length: Int)
102+
101103
internal fun newIdentityMatrix(): FloatArray =
102104
FloatArray(MATRIX_SIZE).apply { Matrix.setIdentityM(this, 0) }
103105

104106
internal fun Color.toFloatArray(): FloatArray {
105107
return floatArrayOf(red, green, blue, alpha)
106-
}
107-
108-
internal fun Color.toFloatArrayWithoutAlpha(): FloatArray {
109-
return floatArrayOf(red, green, blue)
110-
}
108+
}

android/lib/map/src/main/kotlin/net/mullvad/mullvadvpn/lib/map/internal/IndexBufferWithLength.kt

-3
This file was deleted.

android/lib/map/src/main/res/raw/fragment_shader.glsl

-4
This file was deleted.

android/lib/map/src/main/res/raw/vertex_shader.glsl

-9
This file was deleted.

android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Latitude.kt

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ value class Latitude(val value: Float) {
1717
operator fun minus(other: Latitude) = fromFloat(value - other.value)
1818

1919
companion object {
20-
private const val MIN_LATITUDE_VALUE: Float = -COMPLETE_ANGLE / 4 // -90
21-
private const val MAX_LATITUDE_VALUE: Float = COMPLETE_ANGLE / 4 // 90
20+
private const val MIN_LATITUDE_VALUE: Float = -90f
21+
private const val MAX_LATITUDE_VALUE: Float = 90f
2222
private val LATITUDE_RANGE = MIN_LATITUDE_VALUE..MAX_LATITUDE_VALUE
2323

2424
/**
@@ -53,7 +53,3 @@ value class Latitude(val value: Float) {
5353
}
5454
}
5555
}
56-
57-
fun Float.toRadians(): Float {
58-
return this * (Math.PI.toFloat() / 180f)
59-
}

android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Longitude.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ value class Longitude(val value: Float) {
2828
operator fun minus(other: Longitude) = fromFloat(value - other.value)
2929

3030
companion object {
31-
private const val MIN_LONGITUDE_VALUE: Float = -COMPLETE_ANGLE / 2 // -180
32-
private const val MAX_LONGITUDE_VALUE: Float = COMPLETE_ANGLE / 2 // 180
31+
private const val MIN_LONGITUDE_VALUE: Float = -180f
32+
private const val MAX_LONGITUDE_VALUE: Float = 180f
3333
private val LONGITUDE_RANGE = MIN_LONGITUDE_VALUE..MAX_LONGITUDE_VALUE
3434

3535
/**

0 commit comments

Comments
 (0)