Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose v0.1.0-dev15 #45

Merged
merged 21 commits into from Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 12 additions & 14 deletions build.gradle
Expand Up @@ -21,6 +21,7 @@ buildscript {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap/' }
}

dependencies {
Expand All @@ -41,9 +42,11 @@ subprojects {
mavenCentral()
jcenter()

if (Libs.AndroidX.UI.version.endsWith("SNAPSHOT")) {
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap/' }

if (Libs.AndroidX.Compose.version.endsWith("SNAPSHOT")) {
maven {
url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.UI.snapshot}/artifacts/ui/repository/"
url "https://androidx.dev/snapshots/builds/${Libs.AndroidX.Compose.snapshot}/artifacts/ui/repository/"
}
}
}
Expand All @@ -53,13 +56,13 @@ subprojects {
kotlin {
target "**/*.kt"
ktlint(Versions.ktlint)
licenseHeaderFile project.rootProject.file('spotless/copyright.txt')
licenseHeaderFile rootProject.file('spotless/copyright.txt')
}

groovyGradle {
target '**/*.gradle'
greclipse().configFile(project.rootProject.file('spotless/greclipse.properties'))
licenseHeaderFile project.rootProject.file('spotless/copyright.txt'),
greclipse().configFile(rootProject.file('spotless/greclipse.properties'))
licenseHeaderFile rootProject.file('spotless/copyright.txt'),
'(buildscript|apply|import)'
}
}
Expand All @@ -75,16 +78,11 @@ subprojects {
// Allow use of @OptIn
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"

// Compose is now based on the Kotlin 1.4 compiler, but we need to use the 1.3.x Kotlin
// library due to library compatibility, etc. Therefore we explicit set our apiVersion
// to 1.3 to fix any warnings. Binary dependencies (such as Compose) can continue to
// use 1.4 if built with that library.
// TODO: remove this once we move to Kotlin 1.4
apiVersion = "1.3"
freeCompilerArgs += "-Xallow-jvm-ir-dependencies"

// Don't require parens on fun type annotations e.g. `@Composable~()~ () -> Unit`
// TODO: Remove when we move to Kotlin 1.4
freeCompilerArgs += "-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes"
// Since we're using a pre-release version of the Kotlin compiler, we need
// to disable it's pre-release check
freeCompilerArgs += "-Xskip-prerelease-check"
}
}

