[go: nahoru, domu]

Make Platform[Span|Paragraph]Style.lerp top level function

This CLs makes the PlatformParagraphStyle.lerp and
PlatformSpanStyle.lerp regular top level functions to be consistent
with the remaining of lerp functions.

Test: ./gradlew compose:ui:ui-text:test
Test: ./gradlew compose:ui:ui-text:CAT
Test: Compile and run tests for Desktop

RelNote: "PlatformParagraphStyle.lerp and
PlatformSpanStyle.lerp functions are changed to be top level
functions"

Fixes: 228986072
Change-Id: I9a268d3012b3e215408b2715a73a153818facc20
diff --git a/compose/ui/ui-text/api/public_plus_experimental_current.txt b/compose/ui/ui-text/api/public_plus_experimental_current.txt
index 4e19c85..cdc10ae 100644
--- a/compose/ui/ui-text/api/public_plus_experimental_current.txt
+++ b/compose/ui/ui-text/api/public_plus_experimental_current.txt
@@ -5,6 +5,8 @@
   }
 
   public final class AndroidTextStyle_androidKt {
+    method @androidx.compose.ui.text.ExperimentalTextApi public static androidx.compose.ui.text.PlatformParagraphStyle lerp(androidx.compose.ui.text.PlatformParagraphStyle start, androidx.compose.ui.text.PlatformParagraphStyle stop, float fraction);
+    method @androidx.compose.ui.text.ExperimentalTextApi public static androidx.compose.ui.text.PlatformSpanStyle lerp(androidx.compose.ui.text.PlatformSpanStyle start, androidx.compose.ui.text.PlatformSpanStyle stop, float fraction);
   }
 
   @androidx.compose.runtime.Immutable public final class AnnotatedString implements java.lang.CharSequence {
@@ -285,7 +287,6 @@
   @androidx.compose.ui.text.ExperimentalTextApi public final class PlatformParagraphStyle {
     ctor @Deprecated public PlatformParagraphStyle(optional boolean includeFontPadding);
     method @Deprecated public boolean getIncludeFontPadding();
-    method public androidx.compose.ui.text.PlatformParagraphStyle lerp(androidx.compose.ui.text.PlatformParagraphStyle stop, float fraction);
     method public androidx.compose.ui.text.PlatformParagraphStyle merge(androidx.compose.ui.text.PlatformParagraphStyle? other);
     property @Deprecated public final boolean includeFontPadding;
     field public static final androidx.compose.ui.text.PlatformParagraphStyle.Companion Companion;
@@ -298,7 +299,6 @@
 
   @androidx.compose.ui.text.ExperimentalTextApi public final class PlatformSpanStyle {
     ctor public PlatformSpanStyle();
-    method public androidx.compose.ui.text.PlatformSpanStyle lerp(androidx.compose.ui.text.PlatformSpanStyle stop, float fraction);
     method public androidx.compose.ui.text.PlatformSpanStyle merge(androidx.compose.ui.text.PlatformSpanStyle? other);
     field public static final androidx.compose.ui.text.PlatformSpanStyle.Companion Companion;
   }
diff --git a/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/PlatformSpanStyleTest.kt b/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/PlatformSpanStyleTest.kt
index f60d59c..ae7baff 100644
--- a/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/PlatformSpanStyleTest.kt
+++ b/compose/ui/ui-text/src/androidAndroidTest/kotlin/androidx/compose/ui/text/PlatformSpanStyleTest.kt
@@ -64,7 +64,7 @@
         val style = PlatformSpanStyle()
         val otherStyle = PlatformSpanStyle()
 
-        assertThat(style.lerp(stop = otherStyle, 0.5f)).isSameInstanceAs(style)
+        assertThat(lerp(start = style, stop = otherStyle, 0.5f)).isSameInstanceAs(style)
     }
 
     @Test
diff --git a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/AndroidTextStyle.android.kt b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/AndroidTextStyle.android.kt
index 72001ea..e76a56b 100644
--- a/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/AndroidTextStyle.android.kt
+++ b/compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/AndroidTextStyle.android.kt
@@ -145,16 +145,6 @@
         // right now it is not needed to create a copy
         return other
     }
