diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 3cc336b..88ea3aa 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,22 +1,6 @@ - - diff --git a/build.gradle b/build.gradle index 2eb7964..684c881 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ buildscript { - ext.kotlin_version = "1.4.10" + ext.kotlin_version = "1.4.30" repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.0-alpha14' + classpath 'com.android.tools.build:gradle:7.0.0-alpha08' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/compose-glide-image/build.gradle b/compose-glide-image/build.gradle index 1c05468..6fb20cb 100644 --- a/compose-glide-image/build.gradle +++ b/compose-glide-image/build.gradle @@ -1,7 +1,6 @@ plugins { id 'com.android.library' id 'kotlin-android' - id 'kotlin-android-extensions' } android { @@ -39,8 +38,7 @@ android { } composeOptions { - kotlinCompilerExtensionVersion "1.0.0-alpha04" - kotlinCompilerVersion "1.4.10" + kotlinCompilerExtensionVersion "1.0.0-beta01" } } @@ -52,12 +50,13 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } dependencies { - def compose_version = '1.0.0-alpha07' - def coroutines_version = "1.3.9" + def compose_version = '1.0.0-beta01' + def coroutines_version = "1.4.2" implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation "androidx.compose.foundation:foundation:$compose_version" api 'com.github.bumptech.glide:glide:4.11.0' + implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha03" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" diff --git a/compose-glide-image/src/main/java/com/koduok/compose/glideimage/GlideImage.kt b/compose-glide-image/src/main/java/com/koduok/compose/glideimage/GlideImage.kt index 7eb4449..0361093 100644 --- a/compose-glide-image/src/main/java/com/koduok/compose/glideimage/GlideImage.kt +++ b/compose-glide-image/src/main/java/com/koduok/compose/glideimage/GlideImage.kt @@ -4,6 +4,7 @@ import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.compose.foundation.Canvas import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -11,8 +12,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.* import androidx.compose.ui.graphics.drawscope.drawIntoCanvas import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.layout.WithConstraints -import androidx.compose.ui.platform.ContextAmbient +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.IntSize import com.bumptech.glide.Glide import com.bumptech.glide.RequestBuilder @@ -25,7 +25,7 @@ import kotlinx.coroutines.launch @Composable fun GlideImage( - model: Any, + url: String, modifier: Modifier = Modifier, contentScale: ContentScale = ContentScale.Fit, alignment: Alignment = Alignment.Center, @@ -34,12 +34,12 @@ fun GlideImage( onImageReady: (() -> Unit)? = null, customize: RequestBuilder.() -> RequestBuilder = { this }, ) { - WithConstraints { - var image by remember { mutableStateOf(null) } + BoxWithConstraints { + var image by remember { mutableStateOf(null) } var drawable by remember { mutableStateOf(null) } - val context = ContextAmbient.current + val context = LocalContext.current - onCommit(model) { + DisposableEffect(key1 = url, effect = { val glide = Glide.with(context) var target: CustomTarget? = null val job = CoroutineScope(Dispatchers.Main).launch { @@ -53,8 +53,7 @@ fun GlideImage( resource: Bitmap, transition: Transition?, ) { - FrameManager.ensureStarted() - image = resource.asImageAsset() + image = resource.asImageBitmap() onImageReady?.invoke() } } @@ -68,7 +67,7 @@ fun GlideImage( glide .asBitmap() - .load(model) + .load(url) .override(size.width, size.height) .let(customize) .into(target!!) @@ -80,7 +79,7 @@ fun GlideImage( glide.clear(target) job.cancel() } - } + }) ActiveImage( image = image, @@ -96,9 +95,10 @@ fun GlideImage( @Composable private fun ActiveImage( - image: ImageAsset?, + image: ImageBitmap?, drawable: Drawable?, modifier: Modifier = Modifier, + contentDescription: String? = null, contentScale: ContentScale = ContentScale.Fit, alignment: Alignment = Alignment.Center, alpha: Float = DefaultAlpha, @@ -106,7 +106,8 @@ private fun ActiveImage( ) { if (image != null) { Image( - asset = image, + bitmap = image, + contentDescription = contentDescription, modifier = modifier, contentScale = contentScale, alignment = alignment, diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84dc194..15be0f7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-6.7-rc-4-bin.zip +distributionUrl=https://services.gradle.org/distributions/gradle-6.8.2-bin.zip