Skip to content

Commit

Permalink
Merge pull request #12 from ObsidianX/master
Browse files Browse the repository at this point in the history
Update to Compose beta01
  • Loading branch information
mvarnagiris authored Feb 27, 2021
2 parents cb246ac + 8a07523 commit 4f3b2bb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
}
Expand Down
9 changes: 4 additions & 5 deletions compose-glide-image/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
}

android {
Expand Down Expand Up @@ -39,8 +38,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion "1.0.0-alpha04"
kotlinCompilerVersion "1.4.10"
kotlinCompilerExtensionVersion "1.0.0-beta01"
}
}

Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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
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
Expand All @@ -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,
Expand All @@ -34,12 +34,12 @@ fun GlideImage(
onImageReady: (() -> Unit)? = null,
customize: RequestBuilder<Bitmap>.() -> RequestBuilder<Bitmap> = { this },
) {
WithConstraints {
var image by remember { mutableStateOf<ImageAsset?>(null) }
BoxWithConstraints {
var image by remember { mutableStateOf<ImageBitmap?>(null) }
var drawable by remember { mutableStateOf<Drawable?>(null) }
val context = ContextAmbient.current
val context = LocalContext.current

onCommit(model) {
DisposableEffect(key1 = url, effect = {
val glide = Glide.with(context)
var target: CustomTarget<Bitmap>? = null
val job = CoroutineScope(Dispatchers.Main).launch {
Expand All @@ -53,8 +53,7 @@ fun GlideImage(
resource: Bitmap,
transition: Transition<in Bitmap>?,
) {
FrameManager.ensureStarted()
image = resource.asImageAsset()
image = resource.asImageBitmap()
onImageReady?.invoke()
}
}
Expand All @@ -68,7 +67,7 @@ fun GlideImage(

glide
.asBitmap()
.load(model)
.load(url)
.override(size.width, size.height)
.let(customize)
.into(target!!)
Expand All @@ -80,7 +79,7 @@ fun GlideImage(
glide.clear(target)
job.cancel()
}
}
})

ActiveImage(
image = image,
Expand All @@ -96,17 +95,19 @@ 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,
colorFilter: ColorFilter? = null,
) {
if (image != null) {
Image(
asset = image,
bitmap = image,
contentDescription = contentDescription,
modifier = modifier,
contentScale = contentScale,
alignment = alignment,
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4f3b2bb

Please sign in to comment.