Skip to content

Commit

Permalink
Merge pull request #8 from husseinala/update-compose
Browse files Browse the repository at this point in the history
Update Compose to 1.0.0-alpha12
  • Loading branch information
husseinala authored Feb 21, 2021
2 parents 0948c9c + bcf4dfb commit 72135d2
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 38 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ allprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += ["-Xallow-jvm-ir-dependencies"]
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions buildSrc/src/main/java/com/husseinala/neon/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand Down
20 changes: 9 additions & 11 deletions core/src/main/java/com/husseinala/neon/core/Neon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ImageLoader>()
val LocalImageLoader = staticCompositionLocalOf<ImageLoader>()

@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
Expand Down Expand Up @@ -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.
Expand All @@ -140,7 +138,7 @@ fun LoadImage(
onLoaded: (ImageBitmap) -> Unit,
onFailure: (Throwable) -> Unit
) {
val imageLoader = AmbientImageLoader.current
val imageLoader = LocalImageLoader.current

DisposableEffect(
imageConfig,
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions glide/src/main/java/com/husseinala/neon/glide/Glide.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +84,7 @@ private fun RequestCreator.fetch(
}

override fun onBitmapLoaded(bitmap: Bitmap, from: Picasso.LoadedFrom?) {
onSuccess(bitmap.asImageAsset())
onSuccess(bitmap.asImageBitmap())
}
}

Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 17 additions & 13 deletions sample/src/main/java/com/husseinala/neon/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 72135d2

Please sign in to comment.