Skip to content

Commit 29a5e5a

Browse files
committed
Use faded marquee text in long press menu header
1 parent ad27e7f commit 29a5e5a

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.content.Context
77
import android.content.res.Configuration
88
import android.view.ViewGroup
99
import android.view.ViewGroup.LayoutParams
10-
import androidx.compose.foundation.basicMarquee
1110
import androidx.compose.foundation.clickable
1211
import androidx.compose.foundation.isSystemInDarkTheme
1312
import androidx.compose.foundation.layout.Arrangement
@@ -75,6 +74,7 @@ import org.schabi.newpipe.ui.theme.AppTheme
7574
import org.schabi.newpipe.ui.theme.customColors
7675
import org.schabi.newpipe.util.Either
7776
import org.schabi.newpipe.util.Localization
77+
import org.schabi.newpipe.util.text.fadedMarquee
7878
import java.time.OffsetDateTime
7979

8080
fun openLongPressMenuInActivity(
@@ -356,19 +356,15 @@ fun LongPressMenuHeader(
356356
}
357357

358358
Column(
359-
modifier = Modifier.padding(vertical = 12.dp, horizontal = 12.dp),
359+
modifier = Modifier.padding(vertical = 12.dp),
360360
) {
361-
val marquee = Modifier.basicMarquee(
362-
// wait some time before starting animations, to not distract the user
363-
initialDelayMillis = 4000,
364-
iterations = Int.MAX_VALUE
365-
)
366-
367361
Text(
368362
text = item.title,
369363
style = MaterialTheme.typography.titleMedium,
370364
maxLines = 1,
371-
modifier = marquee,
365+
modifier = Modifier
366+
.fillMaxWidth()
367+
.fadedMarquee(edgeWidth = 12.dp),
372368
)
373369

374370
val subtitle = getSubtitleAnnotatedString(
@@ -389,7 +385,7 @@ fun LongPressMenuHeader(
389385
Modifier.clickable(onClick = onUploaderClick)
390386
}
391387
.fillMaxWidth()
392-
.then(marquee)
388+
.fadedMarquee(edgeWidth = 12.dp)
393389
)
394390
}
395391
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.schabi.newpipe.util.text
2+
3+
import androidx.compose.foundation.MarqueeSpacing
4+
import androidx.compose.foundation.basicMarquee
5+
import androidx.compose.foundation.layout.padding
6+
import androidx.compose.ui.Modifier
7+
import androidx.compose.ui.draw.drawWithContent
8+
import androidx.compose.ui.geometry.Offset
9+
import androidx.compose.ui.geometry.Size
10+
import androidx.compose.ui.graphics.BlendMode
11+
import androidx.compose.ui.graphics.Brush
12+
import androidx.compose.ui.graphics.Color
13+
import androidx.compose.ui.graphics.CompositingStrategy
14+
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
15+
import androidx.compose.ui.graphics.graphicsLayer
16+
import androidx.compose.ui.unit.Dp
17+
18+
/**
19+
* Note: the values in [basicMarquee] are hardcoded, but feel free to expose them as parameters
20+
* in case that will be needed in the future.
21+
*
22+
* Taken from sample [androidx.compose.foundation.samples.BasicMarqueeWithFadedEdgesSample].
23+
*/
24+
fun Modifier.fadedMarquee(edgeWidth: Dp): Modifier {
25+
fun ContentDrawScope.drawFadedEdge(leftEdge: Boolean) {
26+
val edgeWidthPx = edgeWidth.toPx()
27+
drawRect(
28+
topLeft = Offset(if (leftEdge) 0f else size.width - edgeWidthPx, 0f),
29+
size = Size(edgeWidthPx, size.height),
30+
brush = Brush.horizontalGradient(
31+
colors = listOf(Color.Transparent, Color.Black),
32+
startX = if (leftEdge) 0f else size.width,
33+
endX = if (leftEdge) edgeWidthPx else size.width - edgeWidthPx
34+
),
35+
blendMode = BlendMode.DstIn
36+
)
37+
}
38+
39+
return this
40+
.graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
41+
.drawWithContent {
42+
drawContent()
43+
drawFadedEdge(leftEdge = true)
44+
drawFadedEdge(leftEdge = false)
45+
}
46+
.basicMarquee(
47+
repeatDelayMillis = 2000,
48+
// wait some time before starting animations, to not distract the user
49+
initialDelayMillis = 4000,
50+
iterations = Int.MAX_VALUE,
51+
spacing = MarqueeSpacing(edgeWidth)
52+
)
53+
.padding(start = edgeWidth)
54+
}

0 commit comments

Comments
 (0)