-
-    actual fun lerp(stop: PlatformParagraphStyle, fraction: Float): PlatformParagraphStyle {
-        return PlatformParagraphStyle(
-            includeFontPadding = lerpDiscrete(
-                includeFontPadding,
-                stop.includeFontPadding,
-                fraction
-            )
-        )
-    }
 }
 
 /**
@@ -170,10 +160,6 @@
         return this
     }
 
-    actual fun lerp(stop: PlatformSpanStyle, fraction: Float): PlatformSpanStyle {
-        return this
-    }
-
     override fun equals(other: Any?): Boolean {
         if (this === other) return true
         if (other !is PlatformSpanStyle) return false
@@ -189,3 +175,56 @@
         return "PlatformSpanStyle()"
     }
 }
+
+/**
+ * Interpolate between two PlatformParagraphStyle's.
+ *
+ * This will not work well if the styles don't set the same fields.
+ *
+ * The [fraction] argument represents position on the timeline, with 0.0 meaning
+ * that the interpolation has not started, returning [start] (or something
+ * equivalent to [start]), 1.0 meaning that the interpolation has finished,
+ * returning [stop] (or something equivalent to [stop]), and values in between
+ * meaning that the interpolation is at the relevant point on the timeline
+ * between [start] and [stop]. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
+ */
+@Suppress("DEPRECATION")
+@ExperimentalTextApi
+actual fun lerp(
+    start: PlatformParagraphStyle,
+    stop: PlatformParagraphStyle,
+    fraction: Float
+): PlatformParagraphStyle {
+    if (start.includeFontPadding == stop.includeFontPadding) return start
+
+    return PlatformParagraphStyle(
+        includeFontPadding = lerpDiscrete(
+            start.includeFontPadding,
+            stop.includeFontPadding,
+            fraction
+        )
+    )
+}
+
+/**
+ * Interpolate between two PlatformSpanStyle's.
+ *
+ * This will not work well if the styles don't set the same fields.
+ *
+ * The [fraction] argument represents position on the timeline, with 0.0 meaning
+ * that the interpolation has not started, returning [start] (or something
+ * equivalent to [start]), 1.0 meaning that the interpolation has finished,
+ * returning [stop] (or something equivalent to [stop]), and values in between
+ * meaning that the interpolation is at the relevant point on the timeline
+ * between [start] and [stop]. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
+ */
+@ExperimentalTextApi
+actual fun lerp(
+    start: PlatformSpanStyle,
+    stop: PlatformSpanStyle,
+    fraction: Float
+): PlatformSpanStyle {
+    return start
+}
\ No newline at end of file
diff --git a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/ParagraphStyle.kt b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/ParagraphStyle.kt
index c45cb92..b41d800 100644
--- a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/ParagraphStyle.kt
+++ b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/ParagraphStyle.kt
@@ -250,7 +250,7 @@
     if (start == null && stop == null) return null
     val startNonNull = start ?: PlatformParagraphStyle.Default
     val stopNonNull = stop ?: PlatformParagraphStyle.Default
-    return startNonNull.lerp(stopNonNull, fraction)
+    return lerp(startNonNull, stopNonNull, fraction)
 }
 
 @OptIn(ExperimentalTextApi::class)
diff --git a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/PlatformTextStyle.kt b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/PlatformTextStyle.kt
index cc15b47..2f7df74 100644
--- a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/PlatformTextStyle.kt
+++ b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/PlatformTextStyle.kt
@@ -49,8 +49,6 @@
     }
 
     fun merge(other: PlatformParagraphStyle?): PlatformParagraphStyle
