Skip to content
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

Remember the internal image states #633

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ fun DisneyPosters(
PosterItem(poster, vm)
}
}
SelectedPoster(poster)

var palette by rememberPaletteState()

SelectedPoster(poster = poster, onPaletteUpdated = { palette = it })

palette?.let {
PosterInformation(poster = poster, it)
}
}
}

Expand All @@ -131,9 +138,8 @@ private fun PosterItem(
@Composable
private fun SelectedPoster(
poster: Poster,
onPaletteUpdated: (Palette) -> Unit,
) {
var palette by rememberPaletteState(null)

CoilImage(
imageModel = { poster.image },
modifier = Modifier.aspectRatio(0.8f),
Expand All @@ -149,11 +155,17 @@ private fun SelectedPoster(
),
)
+CircularRevealPlugin()
+PalettePlugin { palette = it }
+PalettePlugin { onPaletteUpdated.invoke(it) }
},
previewPlaceholder = painterResource(id = R.drawable.poster),
)
}

@Composable
private fun PosterInformation(
poster: Poster,
palette: Palette,
) {
ColorPalettes(palette)

Text(
Expand Down Expand Up @@ -190,7 +202,7 @@ private fun SelectedPoster(
}

@Composable
private fun ColorPalettes(palette: Palette?) {
private fun ColorPalettes(palette: Palette) {
val colorList: List<Int> = palette.paletteColorList()

LazyRow(
Expand Down Expand Up @@ -224,7 +236,7 @@ private fun SelectedPosterPreview() {
.fillMaxSize()
.verticalScroll(rememberScrollState()),
) {
SelectedPoster(poster = MockUtil.getMockPoster())
SelectedPoster(poster = MockUtil.getMockPoster()) {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ internal fun Project.configureAndroidCompose(
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.5.14"
}

packaging {
resources {
excludes.add("/META-INF/{AL2.0,LGPL2.1}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,14 @@ public fun CoilImage(
imageOptions = imageOptions,
modifier = modifier,
) ImageRequest@{ imageState ->
when (
val coilImageState = imageState.toCoilImageState().apply {

val coilImageState: CoilImageState = remember(imageState) {
imageState.toCoilImageState().apply {
onImageStateChanged.invoke(this)
}
) {
}

when (coilImageState) {
is CoilImageState.None -> Unit

is CoilImageState.Loading -> {
Expand Down
14 changes: 6 additions & 8 deletions coil3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import com.github.skydoves.landscapist.Configuration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("landscapist.library.compose.multiplatformWasm")
Expand Down Expand Up @@ -115,14 +117,10 @@ baselineProfile {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += listOf(
"-Xexplicit-api=strict",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=com.skydoves.landscapist.InternalLandscapistApi",
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.addAll(
"-opt-in=coil3.annotation.ExperimentalCoilApi",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,14 @@ public fun CoilImage(
imageOptions = imageOptions,
modifier = modifier,
) ImageRequest@{ imageState ->
when (
val coilImageState = imageState.toCoilImageState().apply {

val coilImageState: CoilImageState = remember(imageState) {
imageState.toCoilImageState().apply {
onImageStateChanged.invoke(this)
}
) {
}

when (coilImageState) {
is CoilImageState.None -> Unit

is CoilImageState.Loading -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ public fun FrescoImage(
imageRequest = StableHolder(imageRequest.invoke()),
modifier = modifier,
) ImageRequest@{ imageState ->
when (
val frescoImageState = imageState.toFrescoImageState().apply {

val state: FrescoImageState = imageState.toFrescoImageState()
val frescoImageState = remember(state) {
state.apply {
onImageStateChanged.invoke(this)
}
) {
}

when (frescoImageState) {
is FrescoImageState.None -> Unit

is FrescoImageState.Loading -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalInspectionMode
Expand Down Expand Up @@ -149,11 +151,14 @@ public fun GlideImage(
clearTarget = clearTarget,
modifier = modifier,
) ImageRequest@{ imageState ->
when (
val glideImageState = imageState.toGlideImageState(

val glideImageState: GlideImageState = remember(imageState) {
imageState.toGlideImageState(
glideRequestType = glideRequestType,
).apply { onImageStateChanged.invoke(this) }
) {
}

when (glideImageState) {
is GlideImageState.None -> Unit

is GlideImageState.Loading -> {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dokka = "2.0.0"
jvmTarget = "11"
nexusPlugin = "0.30.0"
kotlinxCoroutines = "1.9.0"
kotlinBinaryCompatibility = "0.16.3"
kotlinBinaryCompatibility = "0.17.0"
androidGradlePlugin = "8.7.3"
androidxActivity = "1.9.3"
androidxMaterial = "1.12.0"
Expand Down
10 changes: 6 additions & 4 deletions landscapist-animation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import com.github.skydoves.landscapist.Configuration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("landscapist.library.compose.multiplatformWasm")
Expand Down Expand Up @@ -86,10 +88,10 @@ baselineProfile {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += listOf(
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.addAll(
"-Xexplicit-api=strict",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
Expand Down
10 changes: 6 additions & 4 deletions landscapist-palette/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import com.github.skydoves.landscapist.Configuration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("landscapist.library.compose.multiplatform")
Expand Down Expand Up @@ -81,10 +83,10 @@ baselineProfile {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += listOf(
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.addAll(
"-Xexplicit-api=strict",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import com.kmpalette.palette.graphics.Palette
*/
@Composable
public fun rememberPaletteState(
value: Palette?,
value: Palette? = null,
policy: SnapshotMutationPolicy<Palette?> = structuralEqualityPolicy(),
): MutableState<Palette?> = remember { mutableStateOf(value = value, policy = policy) }
): MutableState<Palette?> = remember(key1 = value) {
mutableStateOf(value = value, policy = policy)
}
10 changes: 6 additions & 4 deletions landscapist-placeholder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import com.github.skydoves.landscapist.Configuration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("landscapist.library.compose.multiplatformWasm")
Expand Down Expand Up @@ -86,10 +88,10 @@ baselineProfile {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += listOf(
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
freeCompilerArgs.addAll(
"-Xexplicit-api=strict",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
Expand Down
15 changes: 6 additions & 9 deletions landscapist/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

import com.github.skydoves.landscapist.Configuration
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
id("landscapist.library.compose.multiplatformWasm")
Expand Down Expand Up @@ -83,14 +85,9 @@ baselineProfile {
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += listOf(
"-Xexplicit-api=strict",
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=com.skydoves.landscapist.InternalLandscapistApi",
)
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public fun <T : Any> ImageLoad(
var state by remember(recomposeKey, imageOptions) {
mutableStateOf<ImageLoadState>(ImageLoadState.None)
}
LaunchedEffect(recomposeKey, imageOptions) {
executeImageLoading(
executeImageRequest,
).collect {

LaunchedEffect(key1 = recomposeKey, key2 = imageOptions) {
executeImageLoading(executeImageRequest).collect {
state = it
}
}

BoxWithConstraints(
modifier = modifier.imageSemantics(imageOptions),
propagateMinConstraints = true,
Expand All @@ -85,7 +85,7 @@ public fun <T : Any> ImageLoad(
}
}

private suspend fun executeImageLoading(
private fun executeImageLoading(
executeImageRequest: suspend () -> Flow<ImageLoadState>,
) = flow {
// execute imager loading
Expand Down