@momo-kits/native-kits 0.162.1-gif.17-debug → 0.162.1-gif.18-debug
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.gradle.kts +0 -10
- package/compose/build.gradle.kts +2 -7
- package/compose/build.gradle.kts.backup +1 -6
- package/compose/compose.podspec +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +13 -14
- package/gradle/libs.versions.toml +2 -5
- package/gradle.properties +1 -1
- package/package.json +1 -1
- package/publish.sh +0 -5
- package/settings.gradle.kts +0 -2
- package/third_party/sketch-compose-core-patched/META-INF/MANIFEST.MF +0 -2
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/LocalPlatformContext.android.kt +0 -27
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/PainterImage.android.kt +0 -36
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/painter/DrawableAnimatablePainter.kt +0 -83
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/painter/DrawablePainter.kt +0 -238
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/painter/IconAnimatablePainter.android.kt +0 -2076
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/painter/IconPainter.android.kt +0 -2076
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/request/ImageOptions.composeAndroid.kt +0 -33
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/request/ImageRequest.composeAndroid.kt +0 -33
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/ColorDrawableStateImage.composeAndroid.kt +0 -70
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/ColorPainterStateImage.android.kt +0 -23
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/CurrentStateImage.composeAndroid.kt +0 -49
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/DrawableStateImage.composeAndroid.kt +0 -40
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/EquitableDrawable.composeAndroid.kt +0 -39
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/IconAnimatableDrawableStateImage.composeAndroid.kt +0 -642
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/IconAnimatablePainterStateImage.android.kt +0 -2077
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/IconDrawableStateImage.composeAndroid.kt +0 -642
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/state/IconPainterStateImage.android.kt +0 -2077
- package/third_party/sketch-compose-core-patched/androidMain/com/github/panpf/sketch/util/compose_core_utils.android.kt +0 -30
- package/third_party/sketch-compose-core-patched/build.gradle.kts +0 -76
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/AsyncImage.kt +0 -292
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/AsyncImagePainter.kt +0 -273
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/AsyncImageState.kt +0 -358
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/LocalPlatformContext.common.kt +0 -27
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/PainterImage.kt +0 -86
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/PainterState.kt +0 -51
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/SubcomposeAsyncImage.kt +0 -397
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/internal/AsyncImageContent.kt +0 -77
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/internal/utils.kt +0 -45
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/AnimatablePainter.kt +0 -72
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/AnimatedImagePainter.kt +0 -398
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/CrossfadePainter.kt +0 -295
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/EquitableAnimatablePainter.kt +0 -74
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/EquitablePainter.common.kt +0 -91
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/IconAnimatablePainter.common.kt +0 -268
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/IconPainter.common.kt +0 -341
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/ImageBitmapPainter.kt +0 -98
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/PainterWrapper.kt +0 -68
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/ResizeAnimatablePainter.kt +0 -99
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/ResizePainter.kt +0 -204
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/SketchPainter.kt +0 -29
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/painter/painters.common.kt +0 -79
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/request/ImageOptions.composeCommon.kt +0 -95
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/request/ImageRequest.composeCommon.kt +0 -135
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/request/internal/ComposeRequestDelegate.kt +0 -44
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/request/internal/ComposeRequestManager.kt +0 -42
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/resize/AsyncImageSizeResolver.kt +0 -59
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/resize/ComposeResizeOnDrawHelper.kt +0 -50
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/state/ColorPainterStateImage.kt +0 -72
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/state/ConditionStateImage.compose.kt +0 -64
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/state/CurrentStateImage.compose.kt +0 -38
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/state/IconAnimatablePainterStateImage.common.kt +0 -261
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/state/IconPainterStateImage.common.kt +0 -261
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/state/PainterStateImage.kt +0 -55
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/target/AsyncImageTarget.kt +0 -144
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/target/ComposeTarget.common.kt +0 -88
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/target/GenericComposeTarget.kt +0 -124
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/target/internal/AsyncImageListener.kt +0 -84
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/transition/ComposeCrossfadeTransition.kt +0 -180
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/transition/TransitionComposeTarget.kt +0 -32
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/transition/TransitionPainter.kt +0 -23
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/util/RememberedCounter.kt +0 -51
- package/third_party/sketch-compose-core-patched/commonMain/com/github/panpf/sketch/util/compose_core_utils.common.kt +0 -347
- package/third_party/sketch-compose-core-patched/nonAndroidMain/com/github/panpf/sketch/LocalPlatformContext.nonAndroid.kt +0 -28
- package/third_party/sketch-compose-core-patched/nonAndroidMain/com/github/panpf/sketch/PainterImage.nonAndroid.kt +0 -35
- package/third_party/sketch-compose-core-patched/nonAndroidMain/com/github/panpf/sketch/request/ImageOptions.composeNonAndroid.kt +0 -35
- package/third_party/sketch-compose-core-patched/nonAndroidMain/com/github/panpf/sketch/request/ImageRequest.composeNonAndroid.kt +0 -35
- package/third_party/sketch-compose-core-patched/nonAndroidMain/com/github/panpf/sketch/util/compose_core_utils.nonAndroid.kt +0 -28
package/build.gradle.kts
CHANGED
|
@@ -9,13 +9,3 @@ plugins {
|
|
|
9
9
|
alias(libs.plugins.jetbrains.kotlin.serialization) apply false
|
|
10
10
|
alias(libs.plugins.vanniktech.mavenPublish) apply false
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
subprojects {
|
|
14
|
-
configurations.configureEach {
|
|
15
|
-
resolutionStrategy.dependencySubstitution {
|
|
16
|
-
substitute(module("io.github.panpf.sketch4:sketch-compose-core"))
|
|
17
|
-
.using(project(":sketch-compose-core"))
|
|
18
|
-
.because("Patch duplicate Kotlin/Native symbols in sketch-compose-core 4.4.0")
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
package/compose/build.gradle.kts
CHANGED
|
@@ -40,7 +40,7 @@ kotlin {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
cocoapods {
|
|
43
|
-
version = "0.162.1-gif.
|
|
43
|
+
version = "0.162.1-gif.18-debug"
|
|
44
44
|
summary = "IOS Shared module"
|
|
45
45
|
homepage = "https://momo.vn"
|
|
46
46
|
ios.deploymentTarget = "15.0"
|
|
@@ -77,12 +77,7 @@ kotlin {
|
|
|
77
77
|
implementation(libs.kotlinx.datetime)
|
|
78
78
|
api(libs.native.max.api)
|
|
79
79
|
implementation(libs.compottie)
|
|
80
|
-
implementation(
|
|
81
|
-
exclude(group = "io.github.panpf.sketch4", module = "sketch-compose-core")
|
|
82
|
-
}
|
|
83
|
-
implementation(project(":sketch-compose-core"))
|
|
84
|
-
implementation(libs.sketch.http.ktor3)
|
|
85
|
-
implementation(libs.sketch.animated.gif)
|
|
80
|
+
implementation(libs.gif.image)
|
|
86
81
|
}
|
|
87
82
|
androidMain.dependencies {
|
|
88
83
|
implementation(libs.ktor.client.okhttp)
|
|
@@ -77,12 +77,7 @@ kotlin {
|
|
|
77
77
|
implementation(libs.kotlinx.datetime)
|
|
78
78
|
api(libs.native.max.api)
|
|
79
79
|
implementation(libs.compottie)
|
|
80
|
-
implementation(
|
|
81
|
-
exclude(group = "io.github.panpf.sketch4", module = "sketch-compose-core")
|
|
82
|
-
}
|
|
83
|
-
implementation(project(":sketch-compose-core"))
|
|
84
|
-
implementation(libs.sketch.http.ktor3)
|
|
85
|
-
implementation(libs.sketch.animated.gif)
|
|
80
|
+
implementation(libs.gif.image)
|
|
86
81
|
}
|
|
87
82
|
androidMain.dependencies {
|
|
88
83
|
implementation(libs.ktor.client.okhttp)
|
package/compose/compose.podspec
CHANGED
|
@@ -19,13 +19,12 @@ import androidx.compose.ui.semantics.contentDescription
|
|
|
19
19
|
import androidx.compose.ui.semantics.semantics
|
|
20
20
|
import androidx.compose.ui.platform.LocalDensity
|
|
21
21
|
import androidx.compose.ui.unit.dp
|
|
22
|
-
import com.github.panpf.sketch.AsyncImage as SketchAsyncImage
|
|
23
|
-
import com.github.panpf.sketch.PainterState
|
|
24
|
-
import com.github.panpf.sketch.rememberAsyncImageState
|
|
25
22
|
import coil3.compose.AsyncImage as CoilAsyncImage
|
|
26
23
|
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
27
24
|
import vn.momo.kits.const.AppTheme
|
|
28
25
|
import vn.momo.kits.const.Colors
|
|
26
|
+
import vn.momo.kits.gifimage.GifImage
|
|
27
|
+
import vn.momo.kits.gifimage.GifImageState
|
|
29
28
|
import vn.momo.kits.modifier.conditional
|
|
30
29
|
|
|
31
30
|
data class Options(
|
|
@@ -137,27 +136,27 @@ fun Image(
|
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
if (isGifUrl(urlToLoad)) {
|
|
140
|
-
val
|
|
139
|
+
val imageState = remember(urlToLoad) { mutableStateOf(ImageState.Loading) }
|
|
141
140
|
|
|
142
|
-
|
|
141
|
+
GifImage(
|
|
143
142
|
modifier = Modifier.matchParentSize(),
|
|
144
|
-
|
|
145
|
-
state = asyncImageState,
|
|
143
|
+
url = urlToLoad,
|
|
146
144
|
contentDescription = null,
|
|
147
145
|
contentScale = imageOptions.contentScale,
|
|
148
146
|
alignment = imageOptions.alignment,
|
|
149
147
|
colorFilter = imageOptions.colorFilter,
|
|
150
148
|
alpha = imageOptions.alpha,
|
|
149
|
+
onStateChanged = {
|
|
150
|
+
imageState.value = when (it) {
|
|
151
|
+
GifImageState.Success -> ImageState.Success
|
|
152
|
+
GifImageState.Error -> ImageState.Error
|
|
153
|
+
GifImageState.Loading -> ImageState.Loading
|
|
154
|
+
}
|
|
155
|
+
},
|
|
151
156
|
)
|
|
152
157
|
|
|
153
|
-
val imageState = when (asyncImageState.painterState) {
|
|
154
|
-
is PainterState.Success -> ImageState.Success
|
|
155
|
-
is PainterState.Error -> ImageState.Error
|
|
156
|
-
else -> ImageState.Loading
|
|
157
|
-
}
|
|
158
|
-
|
|
159
158
|
ImageStateContent(
|
|
160
|
-
imageState = imageState,
|
|
159
|
+
imageState = imageState.value,
|
|
161
160
|
loading = loading,
|
|
162
161
|
onLoadingChanged = currentOnLoadingChanged.value
|
|
163
162
|
)
|
|
@@ -21,7 +21,7 @@ maxapi = "0.1.1"
|
|
|
21
21
|
vanniktechMavenPublish = "0.34.0"
|
|
22
22
|
kits = "0.159.1-beta.7"
|
|
23
23
|
nativemaxapi = "0.0.6"
|
|
24
|
-
|
|
24
|
+
gif-image = "0.1.0"
|
|
25
25
|
|
|
26
26
|
[libraries]
|
|
27
27
|
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor-version" }
|
|
@@ -54,10 +54,7 @@ androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "a
|
|
|
54
54
|
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
|
|
55
55
|
material = { module = "com.google.android.material:material", version.ref = "material" }
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
sketch-core = { module = "io.github.panpf.sketch4:sketch-core", version.ref = "sketch" }
|
|
59
|
-
sketch-http-ktor3 = { module = "io.github.panpf.sketch4:sketch-http-ktor3", version.ref = "sketch" }
|
|
60
|
-
sketch-animated-gif = { module = "io.github.panpf.sketch4:sketch-animated-gif", version.ref = "sketch" }
|
|
57
|
+
gif-image = { module = "vn.momo.kits:gif-image", version.ref = "gif-image" }
|
|
61
58
|
[plugins]
|
|
62
59
|
jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
|
63
60
|
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
package/gradle.properties
CHANGED
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -241,11 +241,6 @@ phase_publish_maven() {
|
|
|
241
241
|
VERSION=$(node -p "require('./package.json').version")
|
|
242
242
|
export VERSION="$VERSION"
|
|
243
243
|
|
|
244
|
-
echo "📦 Publishing patched sketch-compose-core to Maven..."
|
|
245
|
-
|
|
246
|
-
./gradlew :sketch-compose-core:publishAllPublicationsToGitLabPackagesRepository
|
|
247
|
-
|
|
248
|
-
echo "✅ patched sketch-compose-core Maven publishing completed successfully!"
|
|
249
244
|
echo "📦 Publishing KMP artifacts to Maven (version ${VERSION})..."
|
|
250
245
|
|
|
251
246
|
./gradlew :compose:publishAllPublicationsToGitLabPackagesRepository
|
package/settings.gradle.kts
CHANGED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2024 panpf <panpfpanpf@outlook.com>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
package com.github.panpf.sketch
|
|
18
|
-
|
|
19
|
-
import androidx.compose.runtime.ProvidableCompositionLocal
|
|
20
|
-
import androidx.compose.ui.platform.LocalContext
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Platform context, used to provide platform-specific context information
|
|
24
|
-
*
|
|
25
|
-
* @see com.github.panpf.sketch.compose.core.android.test.LocalPlatformContextAndroidTest.testLocalPlatformContext
|
|
26
|
-
*/
|
|
27
|
-
actual val LocalPlatformContext: ProvidableCompositionLocal<PlatformContext> = LocalContext
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2024 panpf <panpfpanpf@outlook.com>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
package com.github.panpf.sketch
|
|
18
|
-
|
|
19
|
-
import androidx.compose.ui.graphics.FilterQuality
|
|
20
|
-
import androidx.compose.ui.graphics.asImageBitmap
|
|
21
|
-
import androidx.compose.ui.graphics.painter.Painter
|
|
22
|
-
import com.github.panpf.sketch.painter.AnimatedImagePainter
|
|
23
|
-
import com.github.panpf.sketch.painter.asPainter
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Convert the Image to a Painter
|
|
27
|
-
*
|
|
28
|
-
* @see com.github.panpf.sketch.compose.core.android.test.PainterImageAndroidTest.testImageAsPainterOrNull
|
|
29
|
-
*/
|
|
30
|
-
actual fun Image.asPainterOrNull(filterQuality: FilterQuality): Painter? = when (this) {
|
|
31
|
-
is PainterImage -> painter
|
|
32
|
-
is BitmapImage -> bitmap.asImageBitmap().asPainter(filterQuality)
|
|
33
|
-
is AnimatedImage -> AnimatedImagePainter(this)
|
|
34
|
-
is DrawableImage -> drawable.asPainter()
|
|
35
|
-
else -> null
|
|
36
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2024 panpf <panpfpanpf@outlook.com>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
package com.github.panpf.sketch.painter
|
|
18
|
-
|
|
19
|
-
import android.graphics.drawable.Animatable
|
|
20
|
-
import android.graphics.drawable.Drawable
|
|
21
|
-
import androidx.compose.runtime.Stable
|
|
22
|
-
import com.github.panpf.sketch.util.toLogString
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Drawable painter that implements the [AnimatablePainter] interface
|
|
26
|
-
*
|
|
27
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawableAnimatablePainterTest
|
|
28
|
-
*/
|
|
29
|
-
@Stable
|
|
30
|
-
class DrawableAnimatablePainter(
|
|
31
|
-
drawable: Drawable
|
|
32
|
-
) : DrawablePainter(drawable), AnimatablePainter {
|
|
33
|
-
|
|
34
|
-
private val animatable: Animatable
|
|
35
|
-
|
|
36
|
-
init {
|
|
37
|
-
require(drawable is Animatable) {
|
|
38
|
-
"drawable must be Animatable"
|
|
39
|
-
}
|
|
40
|
-
animatable = drawable
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
override fun onFirstRemembered() {
|
|
44
|
-
super.onFirstRemembered()
|
|
45
|
-
animatable.start()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
override fun onLastRemembered() {
|
|
49
|
-
super.onLastRemembered()
|
|
50
|
-
animatable.stop()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
override fun start() {
|
|
54
|
-
if (rememberedCounter.isRemembered) {
|
|
55
|
-
animatable.start()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
override fun stop() {
|
|
60
|
-
if (rememberedCounter.isRemembered) {
|
|
61
|
-
animatable.stop()
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
override fun isRunning(): Boolean {
|
|
66
|
-
return animatable.isRunning
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
override fun equals(other: Any?): Boolean {
|
|
70
|
-
if (this === other) return true
|
|
71
|
-
if (other == null || this::class != other::class) return false
|
|
72
|
-
other as DrawableAnimatablePainter
|
|
73
|
-
return drawable == other.drawable
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
override fun hashCode(): Int {
|
|
77
|
-
return drawable.hashCode()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
override fun toString(): String {
|
|
81
|
-
return "DrawableAnimatablePainter(drawable=${drawable.toLogString()})"
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2024 panpf <panpfpanpf@outlook.com>
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
package com.github.panpf.sketch.painter
|
|
18
|
-
|
|
19
|
-
import android.graphics.drawable.Animatable
|
|
20
|
-
import android.graphics.drawable.BitmapDrawable
|
|
21
|
-
import android.graphics.drawable.ColorDrawable
|
|
22
|
-
import android.graphics.drawable.Drawable
|
|
23
|
-
import android.graphics.drawable.Drawable.Callback
|
|
24
|
-
import android.os.Build.VERSION
|
|
25
|
-
import android.os.Handler
|
|
26
|
-
import android.os.Looper
|
|
27
|
-
import android.view.View
|
|
28
|
-
import androidx.compose.runtime.Composable
|
|
29
|
-
import androidx.compose.runtime.RememberObserver
|
|
30
|
-
import androidx.compose.runtime.Stable
|
|
31
|
-
import androidx.compose.runtime.getValue
|
|
32
|
-
import androidx.compose.runtime.mutableIntStateOf
|
|
33
|
-
import androidx.compose.runtime.mutableStateOf
|
|
34
|
-
import androidx.compose.runtime.remember
|
|
35
|
-
import androidx.compose.runtime.setValue
|
|
36
|
-
import androidx.compose.ui.geometry.Size
|
|
37
|
-
import androidx.compose.ui.graphics.Color
|
|
38
|
-
import androidx.compose.ui.graphics.ColorFilter
|
|
39
|
-
import androidx.compose.ui.graphics.asAndroidColorFilter
|
|
40
|
-
import androidx.compose.ui.graphics.asImageBitmap
|
|
41
|
-
import androidx.compose.ui.graphics.drawscope.DrawScope
|
|
42
|
-
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
|
43
|
-
import androidx.compose.ui.graphics.nativeCanvas
|
|
44
|
-
import androidx.compose.ui.graphics.painter.BitmapPainter
|
|
45
|
-
import androidx.compose.ui.graphics.painter.ColorPainter
|
|
46
|
-
import androidx.compose.ui.graphics.painter.Painter
|
|
47
|
-
import androidx.compose.ui.graphics.withSave
|
|
48
|
-
import androidx.compose.ui.unit.LayoutDirection
|
|
49
|
-
import androidx.compose.ui.unit.LayoutDirection.Ltr
|
|
50
|
-
import androidx.compose.ui.unit.LayoutDirection.Rtl
|
|
51
|
-
import com.github.panpf.sketch.drawable.EquitableDrawable
|
|
52
|
-
import com.github.panpf.sketch.util.RememberedCounter
|
|
53
|
-
import com.github.panpf.sketch.util.toLogString
|
|
54
|
-
import kotlin.math.ceil
|
|
55
|
-
import kotlin.math.roundToInt
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Remembers [Drawable] wrapped up as a [Painter]. This function attempts to un-wrap the
|
|
59
|
-
* drawable contents and use Compose primitives where possible.
|
|
60
|
-
*
|
|
61
|
-
* If the provided [drawable] is `null`, an empty no-op painter is returned.
|
|
62
|
-
*
|
|
63
|
-
* This function tries to dispatch lifecycle events to [drawable] as much as possible from
|
|
64
|
-
* within Compose.
|
|
65
|
-
*
|
|
66
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawablePainterTest.testRememberDrawablePainter
|
|
67
|
-
*/
|
|
68
|
-
@Composable
|
|
69
|
-
fun rememberDrawablePainter(drawable: EquitableDrawable): Painter =
|
|
70
|
-
remember(drawable) { drawable.asPainter() }
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Converts a [Drawable] to a [Painter]. This function attempts to un-wrap the drawable contents
|
|
74
|
-
*
|
|
75
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawablePainterTest.testAsPainter
|
|
76
|
-
*/
|
|
77
|
-
fun Drawable?.asPainter(): Painter {
|
|
78
|
-
return when (this) {
|
|
79
|
-
null -> EmptyPainter
|
|
80
|
-
is Animatable -> DrawableAnimatablePainter(this.mutate())
|
|
81
|
-
is BitmapDrawable -> BitmapPainter(this.bitmap.asImageBitmap())
|
|
82
|
-
is ColorDrawable -> ColorPainter(Color(this.color))
|
|
83
|
-
// Since the DrawablePainter will be remembered and it implements RememberObserver, it
|
|
84
|
-
// will receive the necessary events
|
|
85
|
-
else -> DrawablePainter(this.mutate())
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* A [Painter] which draws an Android [Drawable] and supports [Animatable] drawables. Instances
|
|
91
|
-
* should be remembered to be able to start and stop [Animatable] animations.
|
|
92
|
-
*
|
|
93
|
-
* Instances are usually retrieved from [rememberDrawablePainter].
|
|
94
|
-
*
|
|
95
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawablePainterTest
|
|
96
|
-
*/
|
|
97
|
-
@Stable
|
|
98
|
-
// TODO Synchronize from accompanyist-drawablepainter
|
|
99
|
-
open class DrawablePainter(
|
|
100
|
-
val drawable: Drawable
|
|
101
|
-
) : Painter(), RememberObserver, SketchPainter {
|
|
102
|
-
private var drawInvalidateTick by mutableIntStateOf(0)
|
|
103
|
-
private var drawableIntrinsicSize by mutableStateOf(drawable.intrinsicSize)
|
|
104
|
-
|
|
105
|
-
private val callback: Callback by lazy {
|
|
106
|
-
object : Callback {
|
|
107
|
-
override fun invalidateDrawable(d: Drawable) {
|
|
108
|
-
// Update the tick so that we get re-drawn
|
|
109
|
-
drawInvalidateTick++
|
|
110
|
-
// Update our intrinsic size too
|
|
111
|
-
drawableIntrinsicSize = drawable.intrinsicSize
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
override fun scheduleDrawable(d: Drawable, what: Runnable, time: Long) {
|
|
115
|
-
MAIN_HANDLER.postAtTime(what, time)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
override fun unscheduleDrawable(d: Drawable, what: Runnable) {
|
|
119
|
-
MAIN_HANDLER.removeCallbacks(what)
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
internal val rememberedCounter: RememberedCounter = RememberedCounter()
|
|
125
|
-
|
|
126
|
-
override val intrinsicSize: Size get() = drawableIntrinsicSize
|
|
127
|
-
|
|
128
|
-
init {
|
|
129
|
-
if (drawable.intrinsicWidth >= 0 && drawable.intrinsicHeight >= 0) {
|
|
130
|
-
// Update the drawable's bounds to match the intrinsic size
|
|
131
|
-
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
override fun onRemembered() {
|
|
136
|
-
if (!rememberedCounter.remember()) return
|
|
137
|
-
onFirstRemembered()
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
protected open fun onFirstRemembered() {
|
|
141
|
-
drawable.callback = callback
|
|
142
|
-
drawable.setVisible(true, true)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
override fun onAbandoned() = onForgotten()
|
|
146
|
-
override fun onForgotten() {
|
|
147
|
-
if (!rememberedCounter.forget()) return
|
|
148
|
-
onLastRemembered()
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
protected open fun onLastRemembered() {
|
|
152
|
-
drawable.setVisible(false, false)
|
|
153
|
-
drawable.callback = null
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
override fun applyAlpha(alpha: Float): Boolean {
|
|
157
|
-
drawable.alpha = (alpha * 255).roundToInt().coerceIn(0, 255)
|
|
158
|
-
return true
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
override fun applyColorFilter(colorFilter: ColorFilter?): Boolean {
|
|
162
|
-
drawable.colorFilter = colorFilter?.asAndroidColorFilter()
|
|
163
|
-
return true
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
override fun applyLayoutDirection(layoutDirection: LayoutDirection): Boolean {
|
|
167
|
-
if (VERSION.SDK_INT >= 23) {
|
|
168
|
-
return drawable.setLayoutDirection(
|
|
169
|
-
when (layoutDirection) {
|
|
170
|
-
Ltr -> View.LAYOUT_DIRECTION_LTR
|
|
171
|
-
Rtl -> View.LAYOUT_DIRECTION_RTL
|
|
172
|
-
}
|
|
173
|
-
)
|
|
174
|
-
}
|
|
175
|
-
return false
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
override fun DrawScope.onDraw() {
|
|
179
|
-
drawIntoCanvas { canvas ->
|
|
180
|
-
// Reading this ensures that we invalidate when invalidateDrawable() is called
|
|
181
|
-
drawInvalidateTick
|
|
182
|
-
|
|
183
|
-
// Update the Drawable's bounds
|
|
184
|
-
drawable.setBounds(0, 0, ceil(size.width).toInt(), ceil(size.height).toInt())
|
|
185
|
-
|
|
186
|
-
canvas.withSave {
|
|
187
|
-
drawable.draw(canvas.nativeCanvas)
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
override fun equals(other: Any?): Boolean {
|
|
193
|
-
if (this === other) return true
|
|
194
|
-
if (other == null || this::class != other::class) return false
|
|
195
|
-
other as DrawablePainter
|
|
196
|
-
return drawable == other.drawable
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
override fun hashCode(): Int {
|
|
200
|
-
return drawable.hashCode()
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
override fun toString(): String {
|
|
204
|
-
return "DrawablePainter(drawable=${drawable.toLogString()})"
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawablePainterTest.testMainHandler
|
|
210
|
-
*/
|
|
211
|
-
internal val MAIN_HANDLER by lazy(LazyThreadSafetyMode.NONE) {
|
|
212
|
-
Handler(Looper.getMainLooper())
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Get the intrinsic size of Drawable, if Drawable has no intrinsic size, return [Size.Unspecified]
|
|
217
|
-
*
|
|
218
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawablePainterTest.testDrawableIntrinsicSize
|
|
219
|
-
*/
|
|
220
|
-
internal val Drawable.intrinsicSize: Size
|
|
221
|
-
get() = when {
|
|
222
|
-
// Only return a finite size if the drawable has an intrinsic size
|
|
223
|
-
intrinsicWidth >= 0 && intrinsicHeight >= 0 -> {
|
|
224
|
-
Size(width = intrinsicWidth.toFloat(), height = intrinsicHeight.toFloat())
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
else -> Size.Unspecified
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Empty Painter
|
|
232
|
-
*
|
|
233
|
-
* @see com.github.panpf.sketch.compose.core.android.test.painter.DrawablePainterTest.testEmptyPainter
|
|
234
|
-
*/
|
|
235
|
-
internal object EmptyPainter : Painter() {
|
|
236
|
-
override val intrinsicSize: Size get() = Size.Unspecified
|
|
237
|
-
override fun DrawScope.onDraw() {}
|
|
238
|
-
}
|