Skip to content

Commit

Permalink
Merge pull request #14 from chrisbanes/cb/compose-dev12
Browse files Browse the repository at this point in the history
Update to Compose + UI v0.1.0-dev12
  • Loading branch information
chrisbanes authored May 28, 2020
2 parents 349045a + 452e1d0 commit 0f9b6fb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Versions {
}

object Libs {
const val androidGradlePlugin = "com.android.tools.build:gradle:4.1.0-alpha09"
const val androidGradlePlugin = "com.android.tools.build:gradle:4.1.0-alpha10"

const val gradleMavenPublishPlugin = "com.vanniktech:gradle-maven-publish-plugin:0.11.1"

Expand All @@ -46,7 +46,7 @@ object Libs {

object UI {
const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
const val version = "0.1.0-dev11"
const val version = "0.1.0-dev12"

const val composeRuntime = "androidx.compose:compose-runtime:$version"

Expand Down
12 changes: 4 additions & 8 deletions coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ import androidx.ui.graphics.ColorFilter
import androidx.ui.graphics.ImageAsset
import androidx.ui.graphics.Paint
import androidx.ui.graphics.asImageAsset
import androidx.ui.graphics.painter.CanvasScope
import androidx.ui.graphics.drawscope.DrawScope
import androidx.ui.graphics.drawscope.drawCanvas
import androidx.ui.graphics.painter.ImagePainter
import androidx.ui.graphics.painter.Painter
import androidx.ui.graphics.painter.drawCanvas
import androidx.ui.unit.IntPx
import androidx.ui.unit.PxSize
import coil.Coil
import coil.decode.DataSource
import coil.request.GetRequest
Expand Down Expand Up @@ -324,9 +322,7 @@ private class ColorMatrixImagePainter(
private val srcSize: Size = Size(image.width.toFloat(), image.height.toFloat()),
private val colorMatrix: ColorMatrix? = null
) : Painter() {
private val size = PxSize(IntPx(image.width), IntPx(image.height))

override fun CanvasScope.onDraw() {
override fun DrawScope.onDraw() {
val paint = paintPool.acquire() ?: Paint()
paint.asFrameworkPaint().colorFilter = colorMatrix?.let(::ColorMatrixColorFilter)

Expand All @@ -340,7 +336,7 @@ private class ColorMatrixImagePainter(
/**
* Return the dimension of the underlying [Image] as it's intrinsic width and height
*/
override val intrinsicSize: PxSize get() = size
override val intrinsicSize: Size get() = srcSize
}

/**
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 @@ -18,4 +18,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-milestone-1-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import androidx.ui.text.font.asFontFamily
import androidx.ui.text.font.font
import androidx.ui.unit.Density
import androidx.ui.unit.Dp
import androidx.ui.unit.Px
import androidx.ui.unit.PxSize
import androidx.ui.unit.TextUnit
import androidx.ui.unit.dp
import androidx.ui.unit.em
import androidx.ui.unit.px
import androidx.ui.unit.sp
import dev.chrisbanes.accompanist.mdctheme.test.R
import org.junit.Assert.assertEquals
Expand Down Expand Up @@ -83,9 +81,9 @@ class MaterialThemeTest {

shapes.small.run {
assertTrue(this is CutCornerShape)
assertEquals(4.px, topLeft.toPx(density))
assertEquals(4f, topLeft.toPx(density))
assertEquals(9.dp.scaleToPx(density), topRight.toPx(density))
assertEquals(5.px, bottomRight.toPx(density))
assertEquals(5f, bottomRight.toPx(density))
assertEquals(3.dp.scaleToPx(density), bottomLeft.toPx(density))
}
shapes.medium.run {
Expand All @@ -97,10 +95,10 @@ class MaterialThemeTest {
}
shapes.large.run {
assertTrue(this is CutCornerShape)
assertEquals(0.px, topLeft.toPx(density))
assertEquals(0.px, topRight.toPx(density))
assertEquals(0.px, bottomRight.toPx(density))
assertEquals(0.px, bottomLeft.toPx(density))
assertEquals(0f, topLeft.toPx(density))
assertEquals(0f, topRight.toPx(density))
assertEquals(0f, bottomRight.toPx(density))
assertEquals(0f, bottomLeft.toPx(density))
}
}
}
Expand All @@ -126,7 +124,7 @@ class MaterialThemeTest {
assertEquals(colorResource(R.color.OliveDrab), color)
assertEquals(4.43f, offset.dx)
assertEquals(8.19f, offset.dy)
assertEquals(2.13.px, blurRadius)
assertEquals(2.13f, blurRadius)
}

typography.body1.run {
Expand All @@ -143,9 +141,9 @@ class MaterialThemeTest {
}
}

private fun Dp.scaleToPx(density: Density): Px {
private fun Dp.scaleToPx(density: Density): Float {
val dp = this
return with(density) { dp.toPx() }
return with(density) { dp.toPx().value }
}

private fun assertTextUnitEquals(expected: TextUnit, actual: TextUnit, density: Density) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import androidx.ui.unit.Density
import androidx.ui.unit.TextUnit
import androidx.ui.unit.dp
import androidx.ui.unit.em
import androidx.ui.unit.px
import androidx.ui.unit.sp
import java.lang.reflect.Method
import kotlin.concurrent.getOrSet
Expand Down Expand Up @@ -367,7 +366,7 @@ private fun textStyleFromTextAppearance(
val dx = a.getFloat(R.styleable.AccompanistMdcTextAppearance_android_shadowDx, 0f)
val dy = a.getFloat(R.styleable.AccompanistMdcTextAppearance_android_shadowDy, 0f)
val rad = a.getFloat(R.styleable.AccompanistMdcTextAppearance_android_shadowRadius, 0f)
Shadow(color = shadowColor, offset = Offset(dx, dy), blurRadius = rad.px)
Shadow(color = shadowColor, offset = Offset(dx, dy), blurRadius = rad)
} else null
},
letterSpacing = when {
Expand Down Expand Up @@ -557,9 +556,9 @@ private fun TypedArray.getCornerSizeOrNull(index: Int): CornerSize? {
when (tv.complexUnitCompat) {
// For DIP and PX values, we convert the value to the equivalent
TypedValue.COMPLEX_UNIT_DIP -> CornerSize(TypedValue.complexToFloat(tv.data).dp)
TypedValue.COMPLEX_UNIT_PX -> CornerSize(TypedValue.complexToFloat(tv.data).px)
TypedValue.COMPLEX_UNIT_PX -> CornerSize(TypedValue.complexToFloat(tv.data))
// For another other dim types, we let the TypedArray flatten to a px value
else -> CornerSize(getDimensionPixelSize(index, 0).px)
else -> CornerSize(getDimensionPixelSize(index, 0))
}
}
TypedValue.TYPE_FRACTION -> CornerSize(tv.getFraction(1f, 1f))
Expand Down

0 comments on commit 0f9b6fb

Please sign in to comment.