diff --git a/README.md b/README.md index 2d6845c12..169b9a73f 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,6 @@ See our [Migration Guide](https://google.github.io/accompanist/navigation-animat ### 🧭🎨️ [Navigation-Material](./navigation-material/) (Deprecated) See our [Migration Guide](https://google.github.io/accompanist/navigation-material/) for migrating to using built in material-navigation support. -### ⏳ [Placeholder](./placeholder/) (Deprecated) -A library that provides easy-to-use modifiers for displaying a placeholder UI while content is loading. - ### 🍫 [System UI Controller](./systemuicontroller/) (Deprecated) We recommend migrating to edge to edge. See our [Migration Guide](https://google.github.io/accompanist/systemuicontroller/) for more details. diff --git a/docs/placeholder.md b/docs/placeholder.md deleted file mode 100644 index 9fa8a76bd..000000000 --- a/docs/placeholder.md +++ /dev/null @@ -1,212 +0,0 @@ -# Placeholder - -[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-placeholder)](https://search.maven.org/search?q=g:com.google.accompanist) - -!!! warning - **This library is deprecated, and the API is no longer maintained. We recommend forking the implementation and customising it to your needs.** The original documentation is below. - -A library which provides a [modifier][modifier] for display 'placeholder' UI while content is loading. - -More information on the UX provided by this library can be found on the Material Theming [Placeholder UI](https://material.io/design/communication/launch-screen.html#placeholder-ui) guidelines. - -There are actually two versions of the library available: - -* *Placeholder Foundation*: Provides the base functionality and depends on Jetpack Compose Foundation. This version requires the app to provide all of the colors to display. -* *Placeholder Material*. This uses the foundation library above, but also provides sensible default colors using your app's Material color palette. - -!!! tip - You only need to use one of the libraries, and most apps should use **Placeholder Material**. The APIs of the libraries are (mostly) equivalent with only the imports being different. Where possible we have provided equivalent code samples below. - -## Basic usage - -At the most basic usage, the modifier will draw a shape over your composable content, filled with the provided color. - -![Basic Placeholder demo](basic.jpg) - -=== "Placeholder Material" - - ``` kotlin - import com.google.accompanist.placeholder.material.placeholder - - Text( - text = "Content to display after content has loaded", - modifier = Modifier - .padding(16.dp) - .placeholder(visible = true) - ) - ``` - -=== "Placeholder Foundation" - - ``` kotlin - import com.google.accompanist.placeholder.placeholder - - Text( - text = "Content to display after content has loaded", - modifier = Modifier - .padding(16.dp) - .placeholder( - visible = true, - color = Color.Gray, - // optional, defaults to RectangleShape - shape = RoundedCornerShape(4.dp), - ) - ) - ``` - -## Placeholder highlights - -The library also provides some 'highlight' animations to entertain the user while they are waiting. There are two provided by the library, but you can also provide your own. - -### Fade - -This highlight fades a color over the entire placeholder in and out. - -
- -
Placeholder Fade demo
-
- -=== "Placeholder Material" - - ``` kotlin - import com.google.accompanist.placeholder.PlaceholderHighlight - import com.google.accompanist.placeholder.material.placeholder - import com.google.accompanist.placeholder.material.fade - - Text( - text = "Content to display after content has loaded", - modifier = Modifier - .padding(16.dp) - .placeholder( - visible = true, - highlight = PlaceholderHighlight.fade(), - ) - ) - ``` - -=== "Placeholder Foundation" - - ``` kotlin - import com.google.accompanist.placeholder.PlaceholderHighlight - import com.google.accompanist.placeholder.placeholder - import com.google.accompanist.placeholder.fade - - Text( - text = "Content to display after content has loaded", - modifier = Modifier - .padding(16.dp) - .placeholder( - visible = true, - color = Color.Gray, - // optional, defaults to RectangleShape - shape = RoundedCornerShape(4.dp), - highlight = PlaceholderHighlight.fade( - highlightColor = Color.White, - ), - ) - ) - ``` - -### Shimmer - -This displays a gradient shimmer effect which emanates from the top-start corner. - -
- -
Placeholder Shimmer demo
-
- -=== "Placeholder Material" - - ``` kotlin - import com.google.accompanist.placeholder.PlaceholderHighlight - import com.google.accompanist.placeholder.material.placeholder - import com.google.accompanist.placeholder.material.shimmer - - Text( - text = "Content to display after content has loaded", - modifier = Modifier - .padding(16.dp) - .placeholder( - visible = true, - highlight = PlaceholderHighlight.shimmer(), - ) - ) - ``` - -=== "Placeholder Foundation" - - ``` kotlin - import com.google.accompanist.placeholder.PlaceholderHighlight - import com.google.accompanist.placeholder.placeholder - import com.google.accompanist.placeholder.shimmer - - Text( - text = "Content to display after content has loaded", - modifier = Modifier - .padding(16.dp) - .placeholder( - visible = true, - color = Color.Gray, - // optional, defaults to RectangleShape - shape = RoundedCornerShape(4.dp), - highlight = PlaceholderHighlight.shimmer( - highlightColor = Color.White, - ), - ) - ) - ``` - -## Usage - -``` groovy -repositories { - mavenCentral() -} - -dependencies { - // If you're using Material, use accompanist-placeholder-material - implementation "com.google.accompanist:accompanist-placeholder-material:" - - // Otherwise use the foundation version - implementation "com.google.accompanist:accompanist-placeholder:" -} -``` - -### Library Snapshots - -Snapshots of the current development version of this library are available, which track the latest commit. See [here](../using-snapshot-version) for more information on how to use them. - ---- - -## Contributions - -Please contribute! We will gladly review any pull requests. -Make sure to read the [Contributing](../contributing) page first though. - -## License - -``` -Copyright 2021 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. -``` - - [modifier]: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier diff --git a/docs/placeholder/basic.jpg b/docs/placeholder/basic.jpg deleted file mode 100644 index cdd3111b1..000000000 Binary files a/docs/placeholder/basic.jpg and /dev/null differ diff --git a/docs/placeholder/fade.mp4 b/docs/placeholder/fade.mp4 deleted file mode 100644 index 824143d62..000000000 Binary files a/docs/placeholder/fade.mp4 and /dev/null differ diff --git a/docs/placeholder/shimmer.mp4 b/docs/placeholder/shimmer.mp4 deleted file mode 100644 index d216f63c6..000000000 Binary files a/docs/placeholder/shimmer.mp4 and /dev/null differ diff --git a/mkdocs.yml b/mkdocs.yml index 596923a94..1dc0331d0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -21,10 +21,6 @@ nav: - 'System UI Controller': - 'Guide': systemuicontroller.md - 'API': api/systemuicontroller/ - - 'Placeholder': - - 'Guide': placeholder.md - - 'Foundation API': api/placeholder/ - - 'Material API': api/placeholder-material/ - 'Drawable Painter': - 'Guide': drawablepainter.md - 'API': api/drawablepainter/ diff --git a/placeholder-material/README.md b/placeholder-material/README.md deleted file mode 100644 index 3a3675aea..000000000 --- a/placeholder-material/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Placeholder for Jetpack Compose (Material) - -[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-placeholder)](https://search.maven.org/search?q=g:com.google.accompanist) - -For more information, visit the documentation: https://google.github.io/accompanist/placeholder - -## Download - -```groovy -repositories { - mavenCentral() -} - -dependencies { - implementation "com.google.accompanist:accompanist-placeholder-material:" -} -``` - -Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit. - - [snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/accompanist-placeholder-material/ \ No newline at end of file diff --git a/placeholder-material/api/current.api b/placeholder-material/api/current.api deleted file mode 100644 index f211fe9fb..000000000 --- a/placeholder-material/api/current.api +++ /dev/null @@ -1,17 +0,0 @@ -// Signature format: 4.0 -package com.google.accompanist.placeholder.material { - - public final class PlaceholderHighlightKt { - method @Deprecated @androidx.compose.runtime.Composable public static com.google.accompanist.placeholder.PlaceholderHighlight fade(com.google.accompanist.placeholder.PlaceholderHighlight.Companion, optional androidx.compose.animation.core.InfiniteRepeatableSpec animationSpec); - method @Deprecated @androidx.compose.runtime.Composable public static com.google.accompanist.placeholder.PlaceholderHighlight shimmer(com.google.accompanist.placeholder.PlaceholderHighlight.Companion, optional androidx.compose.animation.core.InfiniteRepeatableSpec animationSpec, optional @FloatRange(from=0.0, to=1.0) float progressForMaxAlpha); - } - - public final class PlaceholderKt { - method @Deprecated @androidx.compose.runtime.Composable public static long color(com.google.accompanist.placeholder.PlaceholderDefaults, optional long backgroundColor, optional long contentColor, optional float contentAlpha); - method @Deprecated @androidx.compose.runtime.Composable public static long fadeHighlightColor(com.google.accompanist.placeholder.PlaceholderDefaults, optional long backgroundColor, optional float alpha); - method @Deprecated public static androidx.compose.ui.Modifier placeholder(androidx.compose.ui.Modifier, boolean visible, optional long color, optional androidx.compose.ui.graphics.Shape? shape, optional com.google.accompanist.placeholder.PlaceholderHighlight? highlight, optional kotlin.jvm.functions.Function1,? extends androidx.compose.animation.core.FiniteAnimationSpec> placeholderFadeTransitionSpec, optional kotlin.jvm.functions.Function1,? extends androidx.compose.animation.core.FiniteAnimationSpec> contentFadeTransitionSpec); - method @Deprecated @androidx.compose.runtime.Composable public static long shimmerHighlightColor(com.google.accompanist.placeholder.PlaceholderDefaults, optional long backgroundColor, optional float alpha); - } - -} - diff --git a/placeholder-material/build.gradle.kts b/placeholder-material/build.gradle.kts deleted file mode 100644 index 32f712cc4..000000000 --- a/placeholder-material/build.gradle.kts +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2023 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. - */ -@file:Suppress("UnstableApiUsage") - -plugins { - id(libs.plugins.android.library.get().pluginId) - id(libs.plugins.android.kotlin.get().pluginId) - id(libs.plugins.jetbrains.dokka.get().pluginId) - id(libs.plugins.gradle.metalava.get().pluginId) - id(libs.plugins.vanniktech.maven.publish.get().pluginId) -} - -kotlin { - explicitApi() -} - -android { - namespace = "com.google.accompanist.placeholder.material" - - compileSdk = 34 - - defaultConfig { - minSdk = 21 - // targetSdkVersion has no effect for libraries. This is only used for the test APK - targetSdk = 33 - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - buildFeatures { - buildConfig = false - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() - } - - lint { - textReport = true - textOutput = File("stdout") - // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks - checkReleaseBuilds = false - disable += setOf("GradleOverrides") - } - - packaging { - // Some of the META-INF files conflict with coroutines-test. Exclude them to enable - // our test APK to build (has no effect on our AARs) - resources { - excludes += listOf("/META-INF/AL2.0", "/META-INF/LGPL2.1") - } - } - - testOptions { - unitTests { - isIncludeAndroidResources = true - } - animationsDisabled = true - } -} - -metalava { - sourcePaths.setFrom("src/main") - filename.set("api/current.api") - reportLintsAsErrors.set(true) -} - -dependencies { - implementation(libs.compose.material.material) - api(project(":placeholder")) - - implementation(libs.kotlin.coroutines.android) - - // ====================== - // Test dependencies - // ====================== - - androidTestImplementation(libs.junit) - androidTestImplementation(libs.truth) - - androidTestImplementation(libs.compose.ui.test.junit4) - androidTestImplementation(libs.compose.ui.test.manifest) - androidTestImplementation(libs.compose.foundation.foundation) - - androidTestImplementation(libs.androidx.test.core) - androidTestImplementation(libs.androidx.test.rules) - androidTestImplementation(libs.androidx.test.runner) -} diff --git a/placeholder-material/gradle.properties b/placeholder-material/gradle.properties deleted file mode 100644 index 7d226f9ba..000000000 --- a/placeholder-material/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_ARTIFACT_ID=accompanist-placeholder-material -POM_NAME=Accompanist Placeholder Material -POM_PACKAGING=aar \ No newline at end of file diff --git a/placeholder-material/src/main/AndroidManifest.xml b/placeholder-material/src/main/AndroidManifest.xml deleted file mode 100644 index 928e8bf1f..000000000 --- a/placeholder-material/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - diff --git a/placeholder-material/src/main/java/com/google/accompanist/placeholder/material/Placeholder.kt b/placeholder-material/src/main/java/com/google/accompanist/placeholder/material/Placeholder.kt deleted file mode 100644 index c609afc46..000000000 --- a/placeholder-material/src/main/java/com/google/accompanist/placeholder/material/Placeholder.kt +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder.material - -import androidx.compose.animation.core.FiniteAnimationSpec -import androidx.compose.animation.core.Transition -import androidx.compose.animation.core.spring -import androidx.compose.material.MaterialTheme -import androidx.compose.material.contentColorFor -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.composed -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.graphics.compositeOver -import androidx.compose.ui.graphics.isSpecified -import com.google.accompanist.placeholder.PlaceholderDefaults -import com.google.accompanist.placeholder.PlaceholderHighlight -import com.google.accompanist.placeholder.placeholder - -/** - * Returns the value used as the the `color` parameter value on [Modifier.placeholder]. - * - * @param backgroundColor The current background color of the layout. Defaults to - * `MaterialTheme.colors.surface`. - * @param contentColor The content color to be used on top of [backgroundColor]. - * @param contentAlpha The alpha component to set on [contentColor] when compositing the color - * on top of [backgroundColor]. Defaults to `0.1f`. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderDefaults.color( - backgroundColor: Color = MaterialTheme.colors.surface, - contentColor: Color = contentColorFor(backgroundColor), - contentAlpha: Float = 0.1f, -): Color = contentColor.copy(contentAlpha).compositeOver(backgroundColor) - -/** - * Returns the value used as the the `highlightColor` parameter value of - * [PlaceholderHighlight.Companion.fade]. - * - * @param backgroundColor The current background color of the layout. Defaults to - * `MaterialTheme.colors.surface`. - * @param alpha The alpha component to set on [backgroundColor]. Defaults to `0.3f`. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderDefaults.fadeHighlightColor( - backgroundColor: Color = MaterialTheme.colors.surface, - alpha: Float = 0.3f, -): Color = backgroundColor.copy(alpha = alpha) - -/** - * Returns the value used as the the `highlightColor` parameter value of - * [PlaceholderHighlight.Companion.shimmer]. - * - * @param backgroundColor The current background color of the layout. Defaults to - * `MaterialTheme.colors.surface`. - * @param alpha The alpha component to set on [backgroundColor]. Defaults to `0.75f`. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderDefaults.shimmerHighlightColor( - backgroundColor: Color = MaterialTheme.colors.surface, - alpha: Float = 0.75f, -): Color { - return backgroundColor.copy(alpha = alpha) -} - -/** - * Draws some skeleton UI which is typically used whilst content is 'loading'. - * - * To customize the color and shape of the placeholder, you can use the foundation version of - * [Modifier.placeholder], along with the values provided by [PlaceholderDefaults]. - * - * A cross-fade transition will be applied to the content and placeholder UI when the [visible] - * value changes. The transition can be customized via the [contentFadeTransitionSpec] and - * [placeholderFadeTransitionSpec] parameters. - * - * You can provide a [PlaceholderHighlight] which runs an highlight animation on the placeholder. - * The [shimmer] and [fade] implementations are provided for easy usage. - * - * You can find more information on the pattern at the Material Theming - * [Placeholder UI](https://material.io/design/communication/launch-screen.html#placeholder-ui) - * guidelines. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Material_Placeholder - * - * @param visible whether the placeholder should be visible or not. - * @param color the color used to draw the placeholder UI. If [Color.Unspecified] is provided, - * the placeholder will use [PlaceholderDefaults.color]. - * @param shape desired shape of the placeholder. If null is provided the placeholder - * will use the small shape set in [MaterialTheme.shapes]. - * @param highlight optional highlight animation. - * @param placeholderFadeTransitionSpec The transition spec to use when fading the placeholder - * on/off screen. The boolean parameter defined for the transition is [visible]. - * @param contentFadeTransitionSpec The transition spec to use when fading the content - * on/off screen. The boolean parameter defined for the transition is [visible]. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public fun Modifier.placeholder( - visible: Boolean, - color: Color = Color.Unspecified, - shape: Shape? = null, - highlight: PlaceholderHighlight? = null, - placeholderFadeTransitionSpec: @Composable Transition.Segment.() -> FiniteAnimationSpec = { spring() }, - contentFadeTransitionSpec: @Composable Transition.Segment.() -> FiniteAnimationSpec = { spring() }, -): Modifier = composed { - Modifier.placeholder( - visible = visible, - color = if (color.isSpecified) color else PlaceholderDefaults.color(), - shape = shape ?: MaterialTheme.shapes.small, - highlight = highlight, - placeholderFadeTransitionSpec = placeholderFadeTransitionSpec, - contentFadeTransitionSpec = contentFadeTransitionSpec, - ) -} diff --git a/placeholder-material/src/main/java/com/google/accompanist/placeholder/material/PlaceholderHighlight.kt b/placeholder-material/src/main/java/com/google/accompanist/placeholder/material/PlaceholderHighlight.kt deleted file mode 100644 index 1594a04da..000000000 --- a/placeholder-material/src/main/java/com/google/accompanist/placeholder/material/PlaceholderHighlight.kt +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder.material - -import androidx.annotation.FloatRange -import androidx.compose.animation.core.AnimationSpec -import androidx.compose.animation.core.InfiniteRepeatableSpec -import androidx.compose.runtime.Composable -import com.google.accompanist.placeholder.PlaceholderDefaults -import com.google.accompanist.placeholder.PlaceholderHighlight -import com.google.accompanist.placeholder.fade -import com.google.accompanist.placeholder.shimmer - -/** - * Creates a [PlaceholderHighlight] which fades in an appropriate color, using the - * given [animationSpec]. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Material_PlaceholderFade - * - * @param animationSpec the [AnimationSpec] to configure the animation. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderHighlight.Companion.fade( - animationSpec: InfiniteRepeatableSpec = PlaceholderDefaults.fadeAnimationSpec, -): PlaceholderHighlight = PlaceholderHighlight.fade( - highlightColor = PlaceholderDefaults.fadeHighlightColor(), - animationSpec = animationSpec, -) - -/** - * Creates a [PlaceholderHighlight] which 'shimmers', using a default color. - * - * The highlight starts at the top-start, and then grows to the bottom-end during the animation. - * During that time it is also faded in, from 0f..progressForMaxAlpha, and then faded out from - * progressForMaxAlpha..1f. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Material_PlaceholderShimmer - * - * @param animationSpec the [AnimationSpec] to configure the animation. - * @param progressForMaxAlpha The progress where the shimmer should be at it's peak opacity. - * Defaults to 0.6f. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderHighlight.Companion.shimmer( - animationSpec: InfiniteRepeatableSpec = PlaceholderDefaults.shimmerAnimationSpec, - @FloatRange(from = 0.0, to = 1.0) progressForMaxAlpha: Float = 0.6f, -): PlaceholderHighlight = PlaceholderHighlight.shimmer( - highlightColor = PlaceholderDefaults.shimmerHighlightColor(), - animationSpec = animationSpec, - progressForMaxAlpha = progressForMaxAlpha, -) diff --git a/placeholder-material3/README.md b/placeholder-material3/README.md deleted file mode 100644 index 50fb20dd2..000000000 --- a/placeholder-material3/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Placeholder for Jetpack Compose (Material3) - -[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-placeholder)](https://search.maven.org/search?q=g:com.google.accompanist) - -For more information, visit the documentation: https://google.github.io/accompanist/placeholder - -## Download - -```groovy -repositories { - mavenCentral() -} - -dependencies { - implementation "com.google.accompanist:accompanist-placeholder-material3:" -} -``` - -Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit. - - [snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/accompanist-placeholder-material3/ \ No newline at end of file diff --git a/placeholder-material3/api/current.api b/placeholder-material3/api/current.api deleted file mode 100644 index 2aad44bed..000000000 --- a/placeholder-material3/api/current.api +++ /dev/null @@ -1,17 +0,0 @@ -// Signature format: 4.0 -package com.google.accompanist.placeholder.material3 { - - public final class PlaceholderHighlightKt { - method @Deprecated @androidx.compose.runtime.Composable public static com.google.accompanist.placeholder.PlaceholderHighlight fade(com.google.accompanist.placeholder.PlaceholderHighlight.Companion, optional androidx.compose.animation.core.InfiniteRepeatableSpec animationSpec); - method @Deprecated @androidx.compose.runtime.Composable public static com.google.accompanist.placeholder.PlaceholderHighlight shimmer(com.google.accompanist.placeholder.PlaceholderHighlight.Companion, optional androidx.compose.animation.core.InfiniteRepeatableSpec animationSpec, optional @FloatRange(from=0.0, to=1.0) float progressForMaxAlpha); - } - - public final class PlaceholderKt { - method @Deprecated @androidx.compose.runtime.Composable public static long color(com.google.accompanist.placeholder.PlaceholderDefaults, optional long backgroundColor, optional long contentColor, optional float contentAlpha); - method @Deprecated @androidx.compose.runtime.Composable public static long fadeHighlightColor(com.google.accompanist.placeholder.PlaceholderDefaults, optional long backgroundColor, optional float alpha); - method @Deprecated public static androidx.compose.ui.Modifier placeholder(androidx.compose.ui.Modifier, boolean visible, optional long color, optional androidx.compose.ui.graphics.Shape? shape, optional com.google.accompanist.placeholder.PlaceholderHighlight? highlight, optional kotlin.jvm.functions.Function1,? extends androidx.compose.animation.core.FiniteAnimationSpec> placeholderFadeTransitionSpec, optional kotlin.jvm.functions.Function1,? extends androidx.compose.animation.core.FiniteAnimationSpec> contentFadeTransitionSpec); - method @Deprecated @androidx.compose.runtime.Composable public static long shimmerHighlightColor(com.google.accompanist.placeholder.PlaceholderDefaults, optional long backgroundColor, optional float alpha); - } - -} - diff --git a/placeholder-material3/build.gradle.kts b/placeholder-material3/build.gradle.kts deleted file mode 100644 index 45ab465cb..000000000 --- a/placeholder-material3/build.gradle.kts +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2023 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. - */ -@file:Suppress("UnstableApiUsage") - -plugins { - id(libs.plugins.android.library.get().pluginId) - id(libs.plugins.android.kotlin.get().pluginId) - id(libs.plugins.jetbrains.dokka.get().pluginId) - id(libs.plugins.gradle.metalava.get().pluginId) - id(libs.plugins.vanniktech.maven.publish.get().pluginId) -} - -kotlin { - explicitApi() -} - -android { - namespace = "com.google.accompanist.placeholder.material3" - - compileSdk = 34 - - defaultConfig { - minSdk = 21 - // targetSdkVersion has no effect for libraries. This is only used for the test APK - targetSdk = 33 - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - buildFeatures { - buildConfig = false - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() - } - - lint { - textReport = true - textOutput = File("stdout") - // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks - checkReleaseBuilds = false - disable += setOf("GradleOverrides") - } - - packaging { - // Some of the META-INF files conflict with coroutines-test. Exclude them to enable - // our test APK to build (has no effect on our AARs) - resources { - excludes += listOf("/META-INF/AL2.0", "/META-INF/LGPL2.1") - } - } - - testOptions { - unitTests { - isIncludeAndroidResources = true - } - animationsDisabled = true - } -} - -metalava { - sourcePaths.setFrom("src/main") - filename.set("api/current.api") - reportLintsAsErrors.set(true) -} - -dependencies { - implementation(libs.compose.material3.material3) - api(project(":placeholder")) - implementation(libs.kotlin.coroutines.android) - - // ====================== - // Test dependencies - // ====================== - - androidTestImplementation(libs.junit) - androidTestImplementation(libs.truth) - - androidTestImplementation(libs.compose.ui.test.junit4) - androidTestImplementation(libs.compose.ui.test.manifest) - androidTestImplementation(libs.compose.foundation.foundation) - - androidTestImplementation(libs.androidx.test.core) - androidTestImplementation(libs.androidx.test.rules) - androidTestImplementation(libs.androidx.test.runner) -} diff --git a/placeholder-material3/gradle.properties b/placeholder-material3/gradle.properties deleted file mode 100644 index d30c0eb92..000000000 --- a/placeholder-material3/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_ARTIFACT_ID=accompanist-placeholder-material3 -POM_NAME=Accompanist Placeholder Material3 -POM_PACKAGING=aar \ No newline at end of file diff --git a/placeholder-material3/src/main/AndroidManifest.xml b/placeholder-material3/src/main/AndroidManifest.xml deleted file mode 100644 index 5d9779b28..000000000 --- a/placeholder-material3/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - diff --git a/placeholder-material3/src/main/java/com/google/accompanist/placeholder/material3/Placeholder.kt b/placeholder-material3/src/main/java/com/google/accompanist/placeholder/material3/Placeholder.kt deleted file mode 100644 index e9e3d115a..000000000 --- a/placeholder-material3/src/main/java/com/google/accompanist/placeholder/material3/Placeholder.kt +++ /dev/null @@ -1,156 +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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder.material3 - -import androidx.compose.animation.core.FiniteAnimationSpec -import androidx.compose.animation.core.Transition -import androidx.compose.animation.core.spring -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.contentColorFor -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.composed -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.graphics.compositeOver -import androidx.compose.ui.graphics.isSpecified -import com.google.accompanist.placeholder.PlaceholderDefaults -import com.google.accompanist.placeholder.PlaceholderHighlight -import com.google.accompanist.placeholder.placeholder - -/** - * Returns the value used as the the `color` parameter value on [Modifier.placeholder]. - * - * @param backgroundColor The current background color of the layout. Defaults to - * `MaterialTheme.colorScheme.surface`. - * @param contentColor The content color to be used on top of [backgroundColor]. - * @param contentAlpha The alpha component to set on [contentColor] when compositing the color - * on top of [backgroundColor]. Defaults to `0.1f`. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderDefaults.color( - backgroundColor: Color = MaterialTheme.colorScheme.surface, - contentColor: Color = contentColorFor(backgroundColor), - contentAlpha: Float = 0.1f, -): Color = contentColor.copy(contentAlpha).compositeOver(backgroundColor) - -/** - * Returns the value used as the the `highlightColor` parameter value of - * [PlaceholderHighlight.Companion.fade]. - * - * @param backgroundColor The current background color of the layout. Defaults to - * `MaterialTheme.colorScheme.surface`. - * @param alpha The alpha component to set on [backgroundColor]. Defaults to `0.3f`. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderDefaults.fadeHighlightColor( - backgroundColor: Color = MaterialTheme.colorScheme.surface, - alpha: Float = 0.3f, -): Color = backgroundColor.copy(alpha = alpha) - -/** - * Returns the value used as the the `highlightColor` parameter value of - * [PlaceholderHighlight.Companion.shimmer]. - * - * @param backgroundColor The current background color of the layout. Defaults to - * `MaterialTheme.colorScheme.inverseSurface`. - * @param alpha The alpha component to set on [backgroundColor]. Defaults to `0.75f`. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderDefaults.shimmerHighlightColor( - backgroundColor: Color = MaterialTheme.colorScheme.inverseSurface, - alpha: Float = 0.75f, -): Color { - return backgroundColor.copy(alpha = alpha) -} - -/** - * Draws some skeleton UI which is typically used whilst content is 'loading'. - * - * To customize the color and shape of the placeholder, you can use the foundation version of - * [Modifier.placeholder], along with the values provided by [PlaceholderDefaults]. - * - * A cross-fade transition will be applied to the content and placeholder UI when the [visible] - * value changes. The transition can be customized via the [contentFadeTransitionSpec] and - * [placeholderFadeTransitionSpec] parameters. - * - * You can provide a [PlaceholderHighlight] which runs an highlight animation on the placeholder. - * The [shimmer] and [fade] implementations are provided for easy usage. - * - * You can find more information on the pattern at the Material Theming - * [Placeholder UI](https://material.io/design/communication/launch-screen.html#placeholder-ui) - * guidelines. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Material_Placeholder - * - * @param visible whether the placeholder should be visible or not. - * @param color the color used to draw the placeholder UI. If [Color.Unspecified] is provided, - * the placeholder will use [PlaceholderDefaults.color]. - * @param shape desired shape of the placeholder. If null is provided the placeholder - * will use the small shape set in [MaterialTheme.shapes]. - * @param highlight optional highlight animation. - * @param placeholderFadeTransitionSpec The transition spec to use when fading the placeholder - * on/off screen. The boolean parameter defined for the transition is [visible]. - * @param contentFadeTransitionSpec The transition spec to use when fading the content - * on/off screen. The boolean parameter defined for the transition is [visible]. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public fun Modifier.placeholder( - visible: Boolean, - color: Color = Color.Unspecified, - shape: Shape? = null, - highlight: PlaceholderHighlight? = null, - placeholderFadeTransitionSpec: @Composable Transition.Segment.() -> FiniteAnimationSpec = { spring() }, - contentFadeTransitionSpec: @Composable Transition.Segment.() -> FiniteAnimationSpec = { spring() }, -): Modifier = composed { - Modifier.placeholder( - visible = visible, - color = if (color.isSpecified) color else PlaceholderDefaults.color(), - shape = shape ?: MaterialTheme.shapes.small, - highlight = highlight, - placeholderFadeTransitionSpec = placeholderFadeTransitionSpec, - contentFadeTransitionSpec = contentFadeTransitionSpec, - ) -} diff --git a/placeholder-material3/src/main/java/com/google/accompanist/placeholder/material3/PlaceholderHighlight.kt b/placeholder-material3/src/main/java/com/google/accompanist/placeholder/material3/PlaceholderHighlight.kt deleted file mode 100644 index 87e903049..000000000 --- a/placeholder-material3/src/main/java/com/google/accompanist/placeholder/material3/PlaceholderHighlight.kt +++ /dev/null @@ -1,80 +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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder.material3 - -import androidx.annotation.FloatRange -import androidx.compose.animation.core.AnimationSpec -import androidx.compose.animation.core.InfiniteRepeatableSpec -import androidx.compose.runtime.Composable -import com.google.accompanist.placeholder.PlaceholderDefaults -import com.google.accompanist.placeholder.PlaceholderHighlight -import com.google.accompanist.placeholder.fade -import com.google.accompanist.placeholder.shimmer - -/** - * Creates a [PlaceholderHighlight] which fades in an appropriate color, using the - * given [animationSpec]. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Material_PlaceholderFade - * - * @param animationSpec the [AnimationSpec] to configure the animation. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderHighlight.Companion.fade( - animationSpec: InfiniteRepeatableSpec = PlaceholderDefaults.fadeAnimationSpec, -): PlaceholderHighlight = PlaceholderHighlight.fade( - highlightColor = PlaceholderDefaults.fadeHighlightColor(), - animationSpec = animationSpec, -) - -/** - * Creates a [PlaceholderHighlight] which 'shimmers', using a default color. - * - * The highlight starts at the top-start, and then grows to the bottom-end during the animation. - * During that time it is also faded in, from 0f..progressForMaxAlpha, and then faded out from - * progressForMaxAlpha..1f. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Material_PlaceholderShimmer - * - * @param animationSpec the [AnimationSpec] to configure the animation. - * @param progressForMaxAlpha The progress where the shimmer should be at it's peak opacity. - * Defaults to 0.6f. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -@Composable -public fun PlaceholderHighlight.Companion.shimmer( - animationSpec: InfiniteRepeatableSpec = PlaceholderDefaults.shimmerAnimationSpec, - @FloatRange(from = 0.0, to = 1.0) progressForMaxAlpha: Float = 0.6f, -): PlaceholderHighlight = PlaceholderHighlight.shimmer( - highlightColor = PlaceholderDefaults.shimmerHighlightColor(), - animationSpec = animationSpec, - progressForMaxAlpha = progressForMaxAlpha, -) diff --git a/placeholder/README.md b/placeholder/README.md deleted file mode 100644 index 95e5ce651..000000000 --- a/placeholder/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Placeholder for Jetpack Compose - -[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-placeholder)](https://search.maven.org/search?q=g:com.google.accompanist) - -> :warning: This library has been deprecated and the API is no longer maintained. We recommend forking the implementation and customising it to your needs. - -For more information, visit the documentation: https://google.github.io/accompanist/placeholder - -## Download - -```groovy -repositories { - mavenCentral() -} - -dependencies { - implementation "com.google.accompanist:accompanist-placeholder:" -} -``` - -Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit. - - [snap]: https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/accompanist-placeholder/ \ No newline at end of file diff --git a/placeholder/api/current.api b/placeholder/api/current.api deleted file mode 100644 index 5bb61da05..000000000 --- a/placeholder/api/current.api +++ /dev/null @@ -1,33 +0,0 @@ -// Signature format: 4.0 -package com.google.accompanist.placeholder { - - @Deprecated public final class PlaceholderDefaults { - method @Deprecated public androidx.compose.animation.core.InfiniteRepeatableSpec getFadeAnimationSpec(); - method @Deprecated public androidx.compose.animation.core.InfiniteRepeatableSpec getShimmerAnimationSpec(); - property public final androidx.compose.animation.core.InfiniteRepeatableSpec fadeAnimationSpec; - property public final androidx.compose.animation.core.InfiniteRepeatableSpec shimmerAnimationSpec; - field @Deprecated public static final com.google.accompanist.placeholder.PlaceholderDefaults INSTANCE; - } - - @Deprecated @androidx.compose.runtime.Stable public interface PlaceholderHighlight { - method @Deprecated @FloatRange(from=0.0, to=1.0) public float alpha(float progress); - method @Deprecated public androidx.compose.ui.graphics.Brush brush(@FloatRange(from=0.0, to=1.0) float progress, long size); - method @Deprecated public androidx.compose.animation.core.InfiniteRepeatableSpec? getAnimationSpec(); - property public abstract androidx.compose.animation.core.InfiniteRepeatableSpec? animationSpec; - field @Deprecated public static final com.google.accompanist.placeholder.PlaceholderHighlight.Companion Companion; - } - - @Deprecated public static final class PlaceholderHighlight.Companion { - } - - public final class PlaceholderHighlightKt { - method @Deprecated public static com.google.accompanist.placeholder.PlaceholderHighlight fade(com.google.accompanist.placeholder.PlaceholderHighlight.Companion, long highlightColor, optional androidx.compose.animation.core.InfiniteRepeatableSpec animationSpec); - method @Deprecated public static com.google.accompanist.placeholder.PlaceholderHighlight shimmer(com.google.accompanist.placeholder.PlaceholderHighlight.Companion, long highlightColor, optional androidx.compose.animation.core.InfiniteRepeatableSpec animationSpec, optional @FloatRange(from=0.0, to=1.0) float progressForMaxAlpha); - } - - public final class PlaceholderKt { - method @Deprecated public static androidx.compose.ui.Modifier placeholder(androidx.compose.ui.Modifier, boolean visible, long color, optional androidx.compose.ui.graphics.Shape shape, optional com.google.accompanist.placeholder.PlaceholderHighlight? highlight, optional kotlin.jvm.functions.Function1,? extends androidx.compose.animation.core.FiniteAnimationSpec> placeholderFadeTransitionSpec, optional kotlin.jvm.functions.Function1,? extends androidx.compose.animation.core.FiniteAnimationSpec> contentFadeTransitionSpec); - } - -} - diff --git a/placeholder/build.gradle.kts b/placeholder/build.gradle.kts deleted file mode 100644 index c475e78d1..000000000 --- a/placeholder/build.gradle.kts +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2023 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. - */ -@file:Suppress("UnstableApiUsage") - -plugins { - id(libs.plugins.android.library.get().pluginId) - id(libs.plugins.android.kotlin.get().pluginId) - id(libs.plugins.jetbrains.dokka.get().pluginId) - id(libs.plugins.gradle.metalava.get().pluginId) - id(libs.plugins.vanniktech.maven.publish.get().pluginId) -} - -kotlin { - explicitApi() -} - -android { - compileSdk = 34 - - defaultConfig { - minSdk = 21 - // targetSdkVersion has no effect for libraries. This is only used for the test APK - targetSdk = 33 - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - - buildFeatures { - buildConfig = false - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() - } - - lint { - textReport = true - textOutput = File("stdout") - // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks - checkReleaseBuilds = false - disable += setOf("GradleOverrides") - } - - packaging { - // Some of the META-INF files conflict with coroutines-test. Exclude them to enable - // our test APK to build (has no effect on our AARs) - resources { - excludes += listOf("/META-INF/AL2.0", "/META-INF/LGPL2.1") - } - } - - testOptions { - unitTests { - isIncludeAndroidResources = true - } - unitTests.all { - it.useJUnit { - excludeCategories("com.google.accompanist.internal.test.IgnoreOnRobolectric") - } - } - animationsDisabled = true - } - - sourceSets { - named("test") { - java.srcDirs("src/sharedTest/kotlin") - res.srcDirs("src/sharedTest/res") - } - named("androidTest") { - java.srcDirs("src/sharedTest/kotlin") - res.srcDirs("src/sharedTest/res") - } - } - namespace = "com.google.accompanist.placeholder" -} - -metalava { - sourcePaths.setFrom("src/main") - filename.set("api/current.api") - reportLintsAsErrors.set(true) -} - -dependencies { - implementation(libs.compose.foundation.foundation) - implementation(libs.compose.ui.util) - implementation(libs.kotlin.coroutines.android) - - // ====================== - // Test dependencies - // ====================== - - 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) -} diff --git a/placeholder/gradle.properties b/placeholder/gradle.properties deleted file mode 100644 index 6e692656c..000000000 --- a/placeholder/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_ARTIFACT_ID=accompanist-placeholder -POM_NAME=Accompanist Placeholder -POM_PACKAGING=aar \ No newline at end of file diff --git a/placeholder/src/main/AndroidManifest.xml b/placeholder/src/main/AndroidManifest.xml deleted file mode 100644 index 928e8bf1f..000000000 --- a/placeholder/src/main/AndroidManifest.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - diff --git a/placeholder/src/main/java/com/google/accompanist/placeholder/Placeholder.kt b/placeholder/src/main/java/com/google/accompanist/placeholder/Placeholder.kt deleted file mode 100644 index caadb5555..000000000 --- a/placeholder/src/main/java/com/google/accompanist/placeholder/Placeholder.kt +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder - -import androidx.compose.animation.core.FiniteAnimationSpec -import androidx.compose.animation.core.InfiniteRepeatableSpec -import androidx.compose.animation.core.MutableTransitionState -import androidx.compose.animation.core.RepeatMode -import androidx.compose.animation.core.Transition -import androidx.compose.animation.core.animateFloat -import androidx.compose.animation.core.infiniteRepeatable -import androidx.compose.animation.core.rememberInfiniteTransition -import androidx.compose.animation.core.spring -import androidx.compose.animation.core.tween -import androidx.compose.animation.core.updateTransition -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.composed -import androidx.compose.ui.draw.drawWithContent -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.geometry.toRect -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Outline -import androidx.compose.ui.graphics.Paint -import androidx.compose.ui.graphics.RectangleShape -import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.graphics.drawOutline -import androidx.compose.ui.graphics.drawscope.DrawScope -import androidx.compose.ui.graphics.drawscope.drawIntoCanvas -import androidx.compose.ui.node.Ref -import androidx.compose.ui.platform.debugInspectorInfo -import androidx.compose.ui.unit.LayoutDirection - -/** - * Contains default values used by [Modifier.placeholder] and [PlaceholderHighlight]. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public object PlaceholderDefaults { - /** - * The default [InfiniteRepeatableSpec] to use for [fade]. - */ - public val fadeAnimationSpec: InfiniteRepeatableSpec by lazy { - infiniteRepeatable( - animation = tween(delayMillis = 200, durationMillis = 600), - repeatMode = RepeatMode.Reverse, - ) - } - - /** - * The default [InfiniteRepeatableSpec] to use for [shimmer]. - */ - public val shimmerAnimationSpec: InfiniteRepeatableSpec by lazy { - infiniteRepeatable( - animation = tween(durationMillis = 1700, delayMillis = 200), - repeatMode = RepeatMode.Restart - ) - } -} - -/** - * Draws some skeleton UI which is typically used whilst content is 'loading'. - * - * A version of this modifier which uses appropriate values for Material themed apps is available - * in the 'Placeholder Material' library. - * - * You can provide a [PlaceholderHighlight] which runs an highlight animation on the placeholder. - * The [shimmer] and [fade] implementations are provided for easy usage. - * - * A cross-fade transition will be applied to the content and placeholder UI when the [visible] - * value changes. The transition can be customized via the [contentFadeTransitionSpec] and - * [placeholderFadeTransitionSpec] parameters. - * - * You can find more information on the pattern at the Material Theming - * [Placeholder UI](https://material.io/design/communication/launch-screen.html#placeholder-ui) - * guidelines. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Foundation_Placeholder - * - * @param visible whether the placeholder should be visible or not. - * @param color the color used to draw the placeholder UI. - * @param shape desired shape of the placeholder. Defaults to [RectangleShape]. - * @param highlight optional highlight animation. - * @param placeholderFadeTransitionSpec The transition spec to use when fading the placeholder - * on/off screen. The boolean parameter defined for the transition is [visible]. - * @param contentFadeTransitionSpec The transition spec to use when fading the content - * on/off screen. The boolean parameter defined for the transition is [visible]. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public fun Modifier.placeholder( - visible: Boolean, - color: Color, - shape: Shape = RectangleShape, - highlight: PlaceholderHighlight? = null, - placeholderFadeTransitionSpec: @Composable Transition.Segment.() -> FiniteAnimationSpec = { spring() }, - contentFadeTransitionSpec: @Composable Transition.Segment.() -> FiniteAnimationSpec = { spring() }, -): Modifier = composed( - inspectorInfo = debugInspectorInfo { - name = "placeholder" - value = visible - properties["visible"] = visible - properties["color"] = color - properties["highlight"] = highlight - properties["shape"] = shape - } -) { - // Values used for caching purposes - val lastSize = remember { Ref() } - val lastLayoutDirection = remember { Ref() } - val lastOutline = remember { Ref() } - - // The current highlight animation progress - var highlightProgress: Float by remember { mutableStateOf(0f) } - - // This is our crossfade transition - val transitionState = remember { MutableTransitionState(visible) }.apply { - targetState = visible - } - val transition = updateTransition(transitionState, "placeholder_crossfade") - - val placeholderAlpha by transition.animateFloat( - transitionSpec = placeholderFadeTransitionSpec, - label = "placeholder_fade", - targetValueByState = { placeholderVisible -> if (placeholderVisible) 1f else 0f } - ) - val contentAlpha by transition.animateFloat( - transitionSpec = contentFadeTransitionSpec, - label = "content_fade", - targetValueByState = { placeholderVisible -> if (placeholderVisible) 0f else 1f } - ) - - // Run the optional animation spec and update the progress if the placeholder is visible - val animationSpec = highlight?.animationSpec - if (animationSpec != null && (visible || placeholderAlpha >= 0.01f)) { - val infiniteTransition = rememberInfiniteTransition() - highlightProgress = infiniteTransition.animateFloat( - initialValue = 0f, - targetValue = 1f, - animationSpec = animationSpec, - ).value - } - - val paint = remember { Paint() } - remember(color, shape, highlight) { - drawWithContent { - // Draw the composable content first - if (contentAlpha in 0.01f..0.99f) { - // If the content alpha is between 1% and 99%, draw it in a layer with - // the alpha applied - paint.alpha = contentAlpha - withLayer(paint) { - with(this@drawWithContent) { - drawContent() - } - } - } else if (contentAlpha >= 0.99f) { - // If the content alpha is > 99%, draw it with no alpha - drawContent() - } - - if (placeholderAlpha in 0.01f..0.99f) { - // If the placeholder alpha is between 1% and 99%, draw it in a layer with - // the alpha applied - paint.alpha = placeholderAlpha - withLayer(paint) { - lastOutline.value = drawPlaceholder( - shape = shape, - color = color, - highlight = highlight, - progress = highlightProgress, - lastOutline = lastOutline.value, - lastLayoutDirection = lastLayoutDirection.value, - lastSize = lastSize.value, - ) - } - } else if (placeholderAlpha >= 0.99f) { - // If the placeholder alpha is > 99%, draw it with no alpha - lastOutline.value = drawPlaceholder( - shape = shape, - color = color, - highlight = highlight, - progress = highlightProgress, - lastOutline = lastOutline.value, - lastLayoutDirection = lastLayoutDirection.value, - lastSize = lastSize.value, - ) - } - - // Keep track of the last size & layout direction - lastSize.value = size - lastLayoutDirection.value = layoutDirection - } - } -} - -private fun DrawScope.drawPlaceholder( - shape: Shape, - color: Color, - highlight: PlaceholderHighlight?, - progress: Float, - lastOutline: Outline?, - lastLayoutDirection: LayoutDirection?, - lastSize: Size?, -): Outline? { - // shortcut to avoid Outline calculation and allocation - if (shape === RectangleShape) { - // Draw the initial background color - drawRect(color = color) - - if (highlight != null) { - drawRect( - brush = highlight.brush(progress, size), - alpha = highlight.alpha(progress), - ) - } - // We didn't create an outline so return null - return null - } - - // Otherwise we need to create an outline from the shape - val outline = lastOutline.takeIf { - size == lastSize && layoutDirection == lastLayoutDirection - } ?: shape.createOutline(size, layoutDirection, this) - - // Draw the placeholder color - drawOutline(outline = outline, color = color) - - if (highlight != null) { - drawOutline( - outline = outline, - brush = highlight.brush(progress, size), - alpha = highlight.alpha(progress), - ) - } - - // Return the outline we used - return outline -} - -private inline fun DrawScope.withLayer( - paint: Paint, - drawBlock: DrawScope.() -> Unit, -) = drawIntoCanvas { canvas -> - canvas.saveLayer(size.toRect(), paint) - drawBlock() - canvas.restore() -} diff --git a/placeholder/src/main/java/com/google/accompanist/placeholder/PlaceholderHighlight.kt b/placeholder/src/main/java/com/google/accompanist/placeholder/PlaceholderHighlight.kt deleted file mode 100644 index f91ef3d7d..000000000 --- a/placeholder/src/main/java/com/google/accompanist/placeholder/PlaceholderHighlight.kt +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder - -import androidx.annotation.FloatRange -import androidx.compose.animation.core.AnimationSpec -import androidx.compose.animation.core.InfiniteRepeatableSpec -import androidx.compose.runtime.Stable -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Brush -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.util.lerp -import kotlin.math.max - -/** - * A class which provides a brush to paint placeholder based on progress. - */ -@Stable -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public interface PlaceholderHighlight { - /** - * The optional [AnimationSpec] to use when running the animation for this highlight. - */ - public val animationSpec: InfiniteRepeatableSpec? - - /** - * Return a [Brush] to draw for the given [progress] and [size]. - * - * @param progress the current animated progress in the range of 0f..1f. - * @param size The size of the current layout to draw in. - */ - public fun brush( - @FloatRange(from = 0.0, to = 1.0) progress: Float, - size: Size - ): Brush - - /** - * Return the desired alpha value used for drawing the [Brush] returned from [brush]. - * - * @param progress the current animated progress in the range of 0f..1f. - */ - @FloatRange(from = 0.0, to = 1.0) - public fun alpha(progress: Float): Float - - public companion object -} - -/** - * Creates a [Fade] brush with the given initial and target colors. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Foundation_PlaceholderFade - * - * @param highlightColor the color of the highlight which is faded in/out. - * @param animationSpec the [AnimationSpec] to configure the animation. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public fun PlaceholderHighlight.Companion.fade( - highlightColor: Color, - animationSpec: InfiniteRepeatableSpec = PlaceholderDefaults.fadeAnimationSpec, -): PlaceholderHighlight = Fade( - highlightColor = highlightColor, - animationSpec = animationSpec, -) - -/** - * Creates a [PlaceholderHighlight] which 'shimmers', using the given [highlightColor]. - * - * The highlight starts at the top-start, and then grows to the bottom-end during the animation. - * During that time it is also faded in, from 0f..progressForMaxAlpha, and then faded out from - * progressForMaxAlpha..1f. - * - * @sample com.google.accompanist.sample.placeholder.DocSample_Foundation_PlaceholderShimmer - * - * @param highlightColor the color of the highlight 'shimmer'. - * @param animationSpec the [AnimationSpec] to configure the animation. - * @param progressForMaxAlpha The progress where the shimmer should be at it's peak opacity. - * Defaults to 0.6f. - */ -@Deprecated( - """ -accompanist/placeholder is deprecated and the API is no longer maintained. -We recommend forking the implementation and customising it to your needs. -For more information please visit https://google.github.io/accompanist/placeholder -""" -) -public fun PlaceholderHighlight.Companion.shimmer( - highlightColor: Color, - animationSpec: InfiniteRepeatableSpec = PlaceholderDefaults.shimmerAnimationSpec, - @FloatRange(from = 0.0, to = 1.0) progressForMaxAlpha: Float = 0.6f, -): PlaceholderHighlight = Shimmer( - highlightColor = highlightColor, - animationSpec = animationSpec, - progressForMaxAlpha = progressForMaxAlpha, -) - -private data class Fade( - private val highlightColor: Color, - override val animationSpec: InfiniteRepeatableSpec, -) : PlaceholderHighlight { - private val brush = SolidColor(highlightColor) - - override fun brush(progress: Float, size: Size): Brush = brush - override fun alpha(progress: Float): Float = progress -} - -private data class Shimmer( - private val highlightColor: Color, - override val animationSpec: InfiniteRepeatableSpec, - private val progressForMaxAlpha: Float = 0.6f, -) : PlaceholderHighlight { - override fun brush( - progress: Float, - size: Size, - ): Brush = Brush.radialGradient( - colors = listOf( - highlightColor.copy(alpha = 0f), - highlightColor, - highlightColor.copy(alpha = 0f), - ), - center = Offset(x = 0f, y = 0f), - radius = (max(size.width, size.height) * progress * 2).coerceAtLeast(0.01f), - ) - - override fun alpha(progress: Float): Float = when { - // From 0f...ProgressForOpaqueAlpha we animate from 0..1 - progress <= progressForMaxAlpha -> { - lerp( - start = 0f, - stop = 1f, - fraction = progress / progressForMaxAlpha - ) - } - // From ProgressForOpaqueAlpha..1f we animate from 1..0 - else -> { - lerp( - start = 1f, - stop = 0f, - fraction = (progress - progressForMaxAlpha) / (1f - progressForMaxAlpha) - ) - } - } -} diff --git a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/FakeTests.kt b/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/FakeTests.kt deleted file mode 100644 index ed09fd982..000000000 --- a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/FakeTests.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2021 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.placeholder - -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 - -/** - * Fake tests to help with sharding: https://github.com/android/android-test/issues/973 - */ -@RunWith(JUnit4::class) -class FakeTests { - @Test - fun fake1() = Unit - - @Test - fun fake2() = Unit - - @Test - fun fake3() = Unit - - @Test - fun fake4() = Unit - - @Test - fun fake5() = Unit - - @Test - fun fake6() = Unit - - @Test - fun fake7() = Unit - - @Test - fun fake8() = Unit - - @Test - fun fake9() = Unit - - @Test - fun fake10() = Unit -} diff --git a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/ImageAssertions.kt b/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/ImageAssertions.kt deleted file mode 100644 index 1a6bd2e39..000000000 --- a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/ImageAssertions.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2020 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.placeholder - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.PixelMap -import androidx.compose.ui.graphics.toPixelMap -import com.google.common.truth.Truth.assertThat - -/** - * Asserts that the color at a specific pixel in the bitmap at ([x], [y]) is [expected]. - */ -fun PixelMap.assertPixelColor(expected: Color, x: Int, y: Int, tolerance: Float = 0.02f) { - val color = this[x, y] - assertThat(color.red).isWithin(tolerance).of(expected.red) - assertThat(color.green).isWithin(tolerance).of(expected.green) - assertThat(color.blue).isWithin(tolerance).of(expected.blue) - assertThat(color.alpha).isWithin(tolerance).of(expected.alpha) -} - -/** - * Asserts that the colors at specific pixels in the vertices of bitmap is [expected]. - */ -fun ImageBitmap.assertPixelsOfVertices(expected: Color) { - toPixelMap().run { - assertPixelColor(expected, 0, 0) - assertPixelColor(expected, 0, height - 1) - assertPixelColor(expected, width - 1, 0) - assertPixelColor(expected, width - 1, height - 1) - } -} diff --git a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/PlaceholderHighlightTest.kt b/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/PlaceholderHighlightTest.kt deleted file mode 100644 index c2822a1e5..000000000 --- a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/PlaceholderHighlightTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.test.junit4.createComposeRule -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 PlaceholderHighlightTest { - @get:Rule - val composeTestRule = createComposeRule() - - @Test - fun fadeBrush() { - composeTestRule.setContent { - PlaceholderHighlight.fade(highlightColor = Color.Blue) - } - } - - @Test - fun shimmerBrush() { - composeTestRule.setContent { - PlaceholderHighlight.shimmer(highlightColor = Color.Blue) - } - } - - @Test - fun fadeBrush_equals() { - assertThat(PlaceholderHighlight.fade(highlightColor = Color.Blue)) - .isEqualTo(PlaceholderHighlight.fade(highlightColor = Color.Blue)) - } - - @Test - fun shimmerBrush_equals() { - assertThat(PlaceholderHighlight.shimmer(highlightColor = Color.Blue)) - .isEqualTo(PlaceholderHighlight.shimmer(highlightColor = Color.Blue)) - } -} diff --git a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/PlaceholderTest.kt b/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/PlaceholderTest.kt deleted file mode 100644 index 630c72843..000000000 --- a/placeholder/src/sharedTest/kotlin/com/google/accompanist/placeholder/PlaceholderTest.kt +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.placeholder - -import androidx.compose.animation.core.InfiniteRepeatableSpec -import androidx.compose.animation.core.RepeatMode -import androidx.compose.animation.core.infiniteRepeatable -import androidx.compose.animation.core.tween -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Brush -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.RectangleShape -import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.platform.InspectableValue -import androidx.compose.ui.platform.ValueElement -import androidx.compose.ui.platform.isDebugInspectorInfoEnabled -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.test.assertHeightIsEqualTo -import androidx.compose.ui.test.assertIsDisplayed -import androidx.compose.ui.test.assertWidthIsEqualTo -import androidx.compose.ui.test.captureToImage -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 androidx.test.filters.SdkSuppress -import com.google.accompanist.internal.test.IgnoreOnRobolectric -import com.google.accompanist.internal.test.assertPixels -import com.google.common.truth.Truth.assertThat -import org.junit.After -import org.junit.Before -import org.junit.Rule -import org.junit.Test -import org.junit.experimental.categories.Category -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class PlaceholderTest { - @get:Rule - val composeTestRule = createComposeRule() - - private val contentTag = "Content" - - @Before - fun before() { - isDebugInspectorInfoEnabled = true - } - - @After - fun after() { - isDebugInspectorInfoEnabled = false - } - - @Test - @SdkSuppress(minSdkVersion = 26) // captureToImage is SDK 26+ - @Category(IgnoreOnRobolectric::class) // captureToImage doesn't work on Robolectric - fun placeholder_switchVisible1() { - var visible by mutableStateOf(true) - - composeTestRule.setContent { - Box( - Modifier - .size(128.dp) - .background(color = Color.Black) - .placeholder(visible = visible, color = Color.Red) - .testTag(contentTag) - ) - } - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Red) - - visible = false - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Black) - } - - @Test - @SdkSuppress(minSdkVersion = 26) // captureToImage is SDK 26+ - @Category(IgnoreOnRobolectric::class) // captureToImage doesn't work on Robolectric - fun placeholder_switchVisible2() { - var visible by mutableStateOf(true) - - composeTestRule.setContent { - Box( - Modifier - .size(128.dp) - .background(color = Color.Black) - .placeholder( - visible = visible, - color = Color.Gray, - highlight = Solid(Color.Red) - ) - .testTag(contentTag) - ) - } - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Red) - - visible = false - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Black) - } - - @Test - @SdkSuppress(minSdkVersion = 26) // captureToImage is SDK 26+ - @Category(IgnoreOnRobolectric::class) // captureToImage doesn't work on Robolectric - fun placeholder_switchColor() { - var color by mutableStateOf(Color.Red) - - composeTestRule.setContent { - Box( - Modifier - .size(128.dp) - .background(color = Color.Black) - .placeholder(visible = true, color = color) - .testTag(contentTag) - ) - } - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Red) - - color = Color.Blue - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Blue) - } - - @Test - @SdkSuppress(minSdkVersion = 26) // captureToImage is SDK 26+ - @Category(IgnoreOnRobolectric::class) // captureToImage doesn't work on Robolectric - fun placeholder_switchAnimatedBrush() { - var animatedBrush by mutableStateOf(Solid(Color.Red)) - - composeTestRule.setContent { - Box( - Modifier - .size(128.dp) - .background(color = Color.Black) - .placeholder( - visible = true, - color = Color.Gray, - highlight = animatedBrush - ) - .testTag(contentTag) - ) - } - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Red) - - animatedBrush = Solid(Color.Blue) - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(128.dp) - .assertHeightIsEqualTo(128.dp) - .captureToImage() - .assertPixels(Color.Blue) - } - - @Test - @SdkSuppress(minSdkVersion = 26) // captureToImage is SDK 26+ - @Category(IgnoreOnRobolectric::class) // captureToImage doesn't work on Robolectric - fun placeholder_switchShape1() { - var shape by mutableStateOf(RectangleShape) - - composeTestRule.setContent { - Box( - Modifier - .size(20.dp) - .background(color = Color.Black) - .placeholder( - visible = true, - color = Color.Red, - shape = shape - ) - .testTag(contentTag) - ) - } - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(20.dp) - .assertHeightIsEqualTo(20.dp) - .captureToImage() - .assertPixels(Color.Red) - - shape = CircleShape - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(20.dp) - .assertHeightIsEqualTo(20.dp) - .captureToImage() - // There is no stable API to assert the shape. - // So check the color of the vertices simply. - .assertPixelsOfVertices(Color.Black) - } - - @Test - @SdkSuppress(minSdkVersion = 26) // captureToImage is SDK 26+ - @Category(IgnoreOnRobolectric::class) // captureToImage doesn't work on Robolectric - fun placeholder_switchShape2() { - var shape by mutableStateOf(RectangleShape) - - composeTestRule.setContent { - Box( - Modifier - .size(20.dp) - .background(color = Color.Black) - .placeholder( - visible = true, - color = Color.Gray, - highlight = Solid(Color.Red), - shape = shape - ) - .testTag(contentTag) - ) - } - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(20.dp) - .assertHeightIsEqualTo(20.dp) - .captureToImage() - .assertPixels(Color.Red) - - shape = CircleShape - - composeTestRule.onNodeWithTag(contentTag) - .assertIsDisplayed() - .assertWidthIsEqualTo(20.dp) - .assertHeightIsEqualTo(20.dp) - .captureToImage() - // There is no stable API to assert the shape. - // So check the color of the vertices simply. - .assertPixelsOfVertices(Color.Black) - } - - @Test - fun placeholder_inspectableParameter1() { - val highlight = PlaceholderHighlight.shimmer(Color.Red) - val modifier = Modifier.placeholder( - visible = true, - color = Color.Blue, - highlight = highlight, - ) as InspectableValue - - assertThat(modifier.nameFallback).isEqualTo("placeholder") - assertThat(modifier.valueOverride).isEqualTo(true) - assertThat(modifier.inspectableElements.asIterable()).containsExactly( - ValueElement("visible", true), - ValueElement("color", Color.Blue), - ValueElement("highlight", highlight), - ValueElement("shape", RectangleShape) - ) - } - - @Test - fun placeholder_inspectableParameter2() { - val highlight = PlaceholderHighlight.fade(Color.Red) - val modifier = Modifier.placeholder( - visible = true, - color = Color.Blue, - highlight = highlight, - ) as InspectableValue - - assertThat(modifier.nameFallback).isEqualTo("placeholder") - assertThat(modifier.valueOverride).isEqualTo(true) - assertThat(modifier.inspectableElements.asIterable()).containsExactly( - ValueElement("visible", true), - ValueElement("color", Color.Blue), - ValueElement("highlight", highlight), - ValueElement("shape", RectangleShape) - ) - } -} - -internal class Solid( - private val color: Color, - override val animationSpec: InfiniteRepeatableSpec = infiniteRepeatable( - animation = tween(delayMillis = 0, durationMillis = 500), - repeatMode = RepeatMode.Restart - ) -) : PlaceholderHighlight { - override fun alpha(progress: Float): Float = 1f - - override fun brush(progress: Float, size: Size): Brush { - return SolidColor(color) - } -} diff --git a/placeholder/src/test/resources/robolectric.properties b/placeholder/src/test/resources/robolectric.properties deleted file mode 100644 index 2806eaffa..000000000 --- a/placeholder/src/test/resources/robolectric.properties +++ /dev/null @@ -1,3 +0,0 @@ -# Pin SDK to 30 since Robolectric does not currently support API 31: -# https://github.com/robolectric/robolectric/issues/6635 -sdk=30 diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index fd582a55a..717462115 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -63,8 +63,6 @@ dependencies { implementation(project(":navigation-animation")) implementation(project(":navigation-material")) implementation(project(":permissions")) - implementation(project(":placeholder")) - implementation(project(":placeholder-material")) implementation(project(":systemuicontroller")) implementation(project(":testharness")) // Don't use in production! Use the configurations below testImplementation(project(":testharness")) diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 5f222424c..7578ed119 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -133,36 +133,6 @@ - - - - - - - - - - - - - - - - - - - - - - // Simulate a fake 2-second 'load'. Ideally this 'refreshing' value would - // come from a ViewModel or similar - var refreshing by remember { mutableStateOf(false) } - LaunchedEffect(refreshing) { - if (refreshing) { - delay(2000) - refreshing = false - } - } - - val state = rememberPullRefreshState( - refreshing = refreshing, - onRefresh = { refreshing = true } - ) - - Box(Modifier.pullRefresh(state)) { - LazyColumn(contentPadding = padding) { - if (refreshing.not()) { - item { - ListItem( - painter = rememberVectorPainter(Icons.Default.ArrowDownward), - text = "Pull down" - ) - } - } - items(30) { index -> - ListItem( - painter = rememberImagePainter(randomSampleImageUrl(index)), - text = "Text", - // We're using the modifier provided by placeholder-material which - // uses good default values for the color - childModifier = Modifier.placeholder(visible = refreshing) - ) - } - } - - PullRefreshIndicator( - refreshing = refreshing, - state = state, - modifier = Modifier.align(Alignment.TopCenter) - ) - } - } -} diff --git a/sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderFadeSample.kt b/sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderFadeSample.kt deleted file mode 100644 index 25abcf041..000000000 --- a/sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderFadeSample.kt +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.sample.placeholder - -import android.os.Bundle -import androidx.activity.ComponentActivity -import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Scaffold -import androidx.compose.material.Text -import androidx.compose.material.TopAppBar -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowDownward -import androidx.compose.material.pullrefresh.PullRefreshIndicator -import androidx.compose.material.pullrefresh.pullRefresh -import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.res.stringResource -import coil.annotation.ExperimentalCoilApi -import coil.compose.rememberImagePainter -import com.google.accompanist.placeholder.PlaceholderHighlight -import com.google.accompanist.placeholder.material.fade -import com.google.accompanist.placeholder.material.placeholder -import com.google.accompanist.sample.AccompanistSampleTheme -import com.google.accompanist.sample.R -import com.google.accompanist.sample.randomSampleImageUrl -import kotlinx.coroutines.delay - -class PlaceholderFadeSample : ComponentActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - setContent { - AccompanistSampleTheme { - Sample() - } - } - } -} - -@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class) -@Composable -private fun Sample() { - Scaffold( - topBar = { - TopAppBar( - title = { Text(stringResource(R.string.placeholder_title_fade)) }, - backgroundColor = MaterialTheme.colors.surface, - ) - }, - modifier = Modifier.fillMaxSize() - ) { padding -> - // Simulate a fake 2-second 'load'. Ideally this 'refreshing' value would - // come from a ViewModel or similar - var refreshing by remember { mutableStateOf(false) } - LaunchedEffect(refreshing) { - if (refreshing) { - delay(4000) - refreshing = false - } - } - - val state = rememberPullRefreshState( - refreshing = refreshing, - onRefresh = { refreshing = true } - ) - - Box(Modifier.pullRefresh(state)) { - LazyColumn(contentPadding = padding) { - if (refreshing.not()) { - item { - ListItem( - painter = rememberVectorPainter(Icons.Default.ArrowDownward), - text = "Pull down" - ) - } - } - items(30) { index -> - ListItem( - painter = rememberImagePainter(randomSampleImageUrl(index)), - text = "Text", - // We're using the modifier provided by placeholder-material which - // uses good default values for the color - childModifier = Modifier.placeholder( - visible = refreshing, - highlight = PlaceholderHighlight.fade(), - ) - ) - } - } - - PullRefreshIndicator( - refreshing = refreshing, - state = state, - modifier = Modifier.align(Alignment.TopCenter) - ) - } - } -} diff --git a/sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderShimmerSample.kt b/sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderShimmerSample.kt deleted file mode 100644 index 23568bcde..000000000 --- a/sample/src/main/java/com/google/accompanist/sample/placeholder/PlaceholderShimmerSample.kt +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2021 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. - */ - -@file:Suppress("DEPRECATION") -package com.google.accompanist.sample.placeholder - -import android.os.Bundle -import androidx.activity.ComponentActivity -import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Scaffold -import androidx.compose.material.Text -import androidx.compose.material.TopAppBar -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowDownward -import androidx.compose.material.pullrefresh.PullRefreshIndicator -import androidx.compose.material.pullrefresh.pullRefresh -import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.vector.rememberVectorPainter -import androidx.compose.ui.res.stringResource -import coil.annotation.ExperimentalCoilApi -import coil.compose.rememberImagePainter -import com.google.accompanist.placeholder.PlaceholderHighlight -import com.google.accompanist.placeholder.material.placeholder -import com.google.accompanist.placeholder.material.shimmer -import com.google.accompanist.sample.AccompanistSampleTheme -import com.google.accompanist.sample.R -import com.google.accompanist.sample.randomSampleImageUrl -import kotlinx.coroutines.delay - -class PlaceholderShimmerSample : ComponentActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - setContent { - AccompanistSampleTheme { - Sample() - } - } - } -} - -@OptIn(ExperimentalCoilApi::class, ExperimentalMaterialApi::class) -@Composable -private fun Sample() { - Scaffold( - topBar = { - TopAppBar( - title = { Text(stringResource(R.string.placeholder_title_shimmer)) }, - backgroundColor = MaterialTheme.colors.surface, - ) - }, - modifier = Modifier.fillMaxSize() - ) { padding -> - // Simulate a fake 2-second 'load'. Ideally this 'refreshing' value would - // come from a ViewModel or similar - var refreshing by remember { mutableStateOf(false) } - LaunchedEffect(refreshing) { - if (refreshing) { - delay(4000) - refreshing = false - } - } - - val state = rememberPullRefreshState( - refreshing = refreshing, - onRefresh = { refreshing = true } - ) - - Box(Modifier.pullRefresh(state)) { - LazyColumn(contentPadding = padding) { - if (refreshing.not()) { - item { - ListItem( - painter = rememberVectorPainter(Icons.Default.ArrowDownward), - text = "Pull down" - ) - } - } - items(30) { index -> - ListItem( - painter = rememberImagePainter(randomSampleImageUrl(index)), - text = "Text", - // We're using the modifier provided by placeholder-material which - // uses good default values for the color - childModifier = Modifier.placeholder( - visible = refreshing, - highlight = PlaceholderHighlight.shimmer(), - ) - ) - } - } - - PullRefreshIndicator( - refreshing = refreshing, - state = state, - modifier = Modifier.align(Alignment.TopCenter) - ) - } - } -}