Expand Down
Expand Up @@ -28,13 +28,13 @@ object Libs {
const val junit = "junit:junit:4.13"

object Kotlin {
private const val version = "1.3.72"
const val version = "1.4-M3"
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
}

object Coroutines {
private const val version = "1.3.7"
private const val version = "1.3.7-1.4-M3"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
const val test = "org.jetbrains.kotlinx:kotlinx-coroutines-test:$version"
}
Expand All @@ -50,27 +50,20 @@ object Libs {
const val espressoCore = "androidx.test.espresso:espresso-core:3.2.0"
}

object UI {
const val snapshot = "6602655"
const val version = "0.1.0-dev14"

const val core = "androidx.ui:ui-core:$version"
const val foundation = "androidx.ui:ui-foundation:$version"

const val layout = "androidx.ui:ui-layout:$version"
const val material = "androidx.ui:ui-material:$version"

const val animation = "androidx.ui:ui-animation:$version"
const val tooling = "androidx.ui:ui-tooling:$version"
const val livedata = "androidx.ui:ui-livedata:$version"

const val test = "androidx.ui:ui-test:$version"
}

object Compose {
const val version = UI.version
const val kotlinCompilerVersion = "1.3.70-dev-withExperimentalGoogleExtensions-20200424"
const val runtime = "androidx.compose:compose-runtime:$version"
const val snapshot = ""
const val version = "0.1.0-dev15"
const val kotlinCompilerVersion = "1.4.0-dev-withExperimentalGoogleExtensions-20200720"

const val runtime = "androidx.compose.runtime:runtime:$version"
const val foundation = "androidx.compose.foundation:foundation:${version}"
const val layout = "androidx.compose.foundation:foundation-layout:${version}"

const val ui = "androidx.compose.ui:ui:${version}"
const val material = "androidx.compose.material:material:${version}"

const val tooling = "androidx.ui:ui-tooling:${version}"
const val test = "androidx.ui:ui-test:${version}"
}

const val core = "androidx.core:core:1.2.0"
Expand Down
7 changes: 4 additions & 3 deletions coil/build.gradle
Expand Up @@ -75,17 +75,18 @@ dependencies {

implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.Compose.runtime
implementation Libs.AndroidX.UI.foundation
implementation Libs.AndroidX.Compose.foundation

implementation Libs.Kotlin.stdlib
implementation Libs.Coroutines.android

androidTestImplementation Libs.junit
androidTestImplementation Libs.truth

androidTestImplementation Libs.Coroutines.test

androidTestImplementation Libs.AndroidX.UI.test
androidTestImplementation Libs.AndroidX.UI.core
androidTestImplementation Libs.AndroidX.Compose.test
androidTestImplementation Libs.AndroidX.Compose.ui
androidTestImplementation Libs.AndroidX.Test.rules
androidTestImplementation Libs.AndroidX.Test.runner
}
Expand Down
Expand Up @@ -34,9 +34,9 @@ import androidx.ui.test.assertIsDisplayed
import androidx.ui.test.assertPixels
import androidx.ui.test.captureToBitmap
import androidx.ui.test.createComposeRule
import androidx.ui.test.findByTag
import androidx.ui.test.findByText
import androidx.ui.test.runOnIdleCompose
import androidx.ui.test.onNodeWithTag
import androidx.ui.test.onNodeWithText
import androidx.ui.test.runOnIdle
import androidx.ui.unit.dp
import coil.request.CachePolicy
import coil.request.GetRequest
Expand Down Expand Up @@ -81,7 +81,7 @@ class CoilTest {
// Wait for the Coil request listener to release the latch
latch.await(5, TimeUnit.SECONDS)

runOnIdleCompose {
runOnIdle {
// And assert that we got a single successful result
assertThat(results).hasSize(1)
assertThat(results[0]).isInstanceOf(SuccessResult::class.java)
Expand All @@ -103,7 +103,7 @@ class CoilTest {
// Wait for the onRequestCompleted to release the latch
latch.await(5, TimeUnit.SECONDS)

findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertIsDisplayed()
.assertSize(composeTestRule.density, 128.dp, 128.dp)
}
Expand All @@ -124,7 +124,7 @@ class CoilTest {
// Wait for the onRequestCompleted to release the latch
latch.await(5, TimeUnit.SECONDS)

findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertSize(composeTestRule.density, 128.dp, 128.dp)
.assertIsDisplayed()
.captureToBitmap()
Expand Down Expand Up @@ -153,7 +153,7 @@ class CoilTest {
}

// Assert that the content is completely Red
findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertSize(composeTestRule.density, 128.dp, 128.dp)
.assertIsDisplayed()
.captureToBitmap()
Expand All @@ -166,7 +166,7 @@ class CoilTest {
runBlocking { loadCompleteSignal.receive() }

// Assert that the content is completely Blue
findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertSize(composeTestRule.density, 128.dp, 128.dp)
.assertIsDisplayed()
.captureToBitmap()
Expand Down Expand Up @@ -230,7 +230,7 @@ class CoilTest {
latch.await(5, TimeUnit.SECONDS)

// Assert that the whole layout is drawn cyan
findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertIsDisplayed()
.captureToBitmap()
.assertPixels { Color.Cyan }
Expand All @@ -252,7 +252,7 @@ class CoilTest {
latch.await(5, TimeUnit.SECONDS)

// Assert that the layout is in the tree and has the correct size
findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertIsDisplayed()
.assertSize(composeTestRule.density, 128.dp, 128.dp)
}
Expand Down Expand Up @@ -281,15 +281,15 @@ class CoilTest {
}

// Assert that the loading component is displayed
findByText("Loading").assertIsDisplayed()
onNodeWithText("Loading").assertIsDisplayed()

// Now resume the dispatcher to start the Coil request, and wait for the
// request to complete
dispatcher.resumeDispatcher()
latch.await(5, TimeUnit.SECONDS)

// And assert that the loading component no longer exists
findByText("Loading").assertDoesNotExist()
onNodeWithText("Loading").assertDoesNotExist()
}
}

Expand All @@ -314,7 +314,7 @@ class CoilTest {
latch.await(5, TimeUnit.SECONDS)

// Assert that the whole layout is drawn red
findByTag(CoilTestTags.Image)
onNodeWithTag(CoilTestTags.Image)
.assertIsDisplayed()
.captureToBitmap()
.assertPixels { Color.Red }
Expand Down
5 changes: 3 additions & 2 deletions coil/src/main/java/dev/chrisbanes/accompanist/coil/Coil.kt
Expand Up @@ -81,8 +81,9 @@ fun CoilImage(
// pass the request through
is GetRequest -> data
// Otherwise we construct a GetRequest using the data parameter
else -> remember(data) {
GetRequest.Builder(ContextAmbient.current).data(data).build()
else -> {
val context = ContextAmbient.current
remember(data) { GetRequest.Builder(context).data(data).build() }
}
},
alignment = alignment,
Expand Down
26 changes: 12 additions & 14 deletions coil/src/main/java/dev/chrisbanes/accompanist/coil/Crossfade.kt
Expand Up @@ -21,10 +21,11 @@ import androidx.animation.AnimationClockObservable
import androidx.animation.FloatPropKey
import androidx.animation.createAnimation
import androidx.animation.transitionDefinition
import androidx.animation.tween
import androidx.compose.Composable
import androidx.compose.NeverEqual
import androidx.compose.getValue
import androidx.compose.mutableStateOf
import androidx.compose.neverEqualPolicy
import androidx.compose.remember
import androidx.compose.setValue
import androidx.core.util.Pools
Expand All @@ -47,7 +48,6 @@ import coil.Coil
import coil.decode.DataSource
import coil.request.GetRequest
import coil.request.GetRequestBuilder
import kotlin.math.roundToInt

private const val DefaultTransitionDuration = 1000

Expand Down Expand Up @@ -190,7 +190,10 @@ private class ObservableCrossfadeImagePainter(

// Initial matrix is completely transparent. We use the NeverEqual equivalence check since this
// is a mutable entity.
private var matrix by mutableStateOf(ImageLoadingColorMatrix(0f, 0f, 0f), NeverEqual)
private var matrix by mutableStateOf(
value = ImageLoadingColorMatrix(0f, 0f, 0f),
policy = neverEqualPolicy()
)

private val animation = CrossfadeTransition.definition(duration).createAnimation(clock)

Expand Down Expand Up @@ -264,17 +267,12 @@ private object CrossfadeTransition {
}

transition {
Alpha using tween<Float> {
// Alpha animation runs over the first 50%
duration = durationMs / 2
}
Brightness using tween<Float> {
// Brightness animation runs over the first 75%
duration = (durationMs * 0.75f).roundToInt()
}
Saturation using tween<Float> {
duration = durationMs
}
// Alpha animates over the first 50%
Alpha using tween(durationMillis = durationMs / 2)
// Brightness animates over the first 75%
Brightness using tween(durationMillis = durationMs * 3 / 4)
// Saturation animates over whole duration
Saturation using tween(durationMillis = durationMs)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions mdc-theme/build.gradle
Expand Up @@ -68,7 +68,7 @@ android {
dependencies {
implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.Compose.runtime
implementation Libs.AndroidX.UI.material
implementation Libs.AndroidX.Compose.material

implementation Libs.mdc
// We need to force AppCompat v1.3.0-alpha01 for AppCompatActivity to work with Compose
Expand All @@ -77,8 +77,8 @@ dependencies {
implementation Libs.Kotlin.stdlib

androidTestImplementation Libs.junit
androidTestImplementation Libs.AndroidX.UI.test
androidTestImplementation Libs.AndroidX.UI.core
androidTestImplementation Libs.AndroidX.Compose.test
androidTestImplementation Libs.AndroidX.Compose.ui
androidTestImplementation Libs.AndroidX.Test.rules
androidTestImplementation Libs.AndroidX.Test.runner
}
Expand Down