Skip to content

Commit 448785f

Browse files
committed
Add previews and snapshot tests for MessageComposerRecordingContent
1 parent 47173cd commit 448785f

6 files changed

+129
-28
lines changed

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,9 +2510,15 @@ public final class io/getstream/chat/android/compose/ui/messages/composer/intern
25102510
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/messages/composer/internal/ComposableSingletons$DefaultMessageComposerRecordingContentKt;
25112511
public static field lambda-1 Lkotlin/jvm/functions/Function2;
25122512
public static field lambda-2 Lkotlin/jvm/functions/Function2;
2513+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
2514+
public static field lambda-4 Lkotlin/jvm/functions/Function2;
2515+
public static field lambda-5 Lkotlin/jvm/functions/Function2;
25132516
public fun <init> ()V
25142517
public final fun getLambda-1$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
25152518
public final fun getLambda-2$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2519+
public final fun getLambda-3$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2520+
public final fun getLambda-4$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
2521+
public final fun getLambda-5$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
25162522
}
25172523

25182524
public final class io/getstream/chat/android/compose/ui/messages/composer/internal/DefaultMessageComposerRecordingContentKt {

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/composer/internal/DefaultMessageComposerRecordingContent.kt

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ import io.getstream.chat.android.ui.common.state.messages.composer.RecordingStat
9090
import io.getstream.chat.android.uiutils.util.openSystemSettings
9191
import kotlinx.coroutines.delay
9292
import kotlin.math.abs
93-
import kotlin.random.Random
9493

9594
private const val HOLD_TO_RECORD_THRESHOLD = 1000L
9695
private const val HOLD_TO_RECORD_DISMISS_TIMEOUT = 1000L
@@ -773,36 +772,82 @@ private fun RecordingControlButtons(
773772
}
774773
}
775774

776-
private fun formatMillis(milliseconds: Int): String {
777-
val totalSeconds = milliseconds / 1000
778-
val minutes = totalSeconds / 60
779-
val seconds = totalSeconds % 60
780-
return "%02d:%02d".format(minutes, seconds)
775+
@Preview(showBackground = true, heightDp = 200)
776+
@Composable
777+
private fun MessageComposerRecordingContentHoldPreview() {
778+
ChatPreviewTheme {
779+
MessageComposerRecordingContentHold()
780+
}
781+
}
782+
783+
@Composable
784+
internal fun MessageComposerRecordingContentHold() {
785+
Box(
786+
modifier = Modifier.fillMaxSize(),
787+
contentAlignment = BottomCenter,
788+
) {
789+
DefaultMessageComposerRecordingContent(
790+
durationInMs = DurationInMs,
791+
waveformVisible = false,
792+
waveformData = WaveformData,
793+
holdControlsVisible = true,
794+
recordingControlsVisible = false,
795+
)
796+
}
781797
}
782798

783-
@Preview(showBackground = true)
799+
@Preview(showBackground = true, heightDp = 200)
784800
@Composable
785-
internal fun DefaultMessageComposerRecordingContentPreview() {
786-
val randomWaveformData = List(150) { Random.nextFloat() }
801+
private fun MessageComposerRecordingContentLockPreview() {
787802
ChatPreviewTheme {
788-
Box(
789-
modifier = Modifier
790-
.fillMaxWidth(),
791-
contentAlignment = Alignment.Center,
792-
) {
793-
DefaultMessageComposerRecordingContent(
794-
modifier = Modifier.fillMaxWidth(),
795-
waveformVisible = true,
796-
waveformThumbVisible = true,
797-
waveformData = randomWaveformData,
798-
waveformProgress = 0.2f,
799-
slideToCancelVisible = true,
800-
holdControlsVisible = true,
801-
holdControlsLocked = false,
802-
holdControlsOffset = IntOffset(0, 0),
803-
recordingControlsVisible = true,
804-
recordingStopControlVisible = true,
805-
)
806-
}
803+
MessageComposerRecordingContentLock()
807804
}
808805
}
806+
807+
@Composable
808+
internal fun MessageComposerRecordingContentLock() {
809+
Box(
810+
modifier = Modifier.fillMaxSize(),
811+
contentAlignment = BottomCenter,
812+
) {
813+
DefaultMessageComposerRecordingContent(
814+
durationInMs = DurationInMs,
815+
waveformData = WaveformData,
816+
waveformProgress = 0.3f,
817+
slideToCancelVisible = false,
818+
holdControlsVisible = true,
819+
holdControlsLocked = true,
820+
)
821+
}
822+
}
823+
824+
@Preview(showBackground = true, heightDp = 200)
825+
@Composable
826+
private fun MessageComposerRecordingContentOverviewPreview() {
827+
ChatPreviewTheme {
828+
MessageComposerRecordingContentOverview()
829+
}
830+
}
831+
832+
@Composable
833+
internal fun MessageComposerRecordingContentOverview() {
834+
Box(
835+
modifier = Modifier.fillMaxSize(),
836+
contentAlignment = BottomCenter,
837+
) {
838+
DefaultMessageComposerRecordingContent(
839+
durationInMs = DurationInMs,
840+
waveformThumbVisible = true,
841+
waveformData = WaveformData,
842+
slideToCancelVisible = false,
843+
recordingStopControlVisible = false,
844+
)
845+
}
846+
}
847+
848+
private const val DurationInMs = 120_000
849+
850+
@Suppress("MagicNumber")
851+
private val WaveformData = (0..10).map {
852+
listOf(0.5f, 0.8f, 0.3f, 0.6f, 0.4f, 0.7f, 0.2f, 0.9f, 0.1f)
853+
}.flatten()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.chat.android.compose.ui.messages.composer.internal
18+
19+
import app.cash.paparazzi.DeviceConfig
20+
import app.cash.paparazzi.Paparazzi
21+
import io.getstream.chat.android.compose.ui.SnapshotTest
22+
import org.junit.Rule
23+
import org.junit.Test
24+
25+
internal class DefaultMessageComposerRecordingContentTest : SnapshotTest {
26+
27+
@get:Rule
28+
override val paparazzi = Paparazzi(deviceConfig = DeviceConfig.PIXEL_2)
29+
30+
@Test
31+
fun `recording content hold`() {
32+
snapshotWithDarkMode {
33+
MessageComposerRecordingContentHold()
34+
}
35+
}
36+
37+
@Test
38+
fun `recording content lock`() {
39+
snapshotWithDarkMode {
40+
MessageComposerRecordingContentLock()
41+
}
42+
}
43+
44+
@Test
45+
fun `recording content overview`() {
46+
snapshotWithDarkMode {
47+
MessageComposerRecordingContentOverview()
48+
}
49+
}
50+
}
12.8 KB
Loading
23.8 KB
Loading
19 KB
Loading

0 commit comments

Comments
 (0)