@@ -31,11 +31,9 @@ import androidx.compose.foundation.background
3131import androidx.compose.foundation.layout.Box
3232import androidx.compose.foundation.layout.Column
3333import androidx.compose.foundation.layout.Row
34- import androidx.compose.foundation.layout.aspectRatio
3534import androidx.compose.foundation.layout.fillMaxSize
3635import androidx.compose.foundation.layout.fillMaxWidth
3736import androidx.compose.foundation.layout.height
38- import androidx.compose.foundation.layout.offset
3937import androidx.compose.foundation.layout.padding
4038import androidx.compose.foundation.layout.wrapContentSize
4139import androidx.compose.foundation.layout.wrapContentWidth
@@ -62,7 +60,6 @@ import androidx.compose.ui.text.style.TextAlign
6260import androidx.compose.ui.text.style.TextOverflow
6361import androidx.compose.ui.tooling.preview.Preview
6462import androidx.compose.ui.unit.Dp
65- import androidx.compose.ui.unit.IntOffset
6663import androidx.compose.ui.unit.dp
6764import androidx.media3.common.util.UnstableApi
6865import net.newpipe.newplayer.R
@@ -92,8 +89,11 @@ internal fun ThumbPreview(
9289
9390 Column (modifier = modifier) {
9491 ThumbTextPreview (
95- modifier = Modifier , uiState = uiState, thumbSize = thumbSize,
96- startOffset = additionalStartPaddingPxls, endOffset = additionalEndPaddingPxls
92+ modifier = Modifier ,
93+ uiState = uiState,
94+ thumbSize = thumbSize,
95+ startOffset = additionalStartPaddingPxls,
96+ endOffset = additionalEndPaddingPxls
9797 )
9898
9999 ThumbImagePreview (
@@ -119,49 +119,30 @@ private fun ThumbTextPreview(
119119
120120 val textHeight = 30 .dp
121121
122- var sliderBoxWidth by remember {
123- mutableIntStateOf(- 1 )
124- }
125-
126- Box (
122+ AnimatedVisibility (
127123 modifier = modifier
128124 .fillMaxWidth()
129- .height((2 * PREVIEW_BOX_PADDING ).dp + textHeight)
130- .onGloballyPositioned { rect ->
131- sliderBoxWidth = rect.size.width
132- }) {
125+ .height((2 * PREVIEW_BOX_PADDING ).dp + textHeight),
126+ visible = uiState.seekPreviewVisible && (uiState.currentSeekPreviewText ? : " " ) != " " ,
127+ enter = PREVIEW_FADE_IN ,
128+ exit = PREVIEW_FADE_OUT
129+ ) {
133130
134- AnimatedVisibility (
135- visible = uiState.seekPreviewVisible && (uiState.currentSeekPreviewText ? : " " ) != " " ,
136- enter = PREVIEW_FADE_IN ,
137- exit = PREVIEW_FADE_OUT
131+ PlaceRelativeToThumbSliderLayout (
132+ Modifier , uiState, thumbSize, startOffset = startOffset, endOffset = endOffset
138133 ) {
139- Box (
140- modifier = Modifier
141- .fillMaxSize()
142- .background(Color .Yellow )
143- ) {
144-
145- PlaceRelativeToThumbSliderLayout (
146- Modifier ,
147- uiState,
148- thumbSize,
149- startOffset = startOffset,
150- endOffset = endOffset
151- ) {
152- Text (
153- text = uiState.currentSeekPreviewText ? : " " ,
154- textAlign = TextAlign .Center ,
155- style = MaterialTheme .typography.bodyMedium,
156- overflow = TextOverflow .Ellipsis ,
157- maxLines = 2 ,
158- )
159- }
160- }
134+ Text (
135+ text = uiState.currentSeekPreviewText ? : " " ,
136+ textAlign = TextAlign .Center ,
137+ style = MaterialTheme .typography.bodyMedium,
138+ overflow = TextOverflow .Ellipsis ,
139+ maxLines = 2 ,
140+ )
161141 }
162142 }
163143}
164144
145+
165146@OptIn(UnstableApi ::class )
166147@Composable
167148private fun ThumbImagePreview (
@@ -173,70 +154,53 @@ private fun ThumbImagePreview(
173154 previewHeight : Dp = 60.dp,
174155) {
175156
176- var sliderBoxWidth by remember {
177- mutableIntStateOf(- 1 )
178- }
179-
180- Box (
181- modifier = modifier
157+ AnimatedVisibility (
158+ modifier = Modifier
182159 .fillMaxWidth()
183- .height((2 * PREVIEW_BOX_PADDING ).dp + previewHeight)
184- .onGloballyPositioned { rect ->
185- sliderBoxWidth = rect.size.width
186- }) {
187- AnimatedVisibility (
188- visible = uiState.seekPreviewVisible && uiState.currentSeekPreviewThumbnail != null ,
189- enter = PREVIEW_FADE_IN ,
190- exit = PREVIEW_FADE_OUT
160+ .height(previewHeight + PREVIEW_BOX_PADDING .dp * 2 ),
161+ visible = uiState.seekPreviewVisible && uiState.currentSeekPreviewThumbnail != null ,
162+ enter = PREVIEW_FADE_IN ,
163+ exit = PREVIEW_FADE_OUT
164+ ) {
165+ // Together with the getHeight() function this Box ensures that the thumbnail
166+ // does not collapse and glitch during enter and exit animation.
167+
168+ // this allows the current thumbnail to remain when animated visibility is being hidden
169+ var lastAvailableImage by remember {
170+ mutableStateOf(uiState.currentSeekPreviewThumbnail)
171+ }
172+ if (uiState.currentSeekPreviewThumbnail != null ) {
173+ lastAvailableImage = uiState.currentSeekPreviewThumbnail
174+ }
175+
176+ PlaceRelativeToThumbSliderLayout (
177+ Modifier .wrapContentSize(),
178+ uiState = uiState,
179+ thumbSize = thumbSize,
180+ startOffset = additionalStartPaddingPxls,
181+ endOffset = additionalEndPaddingPxls
191182 ) {
192- // Together with the getHeight() function this Box ensures that the thumbnail
193- // does not collapse and glitch during enter and exit animation.
194183 Box (
195- Modifier
196- .fillMaxSize()
197- .background(Color .Red )
184+ modifier = Modifier .wrapContentSize()
198185 ) {
199- // this allows the current thumbnail to remain when animated visibility is being hidden
200- var lastAvailableImage by remember {
201- mutableStateOf(uiState.currentSeekPreviewThumbnail)
202- }
203- if (uiState.currentSeekPreviewThumbnail != null ) {
204- lastAvailableImage = uiState.currentSeekPreviewThumbnail
205- }
206-
207- PlaceRelativeToThumbSliderLayout (
208- Modifier ,
209- uiState = uiState,
210- thumbSize = thumbSize,
211- startOffset = additionalStartPaddingPxls,
212- endOffset = additionalEndPaddingPxls
186+ Card (
187+ modifier = Modifier
188+ .padding(PREVIEW_BOX_PADDING .dp)
189+ .height(previewHeight)
190+ .wrapContentWidth(),
191+ elevation = CardDefaults .cardElevation(PREVIEW_BOX_PADDING .dp)
213192 ) {
214- Box (
215- modifier = Modifier
216- .wrapContentSize()
217- ) {
218- Card (
219- modifier = Modifier
220- .padding(PREVIEW_BOX_PADDING .dp)
221- .height(previewHeight)
222- .wrapContentWidth(),
223- elevation = CardDefaults .cardElevation(PREVIEW_BOX_PADDING .dp)
224- ) {
225- lastAvailableImage?.let {
226- Image (
227- modifier = Modifier .fillMaxSize(),
228- bitmap = it,
229- contentDescription = stringResource(id = R .string.seek_thumb_preview)
230- )
231- }
232- }
193+ lastAvailableImage?.let {
194+ Image (
195+ modifier = Modifier .fillMaxSize(),
196+ bitmap = it,
197+ contentDescription = stringResource(id = R .string.seek_thumb_preview)
198+ )
233199 }
234200 }
235-
236201 }
237202 }
238203
239-
240204 /* This is a little helper block that helps place the thumbnail correctly relative to the
241205 thumb of the seeker. This is only there for debug reasons.
242206 Surface(
@@ -276,9 +240,7 @@ private fun ThumbPreviewPreview() {
276240 seekPreviewVisible = thumbDown,
277241 currentSeekPreviewThumbnail = previewThumbnail.asImageBitmap(),
278242 currentSeekPreviewText = Chapter (
279- 0 ,
280- " What a wonderfull chapter" ,
281- null
243+ 0 , " What a wonderfull chapter" , null
282244 ).chapterTitle
283245 ),
284246 additionalStartPaddingPxls = startOffset,
0 commit comments