-
Notifications
You must be signed in to change notification settings - Fork 690
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
Add multiplatform support to coil-svg #1965
Add multiplatform support to coil-svg #1965
Conversation
@@ -0,0 +1,11 @@ | |||
package coil3.decode | |||
|
|||
object SvgDecoder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use an expect/actual class instead of factory functions:
expect class SvgDecoder @JvmOverloads constructor(
source: ImageSource,
options: Options,
useViewBoundsAsIntrinsicSize: Boolean = true,
) : Decoder {
class Factory : Decoder.Factory
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Btw you can run the CI checks locally using |
It should run successfully now. |
Great! This looks pretty good. I think we should be able to merge it once the tests are updated to run on Android and the JVM |
@@ -20,16 +20,17 @@ import kotlin.math.roundToInt | |||
import kotlinx.coroutines.runInterruptible | |||
|
|||
/** | |||
* A [Decoder] that uses [AndroidSVG](https://bigbadaboom.github.io/androidsvg/) to decode SVG | |||
* A [Decoder] that uses [AndroidSVG](https://bigbadaboom.github.io/androidsvg/) | |||
* and [SVGDOM](https://api.skia.org/classSkSVGDOM.html/) to decode SVG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this should be the docs for the expect
declaration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
import coil3.request.Options | ||
|
||
/** | ||
* A [Decoder] that uses [AndroidSVG](https://bigbadaboom.github.io/androidsvg/) and to decode SVG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be swapped with the Android implementation docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
private val decoderFactory = SvgDecoder.Factory() | ||
|
||
@Test | ||
fun handlesSvgMimeType() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to implement these tests in a common way? If you can't put a common test class in jvmCommonTest
, you could create AbstractSvgDecoderTest
in jvmCommonTest
which defines all the tests then have SvgDecoderTestAndroid
and SvgDecoderTestJvm
extend that class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to do this, but I can't access jvmCommonTest
or even commonTest
from androidInstrumentedTest
.
import kotlinx.coroutines.runBlocking | ||
import org.jetbrains.skia.Bitmap | ||
|
||
val Bitmap.size: Size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for converting these! Could we create a common Bitmap
type (only for our tests)? Looks like something like this should be enough:
expect class Bitmap {
val width: Int
val height: Int
fun getPixels(): ByteArray
}
This way we can put the rest of these functions in commonMain
, which will be useful for migrating more of Coil's tests to commonMain
.
I created |
A little mistake in the dependencies caused this failure. It should be running successfully now. |
|
||
class SvgDecoderTestAndroid : AbstractSvgDecoderTest(SvgDecoder.Factory()) { | ||
@Test | ||
override fun handlesSvgMimeType() = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can annotate the methods of the superclass so you don't need to override. We do something similar in Redwood: https://github.com/cashapp/redwood/blob/trunk/redwood-layout-shared-test/src/commonMain/kotlin/app/cash/redwood/layout/AbstractFlexContainerTest.kt#L71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
class SvgDecoderTestJvm : AbstractSvgDecoderTest(SvgDecoder.Factory()) { | ||
@Test | ||
override fun handlesSvgMimeType() = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for here.
|
||
class SvgDecoderTest { | ||
abstract class AbstractSvgDecoderTest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this class live in coil-svg/jvmCommonTest
instead of moving it to test-utils
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When it was in jvmCommonTest
it was not visible to android instrumented test.
@@ -100,7 +129,7 @@ fun Bitmap.isSimilarTo( | |||
*/ | |||
fun Bitmap.assertIsSimilarTo( | |||
expected: Bitmap, | |||
threshold: Double = 0.99 | |||
threshold: Double = 0.987 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use 0.98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it back to 0.99 in android and 0.98 in common.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
* Add multiplatform support to coil-svg * Remove commented code * Move SvgDecoderTest to coil3/decode * Add public API for creating SvgDecoder.Factory from commonMain * Move isSvg_newLine test to common * Apply spotless * Run apiDump * Change SvgDecoder to expect/actual class * Apply spotless * Add test to jvm target * Run spotlessApply * Use Okio FileSystem.RESOURCES * Remove unnecessary code * Fix SvgDecoder documentation * Share SvgDecoderTest between jvm and android * Apply spotless * Bring back old android Bitmap test functions * Fix SvgDecoder android documentation * Rename common decodeBitmapAsset to decodeBitmapResource * Fix test failure * Update threshold default value * Add Test annotation to AbstractSvgDecoderTest methods * Apply spotless
@MohamedRejeb awesome to see your contribution in coil also < 3 |
coil-svg
module to multiplatformSvgDecoder
for non android platforms based on skia svgSvgDecoder
fromcommonMain