Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Audio message slider style #WPB-11384 #3491

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ package com.wire.android.ui.home.conversations.model.messagetypes.audio

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
Expand All @@ -43,6 +46,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.wire.android.R
import com.wire.android.media.audiomessage.AudioMediaPlayingState
Expand Down Expand Up @@ -157,14 +161,10 @@ private fun SuccessfulAudioMessage(
onButtonClicked = onPlayButtonClick
)

Slider(
value = audioDuration.currentPositionInMs.toFloat(),
onValueChange = onSliderPositionChange,
valueRange = 0f..if (totalTimeInMs is AudioState.TotalTimeInMs.Known) totalTimeInMs.value.toFloat() else 0f,
colors = SliderDefaults.colors(
inactiveTrackColor = colorsScheme().secondaryButtonDisabledOutline
),
modifier = Modifier.weight(1f)
AudioMessageSlider(
audioDuration = audioDuration,
totalTimeInMs = totalTimeInMs,
onSliderPositionChange = onSliderPositionChange
)

if (audioMediaPlayingState is AudioMediaPlayingState.Fetching) {
Expand All @@ -182,6 +182,49 @@ private fun SuccessfulAudioMessage(
}
}

/**
* Material3 version 1.3.0 introduced several modifications to the Slider component.
* These changes may require adjustments to maintain the desired appearance and behavior in your app:
* - Thumb size changed to 4dp x 44dp - changed back to old 20dp x 20dp.
* - Thumb requires interactionSource - it must be different than Slider to not update thumb appearance during drag.
* - Track now draws stop indicator by default - turned off.
* - Track adds thumbTrackGapSize - set back to 0dp.
* - Track has different height than previously - changed back to old 4.dp.
*/
@Composable
@OptIn(ExperimentalMaterial3Api::class)
private fun RowScope.AudioMessageSlider(
audioDuration: AudioDuration,
totalTimeInMs: AudioState.TotalTimeInMs,
onSliderPositionChange: (Float) -> Unit,
) {
Slider(
value = audioDuration.currentPositionInMs.toFloat(),
onValueChange = onSliderPositionChange,
valueRange = 0f..if (totalTimeInMs is AudioState.TotalTimeInMs.Known) totalTimeInMs.value.toFloat() else 0f,
thumb = {
SliderDefaults.Thumb(
interactionSource = remember { MutableInteractionSource() },
thumbSize = DpSize(dimensions().spacing20x, dimensions().spacing20x)
)
},
track = { sliderState ->
SliderDefaults.Track(
modifier = Modifier.height(dimensions().spacing4x),
sliderState = sliderState,
thumbTrackGapSize = dimensions().spacing0x,
drawStopIndicator = {
// nop we do not want to draw stop indicator at all.
}
)
},
colors = SliderDefaults.colors(
inactiveTrackColor = colorsScheme().secondaryButtonDisabledOutline
),
modifier = Modifier.weight(1f)
)
}

@Composable
private fun FailedAudioMessage() {
var audioNotAvailableDialog by remember { mutableStateOf(false) }
Expand Down
Loading