diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7828175d..cbb64686 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,11 +6,11 @@ plugins { } android { - compileSdk = 34 + compileSdk = 35 defaultConfig { applicationId = "com.jeluchu.composer" minSdk = 22 - targetSdk = 34 + targetSdk = 35 versionCode = 1 versionName = "1.0.0" } diff --git a/app/src/main/kotlin/com/jeluchu/composer/core/ui/navigation/NavGraphBuilderExtensions.kt b/app/src/main/kotlin/com/jeluchu/composer/core/ui/navigation/NavGraphBuilderExtensions.kt index 31b17ada..33f89c30 100644 --- a/app/src/main/kotlin/com/jeluchu/composer/core/ui/navigation/NavGraphBuilderExtensions.kt +++ b/app/src/main/kotlin/com/jeluchu/composer/core/ui/navigation/NavGraphBuilderExtensions.kt @@ -149,6 +149,10 @@ fun NavGraphBuilder.toolbarsNav(nav: Destinations) { composable(Feature.CENTER_TOOBARS.nav) { CenterToolbarActionsPreview() } + + composable(Feature.LARGE_TOOBARS.nav) { + // Soon + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 80575f7f..a1b90d03 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] -jchucomponents = "2.0.0-alpha15" +jchucomponents = "2.0.0-alpha17" agp = "8.5.2" kotlin = "2.0.0" dokka = "1.9.20" -androidx-activity = "1.9.1" -androidx-compose = "1.6.8" -androidx-lifecycle = "2.8.4" -androidx-navigation = "2.7.7" +androidx-activity = "1.9.2" +androidx-compose = "1.7.2" +androidx-lifecycle = "2.8.6" +androidx-navigation = "2.8.1" com-squareup-okhttp3 = "4.12.0" com-squareup-retrofit2 = "2.11.0" coil-kt = "2.6.0" @@ -23,7 +23,7 @@ androidx-compose-foundation = { module = "androidx.compose.foundation:foundation androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout", version.ref = "androidx-compose" } androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose" } androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "androidx-compose" } -androidx-compose-material3 = "androidx.compose.material3:material3:1.2.1" +androidx-compose-material3 = "androidx.compose.material3:material3:1.3.0" androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "androidx-compose" } androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose" } androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" } diff --git a/jchucomponents-core/build.gradle.kts b/jchucomponents-core/build.gradle.kts index 1a877bf9..c896e087 100644 --- a/jchucomponents-core/build.gradle.kts +++ b/jchucomponents-core/build.gradle.kts @@ -7,11 +7,11 @@ plugins { android { namespace = "com.jeluchu.jchucomponents.core" - compileSdk = 34 + compileSdk = 35 defaultConfig { minSdk = 21 - targetSdk = 34 + targetSdk = 35 proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/jchucomponents-ktx/build.gradle.kts b/jchucomponents-ktx/build.gradle.kts index e45cb4fa..9fc61a67 100644 --- a/jchucomponents-ktx/build.gradle.kts +++ b/jchucomponents-ktx/build.gradle.kts @@ -7,11 +7,11 @@ plugins { android { namespace = "com.jeluchu.jchucomponents.ktx" - compileSdk = 34 + compileSdk = 35 defaultConfig { minSdk = 21 - targetSdk = 34 + targetSdk = 35 proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/bitmaps/BitmapExtensions.kt b/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/bitmaps/BitmapExtensions.kt index 1ff3631b..deee7b9b 100644 --- a/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/bitmaps/BitmapExtensions.kt +++ b/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/bitmaps/BitmapExtensions.kt @@ -70,4 +70,7 @@ fun Bitmap.scaleBitmap(maxBytes: Long = SIZE_2MB_BYTES.toLong()): Bitmap? { val newWidthPx = floor(currentWidth * scaleFactor).toInt() val newHeightPx = floor(currentHeight * scaleFactor).toInt() return Bitmap.createScaledBitmap(this, newWidthPx, newHeightPx, true) -} \ No newline at end of file +} + +internal val Bitmap.safeConfig: Bitmap.Config + get() = config ?: Bitmap.Config.ARGB_8888 diff --git a/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/numbers/IntExtensions.kt b/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/numbers/IntExtensions.kt index 16715578..8063da08 100644 --- a/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/numbers/IntExtensions.kt +++ b/jchucomponents-ktx/src/main/kotlin/com/jeluchu/jchucomponents/ktx/numbers/IntExtensions.kt @@ -18,6 +18,9 @@ fun Int?.orEmpty(defaultValue: Int = Int.empty()) = this ?: defaultValue fun Int.isNotEmpty() = this != Int.empty() fun Long.bytesToMeg(): String = (this / (1024L * 1024L)).toString() +fun Double.Companion.empty() = 0.0 +fun Double?.orEmpty(defaultValue: Double = Double.empty()): Double = this ?: defaultValue + fun Float.Companion.empty() = 0f fun Float?.orEmpty(defaultValue: Float = Float.empty()): Float = this ?: defaultValue diff --git a/jchucomponents-pay/build.gradle.kts b/jchucomponents-pay/build.gradle.kts index 4b60007c..1e65a99f 100644 --- a/jchucomponents-pay/build.gradle.kts +++ b/jchucomponents-pay/build.gradle.kts @@ -7,11 +7,11 @@ plugins { android { namespace = "com.jeluchu.jchucomponents.pay" - compileSdk = 34 + compileSdk = 35 defaultConfig { minSdk = 21 - targetSdk = 34 + targetSdk = 35 proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/jchucomponents-prefs/build.gradle.kts b/jchucomponents-prefs/build.gradle.kts index e2fd6a51..94139d87 100644 --- a/jchucomponents-prefs/build.gradle.kts +++ b/jchucomponents-prefs/build.gradle.kts @@ -8,11 +8,11 @@ plugins { android { namespace = "com.jeluchu.jchucomponents.prefs" - compileSdk = 34 + compileSdk = 35 defaultConfig { minSdk = 21 - targetSdk = 34 + targetSdk = 35 proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/jchucomponents-qr/build.gradle.kts b/jchucomponents-qr/build.gradle.kts index cc94c283..c2e1c2d7 100644 --- a/jchucomponents-qr/build.gradle.kts +++ b/jchucomponents-qr/build.gradle.kts @@ -7,11 +7,11 @@ plugins { android { namespace = "com.jeluchu.jchucomponents.qr" - compileSdk = 34 + compileSdk = 35 defaultConfig { minSdk = 21 - targetSdk = 34 + targetSdk = 35 proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/jchucomponents-ui/build.gradle.kts b/jchucomponents-ui/build.gradle.kts index 9dcc71ba..3e220944 100644 --- a/jchucomponents-ui/build.gradle.kts +++ b/jchucomponents-ui/build.gradle.kts @@ -8,11 +8,11 @@ plugins { android { namespace = "com.jeluchu.jchucomponents.ui" - compileSdk = 34 + compileSdk = 35 defaultConfig { minSdk = 21 - targetSdk = 34 + targetSdk = 35 proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/transformations/BlurTransformation.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/transformations/BlurTransformation.kt index 3a0b7b5e..307828e6 100644 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/transformations/BlurTransformation.kt +++ b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/transformations/BlurTransformation.kt @@ -37,7 +37,7 @@ private suspend fun Bitmap.blur( val width = (sentBitmap.width * scale).roundToInt() val height = (sentBitmap.height * scale).roundToInt() sentBitmap = Bitmap.createScaledBitmap(sentBitmap, width, height, false) - val bitmap = sentBitmap.copy(sentBitmap.config, true) + val bitmap = sentBitmap.copy(sentBitmap.safeConfig, true) if (radius < 1) { return@withContext null } @@ -242,4 +242,7 @@ private suspend fun Bitmap.blur( bitmap.setPixels(pix, 0, w, 0, 0, w, h) sentBitmap.recycle() return@withContext bitmap -} \ No newline at end of file +} + +internal val Bitmap.safeConfig: Bitmap.Config + get() = config ?: Bitmap.Config.ARGB_8888 diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/progress/LinearProgressbar.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/progress/LinearProgressbar.kt index 561450bc..44c99e9c 100644 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/progress/LinearProgressbar.kt +++ b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/progress/LinearProgressbar.kt @@ -44,7 +44,6 @@ import com.jeluchu.jchucomponents.ui.extensions.toPainter import com.jeluchu.jchucomponents.ktx.strings.empty import com.jeluchu.jchucomponents.ui.R import com.jeluchu.jchucomponents.ui.extensions.modifier.cornerRadius -import com.jeluchu.jchucomponents.ui.foundation.text.AutoSizeText import com.jeluchu.jchucomponents.ui.runtime.remember.rememberMutableStateOf import com.jeluchu.jchucomponents.ui.themes.cosmicLatte import com.jeluchu.jchucomponents.ui.themes.darkGreen @@ -148,14 +147,13 @@ fun LinearProgressbar( contentColor = if (enabled) linearProgressCounter.content else linearProgressCounter.disabledContent ) { - AutoSizeText( + Text( modifier = Modifier.padding( vertical = 2.dp, horizontal = 8.dp ), text = if (enabled) "${numberTimes.toInt()}/${maxNumber.toInt()}" else "- / -", style = style, - maxTextSize = 14.sp, textAlign = TextAlign.Center, ) } @@ -260,14 +258,13 @@ fun LinearProgressbar( contentColor = if (enabled) linearProgressCounter.content else linearProgressCounter.disabledContent ) { - AutoSizeText( + Text( modifier = Modifier.padding( vertical = 2.dp, horizontal = 8.dp ), text = if (enabled) "${numberTimes.toInt()}/${maxNumber.toInt()}" else "- / -", style = style, - maxTextSize = 14.sp, textAlign = TextAlign.Center, ) } @@ -275,7 +272,7 @@ fun LinearProgressbar( } @Immutable -class LinearProgressCustom constructor( +class LinearProgressCustom( val disabledIndicator: Color = milky.copy(.2f), val backgroundIndicator: Color = Color.LightGray.copy(.3f), val foregroundIndicator: Color = milky, diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/textfields/CountTextField.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/textfields/CountTextField.kt index dcd9fb67..2a92ef96 100644 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/textfields/CountTextField.kt +++ b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/textfields/CountTextField.kt @@ -18,6 +18,7 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.Text import androidx.compose.material3.TextField +import androidx.compose.material3.TextFieldColors import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable @@ -72,8 +73,8 @@ fun CountTextField( TextField( modifier = Modifier.fillMaxWidth(), value = textState, - colors = TextFieldDefaults.textFieldColors( - containerColor = countField.backgroundColor, + colors = TextFieldDefaults.colors( + focusedContainerColor = countField.backgroundColor, cursorColor = countField.cursorColor, disabledLabelColor = countField.disabledLabelColor, focusedIndicatorColor = Color.Transparent, diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/toolbars/Toolbar.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/toolbars/Toolbar.kt index 6fd2e24d..584c2a7d 100644 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/toolbars/Toolbar.kt +++ b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/toolbars/Toolbar.kt @@ -131,7 +131,7 @@ fun Toolbar( maxLines = 1 ) }, - colors = TopAppBarDefaults.smallTopAppBarColors( + colors = TopAppBarDefaults.topAppBarColors( containerColor = topBarSettings.backgroundColor ), navigationIcon = { diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/AutoSizeText.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/AutoSizeText.kt deleted file mode 100644 index 9ce66cac..00000000 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/AutoSizeText.kt +++ /dev/null @@ -1,298 +0,0 @@ -package com.jeluchu.jchucomponents.ui.foundation.text - -import androidx.compose.foundation.layout.BoxWithConstraints -import androidx.compose.foundation.layout.BoxWithConstraintsScope -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.text.InlineTextContent -import androidx.compose.foundation.text.InternalFoundationTextApi -import androidx.compose.foundation.text.TextDelegate -import androidx.compose.material3.LocalTextStyle -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.Immutable -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.platform.LocalFontFamilyResolver -import androidx.compose.ui.platform.LocalLayoutDirection -import androidx.compose.ui.text.AnnotatedString -import androidx.compose.ui.text.TextLayoutResult -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontStyle -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextDecoration -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.Density -import androidx.compose.ui.unit.TextUnit -import androidx.compose.ui.unit.TextUnitType -import androidx.compose.ui.unit.isUnspecified -import androidx.compose.ui.unit.min -import androidx.compose.ui.unit.sp -import kotlin.math.ceil -import kotlin.math.floor -import kotlin.reflect.KProperty - -/** - * Composable function that automatically adjusts the size of text to fit within the given constraints. - * - * Features: - * 1. Best performance: Utilizes a dichotomous binary search algorithm to quickly find the optimal text size without unnecessary iterations. - * 2. Text alignment support: Supports 6 possible alignment values through the Alignment interface. - * 3. Material Design 3 support. - * 4. Font scaling support: Changing the font scale by the user does not affect the visual rendering result. - * - * Limitation: - * 1. Does not work well when maxLine is greater than 1. - * 2. Does not work well when changing lineHeight - * - * @param text The text to be displayed. - * @param modifier The modifier for the text composable. - * @param suggestedFontSizes The suggested font sizes to choose from. - * @param minTextSize The minimum text size allowed. - * @param maxTextSize The maximum text size allowed. - * @param stepGranularityTextSize The step size for adjusting the text size. - * @param textAlignment The alignment of the text within its container. - * @param color The color of the text. - * @param fontStyle The font style of the text. - * @param fontWeight The font weight of the text. - * @param fontFamily The font family of the text. - * @param letterSpacing The letter spacing of the text. - * @param textDecoration The text decoration style. - * @param textAlign The alignment of the text within the lines of the paragraph. - * @param lineHeight The line height of the text. - * @param softWrap Whether the text should break at soft line breaks. - * @param maxLines The maximum number of lines for the text. - * @param minLines The minimum number of lines for the text. - * @param onTextLayout Callback invoked when the text layout is available. - * @param style The base style to apply to the text. - * @author Reda El Madini - For support, contact gladiatorkilo@gmail.com - */ -@Composable -fun AutoSizeText( - text: String, - modifier: Modifier = Modifier, - suggestedFontSizes: ImmutableWrapper> = emptyList().toImmutableWrapper(), - minTextSize: TextUnit = TextUnit.Unspecified, - maxTextSize: TextUnit = TextUnit.Unspecified, - stepGranularityTextSize: TextUnit = TextUnit.Unspecified, - textAlignment: Alignment = Alignment.Center, - color: Color = Color.Unspecified, - fontStyle: FontStyle? = null, - fontWeight: FontWeight? = null, - fontFamily: FontFamily? = null, - letterSpacing: TextUnit = TextUnit.Unspecified, - textDecoration: TextDecoration? = null, - textAlign: TextAlign? = null, - lineHeight: TextUnit = TextUnit.Unspecified, - softWrap: Boolean = true, - maxLines: Int = 1, - minLines: Int = 1, - onTextLayout: (TextLayoutResult) -> Unit = {}, - style: TextStyle = LocalTextStyle.current, -) { - AutoSizeText( - text = AnnotatedString(text), - modifier = modifier, - suggestedFontSizes = suggestedFontSizes, - minTextSize = minTextSize, - maxTextSize = maxTextSize, - stepGranularityTextSize = stepGranularityTextSize, - textAlignment = textAlignment, - color = color, - fontStyle = fontStyle, - fontWeight = fontWeight, - fontFamily = fontFamily, - letterSpacing = letterSpacing, - textDecoration = textDecoration, - textAlign = textAlign, - lineHeight = lineHeight, - softWrap = softWrap, - maxLines = maxLines, - minLines = minLines, - onTextLayout = onTextLayout, - style = style, - ) -} - -@Composable -fun AutoSizeText( - text: AnnotatedString, - modifier: Modifier = Modifier, - suggestedFontSizes: ImmutableWrapper> = emptyList().toImmutableWrapper(), - minTextSize: TextUnit = TextUnit.Unspecified, - maxTextSize: TextUnit = TextUnit.Unspecified, - stepGranularityTextSize: TextUnit = TextUnit.Unspecified, - textAlignment: Alignment = Alignment.Center, - color: Color = Color.Unspecified, - fontStyle: FontStyle? = null, - fontWeight: FontWeight? = null, - fontFamily: FontFamily? = null, - letterSpacing: TextUnit = TextUnit.Unspecified, - textDecoration: TextDecoration? = null, - textAlign: TextAlign? = null, - lineHeight: TextUnit = TextUnit.Unspecified, - softWrap: Boolean = true, - maxLines: Int = 1, - minLines: Int = 1, - inlineContent: ImmutableWrapper> = mapOf().toImmutableWrapper(), - onTextLayout: (TextLayoutResult) -> Unit = {}, - style: TextStyle = LocalTextStyle.current, -) { - val permittedTextUnitTypes = remember { listOf(TextUnitType.Unspecified, TextUnitType.Sp) } - check(minTextSize.type in permittedTextUnitTypes) - check(maxTextSize.type in permittedTextUnitTypes) - check(stepGranularityTextSize.type in permittedTextUnitTypes) - - val density = LocalDensity.current.density - // Change font scale to 1 - CompositionLocalProvider(LocalDensity provides Density(density = density, fontScale = 1F)) { - BoxWithConstraints( - modifier = modifier, - contentAlignment = textAlignment, - ) { - // (1 / density).sp represents 1px when font scale equals 1 - val step = remember(stepGranularityTextSize) { - (1 / density).let { - if (stepGranularityTextSize.isUnspecified) - it.sp - else - stepGranularityTextSize.value.coerceAtLeast(it).sp - } - } - - val max = remember(maxWidth, maxHeight, maxTextSize) { - min(maxWidth, maxHeight).value.let { - if (maxTextSize.isUnspecified) - it.sp - else - maxTextSize.value.coerceAtMost(it).sp - } - } - - val min = remember(minTextSize, step, max) { - if (minTextSize.isUnspecified) - step - else - minTextSize.value.coerceIn( - minimumValue = step.value, - maximumValue = max.value - ).sp - } - - val possibleFontSizes = remember(suggestedFontSizes, min, max, step) { - if (suggestedFontSizes.value.isEmpty()) { - val firstIndex = ceil(min.value / step.value).toInt() - val lastIndex = floor(max.value / step.value).toInt() - MutableList(size = (lastIndex - firstIndex) + 1) { index -> - step * (lastIndex - index) - } - } else - suggestedFontSizes.value.filter { - it.isSp && it.value in min.value..max.value - }.sortedByDescending { - it.value - } - } - - var combinedTextStyle = LocalTextStyle.current + style - - if (possibleFontSizes.isNotEmpty()) { - // Dichotomous binary search - var low = 0 - var high = possibleFontSizes.lastIndex - while (low <= high) { - val mid = low + (high - low) / 2 - val shouldShrink = shouldShrink( - text = text, - textStyle = combinedTextStyle.copy(fontSize = possibleFontSizes[mid]), - maxLines = maxLines, - softWrap = softWrap, - ) - - if (shouldShrink) low = mid + 1 - else high = mid - 1 - } - combinedTextStyle = combinedTextStyle.copy( - fontSize = possibleFontSizes[low.coerceIn(possibleFontSizes.indices)] - ) - } - - Text( - text = text, - modifier = Modifier, - color = color, - fontSize = TextUnit.Unspecified, - fontStyle = fontStyle, - fontWeight = fontWeight, - fontFamily = fontFamily, - letterSpacing = letterSpacing, - textDecoration = textDecoration, - textAlign = textAlign, - lineHeight = lineHeight, - overflow = TextOverflow.Clip, - softWrap = softWrap, - maxLines = maxLines, - minLines = minLines, - inlineContent = inlineContent.value, - onTextLayout = onTextLayout, - style = combinedTextStyle, - ) - } - } -} - -@OptIn(InternalFoundationTextApi::class) -@Composable -private fun BoxWithConstraintsScope.shouldShrink( - text: AnnotatedString, - textStyle: TextStyle, - maxLines: Int, - softWrap: Boolean, -): Boolean { - val textDelegate = TextDelegate( - text = text, - style = textStyle, - maxLines = maxLines, - softWrap = softWrap, - overflow = TextOverflow.Clip, - density = LocalDensity.current, - fontFamilyResolver = LocalFontFamilyResolver.current, - ) - - val textLayoutResult = textDelegate.layout( - constraints, - LocalLayoutDirection.current, - ) - - return textLayoutResult.hasVisualOverflow -} - -@Immutable -data class ImmutableWrapper(val value: T) - -fun T.toImmutableWrapper() = ImmutableWrapper(this) - -operator fun ImmutableWrapper.getValue(thisRef: Any?, property: KProperty<*>) = value - -@Preview(widthDp = 200, heightDp = 100) -@Preview(widthDp = 200, heightDp = 30) -@Preview(widthDp = 60, heightDp = 30) -@Composable -fun AutoSizeTextPreview() { - MaterialTheme { - Surface { - AutoSizeText( - text = "OvTracker App", - modifier = Modifier.fillMaxSize(), - ) - } - } -} \ No newline at end of file diff --git a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/MarqueeText.kt b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/MarqueeText.kt index 7e2a42a6..2fe7e41a 100644 --- a/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/MarqueeText.kt +++ b/jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/foundation/text/MarqueeText.kt @@ -13,10 +13,10 @@ import androidx.compose.animation.core.TargetBasedAnimation import androidx.compose.animation.core.VectorConverter import androidx.compose.animation.core.infiniteRepeatable import androidx.compose.animation.core.tween -import androidx.compose.foundation.DefaultMarqueeDelayMillis -import androidx.compose.foundation.DefaultMarqueeVelocity import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.MarqueeAnimationMode +import androidx.compose.foundation.MarqueeDefaults.RepeatDelayMillis +import androidx.compose.foundation.MarqueeDefaults.Velocity import androidx.compose.foundation.MarqueeSpacing import androidx.compose.foundation.background import androidx.compose.foundation.basicMarquee @@ -276,9 +276,9 @@ fun MarqueeText( iterations: Int = Int.MAX_VALUE, edgeWidthGradient: Dp = 10.dp, marqueeSpacing: MarqueeSpacing = MarqueeSpacing(30.dp), - delayMillis: Int = DefaultMarqueeDelayMillis, + delayMillis: Int = RepeatDelayMillis, animationMode: MarqueeAnimationMode = MarqueeAnimationMode.Immediately, - velocity: Dp = DefaultMarqueeVelocity, + velocity: Dp = Velocity, maxLines: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current @@ -295,7 +295,7 @@ fun MarqueeText( .basicMarquee( animationMode = animationMode, iterations = iterations, - delayMillis = delayMillis, + repeatDelayMillis = delayMillis, spacing = marqueeSpacing, velocity = velocity ), @@ -335,9 +335,9 @@ fun MarqueeText( iterations: Int = Int.MAX_VALUE, edgeWidthGradient: Dp = 10.dp, marqueeSpacing: MarqueeSpacing = MarqueeSpacing(30.dp), - delayMillis: Int = DefaultMarqueeDelayMillis, + delayMillis: Int = RepeatDelayMillis, animationMode: MarqueeAnimationMode = MarqueeAnimationMode.Immediately, - velocity: Dp = DefaultMarqueeVelocity, + velocity: Dp = Velocity, maxLines: Int = Int.MAX_VALUE, onTextLayout: (TextLayoutResult) -> Unit = {}, style: TextStyle = LocalTextStyle.current @@ -353,7 +353,7 @@ fun MarqueeText( .basicMarquee( animationMode = animationMode, iterations = iterations, - delayMillis = delayMillis, + repeatDelayMillis = delayMillis, spacing = marqueeSpacing, velocity = velocity ),