diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:02:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:02:01 +0000 |
commit | 088c0cefd0f8b5482cc227955cc3057d47ec24b6 (patch) | |
tree | 05f2021c7dd804334bcb781bb0c4881e971cd8fe /mobile/android/fenix | |
parent | Adding debian version 126.0-1. (diff) | |
download | firefox-088c0cefd0f8b5482cc227955cc3057d47ec24b6.tar.xz firefox-088c0cefd0f8b5482cc227955cc3057d47ec24b6.zip |
Merging upstream version 126.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/fenix')
3 files changed, 60 insertions, 4 deletions
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/compose/SwipeToDismissBox.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/compose/SwipeToDismissBox.kt index 9992cf75d3..8c5159baec 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/compose/SwipeToDismissBox.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/compose/SwipeToDismissBox.kt @@ -124,6 +124,20 @@ class SwipeToDismissState( */ val isSwipingToStart: Boolean get() = swipeDestination == SwipeToDismissAnchor.Start + + /** + * The current [IntOffset] of the swipe. If the X-offset is currently [Float.NaN], it will return 0. + */ + val safeSwipeOffset: IntOffset + get() { + val xOffset = if (anchoredDraggableState.offset.isNaN()) { + 0 + } else { + anchoredDraggableState.offset.roundToInt() + } + + return IntOffset(x = xOffset, y = 0) + } } /** @@ -186,7 +200,7 @@ fun SwipeToDismissBox( ) Box( - modifier = Modifier.offset { IntOffset(state.anchoredDraggableState.offset.roundToInt(), 0) }, + modifier = Modifier.offset { state.safeSwipeOffset }, content = dismissContent, ) } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/messaging/state/MessagingMiddleware.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/messaging/state/MessagingMiddleware.kt index 46ac69595c..2122e1efee 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/messaging/state/MessagingMiddleware.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/messaging/state/MessagingMiddleware.kt @@ -135,8 +135,15 @@ class MessagingMiddleware( context.store.dispatch(UpdateMessageToShow(updatedMessage)) } val oldMessageIndex = context.state.messaging.messages.indexOfFirst { it.id == updatedMessage.id } - val newList = context.state.messaging.messages.toMutableList() - newList[oldMessageIndex] = updatedMessage - return newList + + return if (oldMessageIndex != -1) { + val newList = context.state.messaging.messages.toMutableList() + newList[oldMessageIndex] = updatedMessage + newList + } else { + // No need to update the message, it was removed. This is due to a race condition, see: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1897485 + context.state.messaging.messages + } } } diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/messaging/state/MessagingMiddlewareTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/messaging/state/MessagingMiddlewareTest.kt index 88b9161583..05e20c1163 100644 --- a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/messaging/state/MessagingMiddlewareTest.kt +++ b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/messaging/state/MessagingMiddlewareTest.kt @@ -347,6 +347,41 @@ class MessagingMiddlewareTest { assertEquals(0, store.state.messaging.messages.size) assertEquals(0, store.state.messaging.messageToShow.size) } + + @Test + fun `GIVEN message is not found WHEN updateMessage THEN do not update the message list`() = runTestOnMain { + val message = createMessage(messageId = "1") + val message2 = createMessage(messageId = "2") + val store = AppStore( + AppState( + messaging = MessagingState( + messages = listOf( + message, + ), + ), + ), + listOf( + MessagingMiddleware(controller, coroutineScope), + ), + ) + + every { + controller.getNextMessage( + FenixMessageSurfaceId.HOMESCREEN, + any(), + ) + } returns message + + coEvery { + controller.onMessageDisplayed(eq(message), any()) + } returns message2 + + store.dispatch(Evaluate(FenixMessageSurfaceId.HOMESCREEN)).joinBlocking() + store.waitUntilIdle() + + assertEquals(1, store.state.messaging.messages.count()) + assertEquals(message, store.state.messaging.messages.first()) + } } private fun createMessage( metadata: Message.Metadata = createMetadata(), |