From 397c05fc61edd787a89ae4cc13596adf55f28d06 Mon Sep 17 00:00:00 2001 From: Andrey Kulikov Date: Tue, 11 Oct 2022 14:59:55 +0100 Subject: [PATCH] Revert "[DrawablePainter] Fix overwriting bounds of drawable when drawing it via DrawablePainter" --- drawablepainter/build.gradle | 26 ------ .../drawablepainter/DrawablePainterTest.kt | 88 ------------------- .../accompanist/drawablepainter/Drawables.kt | 40 --------- .../drawablepainter/DrawablePainter.kt | 6 +- 4 files changed, 2 insertions(+), 158 deletions(-) delete mode 100644 drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/DrawablePainterTest.kt delete mode 100644 drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/Drawables.kt diff --git a/drawablepainter/build.gradle b/drawablepainter/build.gradle index 625e43103..3c15fc2bb 100644 --- a/drawablepainter/build.gradle +++ b/drawablepainter/build.gradle @@ -66,32 +66,6 @@ android { dependencies { implementation libs.compose.ui.ui implementation libs.kotlin.coroutines.android - - // ====================== - // Test dependencies - // ====================== - - androidTestImplementation libs.compose.foundation.foundation - - androidTestImplementation project(':internal-testutils') - testImplementation project(':internal-testutils') - - androidTestImplementation libs.junit - testImplementation libs.junit - - androidTestImplementation libs.truth - testImplementation libs.truth - - androidTestImplementation libs.compose.ui.test.junit4 - testImplementation libs.compose.ui.test.junit4 - - androidTestImplementation libs.compose.ui.test.manifest - testImplementation libs.compose.ui.test.manifest - - androidTestImplementation libs.androidx.test.runner - testImplementation libs.androidx.test.runner - - testImplementation libs.robolectric } apply plugin: "com.vanniktech.maven.publish" diff --git a/drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/DrawablePainterTest.kt b/drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/DrawablePainterTest.kt deleted file mode 100644 index 354b65e6c..000000000 --- a/drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/DrawablePainterTest.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.accompanist.drawablepainter - -import android.graphics.drawable.Drawable -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width -import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.test.junit4.createComposeRule -import androidx.compose.ui.test.onNodeWithTag -import androidx.compose.ui.unit.dp -import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.google.common.truth.Truth.assertThat -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class DrawablePainterTest { - @get:Rule - val rule = createComposeRule() - - @Test - fun drawableWithIntrinsicSize() { - lateinit var drawable: Drawable - rule.setContent { - with(LocalDensity.current) { - drawable = IntrinsicSizeDrawable( - width = 128.dp.roundToPx(), - height = 32.dp.roundToPx() - ) - } - Image( - modifier = Modifier.width(256.dp), - painter = rememberDrawablePainter(drawable = drawable), - contentDescription = null, - contentScale = ContentScale.FillWidth, - ) - } - - rule.waitForIdle() - assertThat(drawable.bounds.width()).isEqualTo(drawable.intrinsicWidth) - assertThat(drawable.bounds.height()).isEqualTo(drawable.intrinsicHeight) - } - - @Test - fun drawableWithoutIntrinsicSize() { - val drawable = NoIntrinsicSizeDrawable() - rule.setContent { - Image( - modifier = Modifier - .width(128.dp) - .height(64.dp) - .testTag(TestTag), - painter = rememberDrawablePainter(drawable = drawable), - contentDescription = null, - contentScale = ContentScale.FillWidth, - ) - } - - rule.waitForIdle() - val imageSize = rule.onNodeWithTag(TestTag).fetchSemanticsNode().size - assertThat(drawable.bounds.width()).isEqualTo(imageSize.width) - assertThat(drawable.bounds.height()).isEqualTo(imageSize.height) - } - - private companion object { - const val TestTag = "ImageItem" - } -} diff --git a/drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/Drawables.kt b/drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/Drawables.kt deleted file mode 100644 index 519c5a501..000000000 --- a/drawablepainter/src/androidTest/kotlin/com/google/accompanist/drawablepainter/Drawables.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.accompanist.drawablepainter - -import android.graphics.Canvas -import android.graphics.ColorFilter -import android.graphics.PixelFormat -import android.graphics.drawable.Drawable - -class NoIntrinsicSizeDrawable : IntrinsicSizeDrawable(-1, -1) - -open class IntrinsicSizeDrawable(val width: Int, val height: Int) : Drawable() { - - override fun getIntrinsicWidth(): Int = width - - override fun getIntrinsicHeight(): Int = height - - override fun draw(canvas: Canvas) = Unit - - override fun setAlpha(alpha: Int) = Unit - - override fun setColorFilter(colorFilter: ColorFilter?) = Unit - - @Deprecated("Deprecated in Java") - override fun getOpacity(): Int = PixelFormat.TRANSLUCENT -} diff --git a/drawablepainter/src/main/java/com/google/accompanist/drawablepainter/DrawablePainter.kt b/drawablepainter/src/main/java/com/google/accompanist/drawablepainter/DrawablePainter.kt index b40d7e68b..319b9a6b3 100644 --- a/drawablepainter/src/main/java/com/google/accompanist/drawablepainter/DrawablePainter.kt +++ b/drawablepainter/src/main/java/com/google/accompanist/drawablepainter/DrawablePainter.kt @@ -130,10 +130,8 @@ class DrawablePainter( // Reading this ensures that we invalidate when invalidateDrawable() is called drawInvalidateTick - // Update the Drawable's bounds if necessary - if (drawable.bounds.isEmpty) { - drawable.setBounds(0, 0, size.width.roundToInt(), size.height.roundToInt()) - } + // Update the Drawable's bounds + drawable.setBounds(0, 0, size.width.roundToInt(), size.height.roundToInt()) canvas.withSave { drawable.draw(canvas.nativeCanvas)