-
-    fun lerp(stop: PlatformParagraphStyle, fraction: Float): PlatformParagraphStyle
 }
 
 /**
@@ -63,6 +61,44 @@
     }
 
     fun merge(other: PlatformSpanStyle?): PlatformSpanStyle
+}
 
-    fun lerp(stop: PlatformSpanStyle, fraction: Float): PlatformSpanStyle
-}
\ No newline at end of file
+/**
+ * Interpolate between two PlatformParagraphStyle's.
+ *
+ * This will not work well if the styles don't set the same fields.
+ *
+ * The [fraction] argument represents position on the timeline, with 0.0 meaning
+ * that the interpolation has not started, returning [start] (or something
+ * equivalent to [start]), 1.0 meaning that the interpolation has finished,
+ * returning [stop] (or something equivalent to [stop]), and values in between
+ * meaning that the interpolation is at the relevant point on the timeline
+ * between [start] and [stop]. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
+ */
+@ExperimentalTextApi
+expect fun lerp(
+    start: PlatformParagraphStyle,
+    stop: PlatformParagraphStyle,
+    fraction: Float
+): PlatformParagraphStyle
+
+/**
+ * Interpolate between two PlatformSpanStyle's.
+ *
+ * This will not work well if the styles don't set the same fields.
+ *
+ * The [fraction] argument represents position on the timeline, with 0.0 meaning
+ * that the interpolation has not started, returning [start] (or something
+ * equivalent to [start]), 1.0 meaning that the interpolation has finished,
+ * returning [stop] (or something equivalent to [stop]), and values in between
+ * meaning that the interpolation is at the relevant point on the timeline
+ * between [start] and [stop]. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
+ */
+@ExperimentalTextApi
+expect fun lerp(
+    start: PlatformSpanStyle,
+    stop: PlatformSpanStyle,
+    fraction: Float
+): PlatformSpanStyle
\ No newline at end of file
diff --git a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/SpanStyle.kt b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/SpanStyle.kt
index 7ea6b82..12f63e6 100644
--- a/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/SpanStyle.kt
+++ b/compose/ui/ui-text/src/commonMain/kotlin/androidx/compose/ui/text/SpanStyle.kt
@@ -455,7 +455,7 @@
     if (start == null && stop == null) return null
     val startNonNull = start ?: PlatformSpanStyle.Default
     val stopNonNull = stop ?: PlatformSpanStyle.Default
-    return startNonNull.lerp(stopNonNull, fraction)
+    return lerp(startNonNull, stopNonNull, fraction)
 }
 
 @OptIn(ExperimentalTextApi::class)
diff --git a/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/DesktopTextStyle.skiko.kt b/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/DesktopTextStyle.skiko.kt
index b892368..5d3f39f 100644
--- a/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/DesktopTextStyle.skiko.kt
+++ b/compose/ui/ui-text/src/skikoMain/kotlin/androidx/compose/ui/text/DesktopTextStyle.skiko.kt
@@ -64,10 +64,6 @@
         return this
     }
 
-    actual fun lerp(stop: PlatformParagraphStyle, fraction: Float): PlatformParagraphStyle {
-        return this
-    }
-
     override fun equals(other: Any?): Boolean {
         if (this === other) return true
         if (other !is PlatformParagraphStyle) return false
@@ -92,10 +88,6 @@
         return this
     }
 
-    actual fun lerp(stop: PlatformSpanStyle, fraction: Float): PlatformSpanStyle {
-        return this
-    }
-
     override fun equals(other: Any?): Boolean {
         if (this === other) return true
         if (other !is PlatformSpanStyle) return false
@@ -106,4 +98,47 @@
     override fun hashCode(): Int {
         return super.hashCode()
     }
+}
+
+/**
+ * Interpolate between two PlatformParagraphStyle's.
+ *
+ * This will not work well if the styles don't set the same fields.
+ *
+ * The [fraction] argument represents position on the timeline, with 0.0 meaning
+ * that the interpolation has not started, returning [start] (or something
+ * equivalent to [start]), 1.0 meaning that the interpolation has finished,
+ * returning [stop] (or something equivalent to [stop]), and values in between
+ * meaning that the interpolation is at the relevant point on the timeline
+ * between [start] and [stop]. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
+ */
+actual fun lerp(
+    start: PlatformParagraphStyle,
+    stop: PlatformParagraphStyle,
+    fraction: Float
+): PlatformParagraphStyle {
+    return start
+}
+
+/**
+ * Interpolate between two PlatformSpanStyle's.
+ *
+ * This will not work well if the styles don't set the same fields.
+ *
+ * The [fraction] argument represents position on the timeline, with 0.0 meaning
+ * that the interpolation has not started, returning [start] (or something
+ * equivalent to [start]), 1.0 meaning that the interpolation has finished,
+ * returning [stop] (or something equivalent to [stop]), and values in between
+ * meaning that the interpolation is at the relevant point on the timeline
+ * between [start] and [stop]. The interpolation can be extrapolated beyond 0.0 and
+ * 1.0, so negative values and values greater than 1.0 are valid.
+ */
+@ExperimentalTextApi
+actual fun lerp(
+    start: PlatformSpanStyle,
+    stop: PlatformSpanStyle,
+    fraction: Float
+): PlatformSpanStyle {
+    return start
 }
\ No newline at end of file