diff --git a/build.gradle b/build.gradle index 4cd747f..7f59d9e 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,6 @@ allprojects { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { jvmTarget = "1.8" - freeCompilerArgs += ["-Xallow-jvm-ir-dependencies"] } } } diff --git a/buildSrc/src/main/java/com/husseinala/neon/Dependencies.kt b/buildSrc/src/main/java/com/husseinala/neon/Dependencies.kt index a28ad3b..5083d74 100644 --- a/buildSrc/src/main/java/com/husseinala/neon/Dependencies.kt +++ b/buildSrc/src/main/java/com/husseinala/neon/Dependencies.kt @@ -8,11 +8,11 @@ object Versions { const val TARGET_SDK = 29 // Kotlin - const val KOTLIN = "1.4.21-2" + const val KOTLIN = "1.4.30" const val DOKKA = "1.4.0" // Compose - const val COMPOSE = "1.0.0-alpha11" + const val COMPOSE = "1.0.0-alpha12" // Spotless const val KT_LINT = "0.40.0" @@ -27,13 +27,13 @@ object Deps { } object Android { - const val GRADLE_PLUGIN = "com.android.tools.build:gradle:7.0.0-alpha05" + const val GRADLE_PLUGIN = "com.android.tools.build:gradle:7.0.0-alpha07" } object AndroidX { const val CORE = "androidx.core:core-ktx:1.3.2" - const val APPCOMPAT = "androidx.appcompat:appcompat:1.2.0" const val MATERIAL = "com.google.android.material:material:1.3.0" + const val ACTIVITY_COMPOSE = "androidx.activity:activity-compose:1.3.0-alpha02" } object Compose { diff --git a/core/src/main/java/com/husseinala/neon/core/DefaultTransformations.kt b/core/src/main/java/com/husseinala/neon/core/DefaultTransformations.kt index d0e133f..a4c6c7d 100644 --- a/core/src/main/java/com/husseinala/neon/core/DefaultTransformations.kt +++ b/core/src/main/java/com/husseinala/neon/core/DefaultTransformations.kt @@ -1,7 +1,7 @@ package com.husseinala.neon.core import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.AmbientDensity +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.Dp import kotlin.math.roundToInt @@ -48,7 +48,7 @@ fun Transformation.roundedCorners(radius: Dp) = this + RoundedCornersTransformation(radius.toPx().roundToInt()) @Composable -private fun Dp.toPx() = AmbientDensity.current.density * value +private fun Dp.toPx() = LocalDensity.current.density * value object CircleCropTransformation : Transformation diff --git a/core/src/main/java/com/husseinala/neon/core/Neon.kt b/core/src/main/java/com/husseinala/neon/core/Neon.kt index 443b0e1..72eb477 100644 --- a/core/src/main/java/com/husseinala/neon/core/Neon.kt +++ b/core/src/main/java/com/husseinala/neon/core/Neon.kt @@ -10,7 +10,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.runtime.staticAmbientOf +import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ImageBitmap @@ -21,18 +21,16 @@ import androidx.compose.ui.unit.IntSize /** * Provides an [ImageLoader] that can be used by the [Neon] and [LoadImage] composables to fetch images. */ -val AmbientImageLoader = staticAmbientOf() +val LocalImageLoader = staticCompositionLocalOf() -@Suppress("AmbientNaming") @Deprecated( - "Renamed to AmbientImageLoader", + "Renamed to LocalImageLoader", replaceWith = ReplaceWith( - "AmbientImageLoader", - "com.husseinala.neon.core.AmbientImageLoader" + "LocalImageLoader", + "com.husseinala.neon.core.LocalImageLoader" ) ) -val ImageLoaderAmbient - get() = AmbientImageLoader +val AmbientImageLoader get() = LocalImageLoader /** * A composable that downloads and display an image using the specified [url]. This will attempt @@ -129,7 +127,7 @@ fun Neon( /** * A composable that downloads an image with the specified [ImageConfig] using the [ImageLoader] - * provided by the [AmbientImageLoader]. + * provided by the [LocalImageLoader]. * * @param onLoaded Callback invoked when an image has been successfully downloaded. * @param onFailure Callback invoked when an error occurs while downloading the specified image. @@ -140,7 +138,7 @@ fun LoadImage( onLoaded: (ImageBitmap) -> Unit, onFailure: (Throwable) -> Unit ) { - val imageLoader = AmbientImageLoader.current + val imageLoader = LocalImageLoader.current DisposableEffect( imageConfig, @@ -163,5 +161,5 @@ fun LoadImage( */ @Composable fun ProvideImageLoader(imageLoader: ImageLoader, children: @Composable () -> Unit) { - Providers(AmbientImageLoader provides imageLoader, content = children) + Providers(LocalImageLoader provides imageLoader, content = children) } diff --git a/glide/src/main/java/com/husseinala/neon/glide/Glide.kt b/glide/src/main/java/com/husseinala/neon/glide/Glide.kt index 2ec5cab..af78afe 100644 --- a/glide/src/main/java/com/husseinala/neon/glide/Glide.kt +++ b/glide/src/main/java/com/husseinala/neon/glide/Glide.kt @@ -1,7 +1,7 @@ package com.husseinala.neon.glide import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.AmbientContext +import androidx.compose.ui.platform.LocalContext import com.bumptech.glide.Glide import com.bumptech.glide.RequestManager import com.husseinala.neon.core.ImageLoader @@ -10,7 +10,7 @@ import com.husseinala.neon.core.Neon import com.husseinala.neon.core.ProvideImageLoader @Composable -private fun context() = AmbientContext.current +private fun context() = LocalContext.current /** * This composable is used to set the current value of the [ImageLoader] ambient to a diff --git a/glide/src/main/java/com/husseinala/neon/glide/GlideImageLoader.kt b/glide/src/main/java/com/husseinala/neon/glide/GlideImageLoader.kt index 4a81aae..753429a 100644 --- a/glide/src/main/java/com/husseinala/neon/glide/GlideImageLoader.kt +++ b/glide/src/main/java/com/husseinala/neon/glide/GlideImageLoader.kt @@ -3,7 +3,7 @@ package com.husseinala.neon.glide import android.os.Handler import android.os.Looper import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.asImageAsset +import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.unit.IntSize import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestManager @@ -59,7 +59,7 @@ class GlideImageLoader( .load(imageConfig.id.value) .apply(requestOptions) .listener( - onSuccess = { onSuccess(it.asImageAsset()) }, + onSuccess = { onSuccess(it.asImageBitmap()) }, onFailure = onFailure ) .submit(size.width, size.height) diff --git a/picasso/src/main/java/com/husseinala/neon/picasso/PicassoImageLoader.kt b/picasso/src/main/java/com/husseinala/neon/picasso/PicassoImageLoader.kt index 1a2cd24..3296e37 100644 --- a/picasso/src/main/java/com/husseinala/neon/picasso/PicassoImageLoader.kt +++ b/picasso/src/main/java/com/husseinala/neon/picasso/PicassoImageLoader.kt @@ -3,7 +3,7 @@ package com.husseinala.neon.picasso import android.graphics.Bitmap import android.graphics.drawable.Drawable import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.asImageAsset +import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.unit.IntSize import com.husseinala.neon.core.Cancelable import com.husseinala.neon.core.CircleCropTransformation @@ -84,7 +84,7 @@ private fun RequestCreator.fetch( } override fun onBitmapLoaded(bitmap: Bitmap, from: Picasso.LoadedFrom?) { - onSuccess(bitmap.asImageAsset()) + onSuccess(bitmap.asImageBitmap()) } } diff --git a/sample/build.gradle b/sample/build.gradle index 80f61b5..78e83d9 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -53,7 +53,7 @@ dependencies { implementation Deps.Kotlin.STD_LIB implementation Deps.AndroidX.CORE - implementation Deps.AndroidX.APPCOMPAT + implementation Deps.AndroidX.ACTIVITY_COMPOSE implementation Deps.AndroidX.MATERIAL implementation Deps.Compose.FOUNDATION diff --git a/sample/src/main/java/com/husseinala/neon/sample/MainActivity.kt b/sample/src/main/java/com/husseinala/neon/sample/MainActivity.kt index a5d9147..68e4eb5 100644 --- a/sample/src/main/java/com/husseinala/neon/sample/MainActivity.kt +++ b/sample/src/main/java/com/husseinala/neon/sample/MainActivity.kt @@ -1,21 +1,21 @@ package com.husseinala.neon.sample import android.os.Bundle +import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumnFor +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.Scaffold import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.runtime.Composable -import androidx.compose.runtime.emptyContent import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.setContent import androidx.compose.ui.unit.dp import com.bumptech.glide.RequestManager import com.husseinala.neon.core.Neon @@ -55,21 +55,25 @@ fun SampleScreen(title: String) { Scaffold( topBar = { TopAppBar(title = { Text(text = title) }) } ) { - LazyColumnFor(items = Samples.images) { url -> - Neon( - url = url, - transformation = Transformation.centerCrop().roundedCorners(radius = 16.dp), - modifier = Modifier.fillParentMaxWidth().aspectRatio(1.7f) - .padding(horizontal = 16.dp, vertical = 8.dp), - onLoading = { Center { CircularProgressIndicator() } } - ) + LazyColumn { + items(Samples.images) { url -> + Neon( + url = url, + transformation = Transformation.centerCrop().roundedCorners(radius = 16.dp), + modifier = Modifier + .fillParentMaxWidth() + .aspectRatio(1.7f) + .padding(horizontal = 16.dp, vertical = 8.dp), + onLoading = { Center { CircularProgressIndicator() } } + ) + } } } } @Composable -fun Center(children: @Composable () -> Unit = emptyContent()) { - Box(modifier = Modifier.fillMaxSize()) { +fun Center(children: @Composable () -> Unit = { }) { + Box(modifier = Modifier.fillMaxSize()) { Box(modifier = Modifier.align(Alignment.Center)) { children() }