-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from skydoves/kmp/landscapist-animation
Support KMP for the landscapist-animation module
- Loading branch information
Showing
18 changed files
with
383 additions
and
29 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
landscapist-animation/api/android/landscapist-animation.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public abstract interface class com/skydoves/landscapist/animation/circular/CircularRevealFinishListener { | ||
public abstract fun onFinish ()V | ||
} | ||
|
||
public final class com/skydoves/landscapist/animation/circular/CircularRevealImageKt { | ||
public static final field DefaultCircularRevealDuration I | ||
public static final fun CircularRevealImage (Landroidx/compose/ui/graphics/ImageBitmap;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/painter/Painter;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin;Landroidx/compose/runtime/Composer;II)V | ||
} | ||
|
||
public final class com/skydoves/landscapist/animation/circular/CircularRevealPlugin : com/skydoves/landscapist/plugins/ImagePlugin$PainterPlugin { | ||
public static final field $stable I | ||
public fun <init> ()V | ||
public fun <init> (ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;)V | ||
public synthetic fun <init> (ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;ILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public final fun component1 ()I | ||
public final fun component2 ()Lcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener; | ||
public fun compose (Landroidx/compose/ui/graphics/ImageBitmap;Landroidx/compose/ui/graphics/painter/Painter;Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/graphics/painter/Painter; | ||
public final fun copy (ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;)Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin; | ||
public static synthetic fun copy$default (Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin;ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;ILjava/lang/Object;)Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin; | ||
public fun equals (Ljava/lang/Object;)Z | ||
public final fun getDuration ()I | ||
public final fun getOnFinishListener ()Lcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener; | ||
public fun hashCode ()I | ||
public fun toString ()Ljava/lang/String; | ||
} | ||
|
||
public final class com/skydoves/landscapist/animation/crossfade/CrossfadePlugin : com/skydoves/landscapist/plugins/ImagePlugin$PainterPlugin { | ||
public static final field $stable I | ||
public fun <init> ()V | ||
public fun <init> (I)V | ||
public synthetic fun <init> (IILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public fun compose (Landroidx/compose/ui/graphics/ImageBitmap;Landroidx/compose/ui/graphics/painter/Painter;Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/graphics/painter/Painter; | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
landscapist-animation/api/desktop/landscapist-animation.api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
public abstract interface class com/skydoves/landscapist/animation/circular/CircularRevealFinishListener { | ||
public abstract fun onFinish ()V | ||
} | ||
|
||
public final class com/skydoves/landscapist/animation/circular/CircularRevealImageKt { | ||
public static final field DefaultCircularRevealDuration I | ||
public static final fun CircularRevealImage (Landroidx/compose/ui/graphics/ImageBitmap;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/painter/Painter;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin;Landroidx/compose/runtime/Composer;II)V | ||
} | ||
|
||
public final class com/skydoves/landscapist/animation/circular/CircularRevealPlugin : com/skydoves/landscapist/plugins/ImagePlugin$PainterPlugin { | ||
public static final field $stable I | ||
public fun <init> ()V | ||
public fun <init> (ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;)V | ||
public synthetic fun <init> (ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;ILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public final fun component1 ()I | ||
public final fun component2 ()Lcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener; | ||
public fun compose (Landroidx/compose/ui/graphics/ImageBitmap;Landroidx/compose/ui/graphics/painter/Painter;Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/graphics/painter/Painter; | ||
public final fun copy (ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;)Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin; | ||
public static synthetic fun copy$default (Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin;ILcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener;ILjava/lang/Object;)Lcom/skydoves/landscapist/animation/circular/CircularRevealPlugin; | ||
public fun equals (Ljava/lang/Object;)Z | ||
public final fun getDuration ()I | ||
public final fun getOnFinishListener ()Lcom/skydoves/landscapist/animation/circular/CircularRevealFinishListener; | ||
public fun hashCode ()I | ||
public fun toString ()Ljava/lang/String; | ||
} | ||
|
||
public final class com/skydoves/landscapist/animation/crossfade/CrossfadePlugin : com/skydoves/landscapist/plugins/ImagePlugin$PainterPlugin { | ||
public static final field $stable I | ||
public fun <init> ()V | ||
public fun <init> (I)V | ||
public synthetic fun <init> (IILkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public fun compose (Landroidx/compose/ui/graphics/ImageBitmap;Landroidx/compose/ui/graphics/painter/Painter;Landroidx/compose/runtime/Composer;I)Landroidx/compose/ui/graphics/painter/Painter; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...rc/commonMain/kotlin/com/skydoves/landscapist/animation/circular/CircularRevealPainter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Designed and developed by 2020-2023 skydoves (Jaewoong Eum) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.skydoves.landscapist.animation.circular | ||
|
||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.painter.Painter | ||
|
||
/** | ||
* CircularRevealPainter is a [Painter] which animates a clipping circle to reveal an image. | ||
* Reveal animations provide users visual continuity when we show an image. | ||
* | ||
* @param imageBitmap an image bitmap for loading for the content. | ||
* @param painter an image painter to draw an [ImageBitmap] into the provided canvas. | ||
*/ | ||
internal expect class CircularRevealPainter( | ||
imageBitmap: ImageBitmap, | ||
painter: Painter, | ||
) : Painter { | ||
internal val imageBitmap: ImageBitmap | ||
internal val painter: Painter | ||
internal var radius: Float | ||
} |
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
...on/src/commonMain/kotlin/com/skydoves/landscapist/animation/crossfade/CrossfadePainter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Designed and developed by 2020-2023 skydoves (Jaewoong Eum) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.skydoves.landscapist.animation.crossfade | ||
|
||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.painter.Painter | ||
|
||
/** | ||
* CrossfadePainter is a [Painter] that applies crossfade filter effect on the given [imageBitmap]. | ||
* | ||
* @param imageBitmap an image bitmap for loading for the content. | ||
* @param painter an image painter to draw an [ImageBitmap] into the provided canvas. | ||
*/ | ||
internal expect class CrossfadePainter( | ||
imageBitmap: ImageBitmap, | ||
painter: Painter, | ||
) : Painter { | ||
internal val imageBitmap: ImageBitmap | ||
internal val painter: Painter | ||
internal var transitionColorFilter: ColorFilter? | ||
} |
File renamed without changes.
File renamed without changes.
100 changes: 100 additions & 0 deletions
100
.../src/skiaMain/kotlin/com/skydoves/landscapist/animation/circular/CircularRevealPainter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Designed and developed by 2020-2023 skydoves (Jaewoong Eum) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.skydoves.landscapist.animation.circular | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.neverEqualPolicy | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.geometry.Rect | ||
import androidx.compose.ui.geometry.Size | ||
import androidx.compose.ui.geometry.toRect | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.Paint | ||
import androidx.compose.ui.graphics.ShaderBrush | ||
import androidx.compose.ui.graphics.asSkiaBitmap | ||
import androidx.compose.ui.graphics.drawscope.DrawScope | ||
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import org.jetbrains.skia.Image | ||
import org.jetbrains.skia.Matrix33 | ||
|
||
/** | ||
* CircularRevealPainter is a [Painter] which animates a clipping circle to reveal an image. | ||
* Reveal animations provide users visual continuity when we show an image. | ||
* | ||
* @param imageBitmap an image bitmap for loading for the content. | ||
* @param painter an image painter to draw an [ImageBitmap] into the provided canvas. | ||
*/ | ||
internal actual class CircularRevealPainter actual constructor( | ||
actual val imageBitmap: ImageBitmap, | ||
actual val painter: Painter, | ||
) : Painter() { | ||
|
||
actual var radius by mutableStateOf(0f, policy = neverEqualPolicy()) | ||
|
||
override fun DrawScope.onDraw() { | ||
var dx = 0f | ||
var dy = 0f | ||
var scale: Float | ||
val paint = Paint() | ||
|
||
paint.asFrameworkPaint().apply { | ||
isAntiAlias = true | ||
isDither = true | ||
} | ||
|
||
drawIntoCanvas { canvas -> | ||
// cache the paint in the internal stack. | ||
canvas.saveLayer(size.toRect(), paint) | ||
|
||
val mDrawableRect = Rect(offset = Offset.Zero, size = Size(size.width, size.height)) | ||
val bitmapWidth: Int = imageBitmap.width | ||
val bitmapHeight: Int = imageBitmap.height | ||
|
||
if (bitmapWidth * mDrawableRect.size.height > mDrawableRect.size.width * bitmapHeight) { | ||
scale = mDrawableRect.size.height / bitmapHeight.toFloat() | ||
dx = (mDrawableRect.size.width - bitmapWidth * scale) * 0.5f | ||
} else { | ||
scale = mDrawableRect.size.width / bitmapWidth.toFloat() | ||
dy = (mDrawableRect.size.height - bitmapHeight * scale) * 0.5f | ||
} | ||
|
||
// resize the matrix to scale by sx and sy. | ||
val m1 = Matrix33.makeScale(scale, scale) | ||
val m2 = Matrix33.makeTranslate( | ||
(dx + 0.5f) + mDrawableRect.left, | ||
(dy + 0.5f) + mDrawableRect.top, | ||
) | ||
val shaderMatrix = m1.makeConcat(m2) | ||
val shader = Image.makeFromBitmap(imageBitmap.asSkiaBitmap()).makeShader( | ||
localMatrix = shaderMatrix, | ||
) | ||
val brush = ShaderBrush(shader) | ||
// calculate radius and draw an image bitmap as a circle. | ||
val calculatedRadius = size.width.coerceAtLeast(size.height) * radius | ||
drawCircle(brush, calculatedRadius, Offset(size.width / 2, size.height / 2)) | ||
// restore canvas. | ||
canvas.restore() | ||
// resets the paint and release to the pool. | ||
paint.asFrameworkPaint().reset() | ||
} | ||
} | ||
|
||
/** return the dimension size of the [painter]'s intrinsic width and height. */ | ||
override val intrinsicSize: Size get() = painter.intrinsicSize | ||
} |
Oops, something went wrong.