Skip to content

Instantly share code, notes, and snippets.

@AhmedMourad0
Last active March 1, 2024 16:11
Show Gist options
  • Save AhmedMourad0/7d11aa94632fde27532e975780c5a9ef to your computer and use it in GitHub Desktop.
Save AhmedMourad0/7d11aa94632fde27532e975780c5a9ef to your computer and use it in GitHub Desktop.
Code snippet for the `Leveraging the Power of Snapshots in Jetpack Compose` Medium article.
@Stable
sealed interface StickerType {
@Stable
class Shape(
shape: androidx.compose.ui.graphics.Shape,
color: Color,
borderWidth: Dp,
borderColor: Color
) : StickerType {
var shape by mutableStateOf(shape)
var color by mutableStateOf(color)
var borderWidth by mutableStateOf(borderWidth)
var borderColor by mutableStateOf(borderColor)
}
//images and other types go here
}
@Stable
class Sticker(
type: StickerType,
width: Dp,
height: Dp,
offset: Offset,
zIndex: Int,
rotation: Float,
scaleX: Float,
scaleY: Float
) {
var type by mutableStateOf(type)
var width by mutableStateOf(width)
var height by mutableStateOf(height)
var offset by mutableStateOf(offset)
var zIndex by mutableStateOf(zIndex)
var rotationZ by mutableStateOf(rotation)
var scaleX by mutableStateOf(scaleX)
var scaleY by mutableStateOf(scaleY)
val canvasId = randomUUID()
}
val Sticker.x get() = this.offset.x
val Sticker.y get() = this.offset.y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment