diff --git a/.github/ISSUE_TEMPLATE/insets-bug-report.md b/.github/ISSUE_TEMPLATE/insets-bug-report.md
deleted file mode 100644
index 77e8a9c18..000000000
--- a/.github/ISSUE_TEMPLATE/insets-bug-report.md
+++ /dev/null
@@ -1,16 +0,0 @@
----
-name: Insets bug report
-about: Create a report about insets
-title: "[Insets]"
-labels: insets
-assignees: alexvanyo
-
----
-
-**Description**
-
-**Steps to reproduce**
-
-**Expected behavior**
-
-**Additional context**
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 951989e5d..5892dfeff 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -4,6 +4,6 @@
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 2d2ecfa2e..85a87be67 100644
--- a/README.md
+++ b/README.md
@@ -67,9 +67,6 @@ A library providing a collection of utilities for adaptive layouts.
### 🗜 [Test Harness](./testharness/)
Utilities for testing Compose layouts.
-### 📐 [Insets](./insets/) (Deprecated)
-See our [Migration Guide](https://google.github.io/accompanist/insets/) for migrating to Insets in Compose.
-
### ⬇️ [Swipe to Refresh](./swiperefresh/) (Deprecated)
See our [Migration Guide](https://google.github.io/accompanist/swiperefresh/) for migrating to PullRefresh in Compose Material.
@@ -88,6 +85,9 @@ See our [Migration Guide](https://google.github.io/accompanist/navigation-animat
### ⏳ [Placeholder](./placeholder/) (Deprecated)
A library that provides easy-to-use modifiers for displaying a placeholder UI while content is loading.
+### 📐 [Insets](./insets/) (Deprecated & Removed)
+See our [Migration Guide](https://google.github.io/accompanist/insets/) for migrating to Insets in Compose.
+
---
## Future?
diff --git a/insets-ui/build.gradle.kts b/insets-ui/build.gradle.kts
index e7c325b3b..538727f8f 100644
--- a/insets-ui/build.gradle.kts
+++ b/insets-ui/build.gradle.kts
@@ -100,7 +100,6 @@ metalava {
}
dependencies {
- api(project(":insets"))
api(libs.compose.material.material)
implementation(libs.kotlin.coroutines.android)
diff --git a/insets/README.md b/insets/README.md
deleted file mode 100644
index f4dcf8f48..000000000
--- a/insets/README.md
+++ /dev/null
@@ -1,24 +0,0 @@
-# Insets for Jetpack Compose (Deprecated)
-
-[![Maven Central](https://img.shields.io/maven-central/v/com.google.accompanist/accompanist-insets)](https://search.maven.org/search?q=g:com.google.accompanist)
-
-> :warning: This library has been deprecated as official support is now available in Compose 1.2.0. Please see our [Migration Guide](https://google.github.io/accompanist/insets/) for how to migrate.
-
-For more information, visit the documentation: https://google.github.io/accompanist/insets
-
-## Download
-
-```groovy
-repositories {
- mavenCentral()
-}
-
-dependencies {
- implementation "com.google.accompanist:accompanist-insets:"
-}
-```
-
-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-insets/
diff --git a/insets/api/current.api b/insets/api/current.api
deleted file mode 100644
index 795630e4f..000000000
--- a/insets/api/current.api
+++ /dev/null
@@ -1,147 +0,0 @@
-// Signature format: 4.0
-package com.google.accompanist.insets {
-
- @kotlin.RequiresOptIn(message="Animated Insets support is experimental. The API may be changed in the future.") @kotlin.annotation.Retention(kotlin.annotation.AnnotationRetention.BINARY) @kotlin.annotation.Target(allowedTargets={kotlin.annotation.AnnotationTarget.CLASS, kotlin.annotation.AnnotationTarget.FUNCTION}) public @interface ExperimentalAnimatedInsets {
- }
-
- @Deprecated public enum HorizontalSide {
- method @Deprecated public static com.google.accompanist.insets.HorizontalSide valueOf(String name) throws java.lang.IllegalArgumentException;
- method @Deprecated public static com.google.accompanist.insets.HorizontalSide[] values();
- enum_constant @Deprecated public static final com.google.accompanist.insets.HorizontalSide Left;
- enum_constant @Deprecated public static final com.google.accompanist.insets.HorizontalSide Right;
- }
-
- @Deprecated @com.google.accompanist.insets.ExperimentalAnimatedInsets public final class ImeNestedScrollConnection implements androidx.compose.ui.input.nestedscroll.NestedScrollConnection {
- ctor @Deprecated public ImeNestedScrollConnection(android.view.View view, boolean scrollImeOffScreenWhenVisible, boolean scrollImeOnScreenWhenNotVisible);
- method @Deprecated public suspend Object? onPostFling(long consumed, long available, kotlin.coroutines.Continuation super androidx.compose.ui.unit.Velocity>);
- method @Deprecated public long onPostScroll(long consumed, long available, int source);
- method @Deprecated public long onPreScroll(long available, int source);
- }
-
- public final class ImeNestedScrollConnectionKt {
- method @Deprecated @androidx.compose.runtime.Composable @com.google.accompanist.insets.ExperimentalAnimatedInsets public static androidx.compose.ui.input.nestedscroll.NestedScrollConnection rememberImeNestedScrollConnection(optional boolean scrollImeOffScreenWhenVisible, optional boolean scrollImeOnScreenWhenNotVisible);
- }
-
- @Deprecated @androidx.compose.runtime.Stable public interface Insets {
- method @Deprecated public default com.google.accompanist.insets.Insets copy(optional int left, optional int top, optional int right, optional int bottom);
- method @Deprecated @IntRange(from=0L) public int getBottom();
- method @Deprecated @IntRange(from=0L) public int getLeft();
- method @Deprecated @IntRange(from=0L) public int getRight();
- method @Deprecated @IntRange(from=0L) public int getTop();
- method @Deprecated public default operator com.google.accompanist.insets.Insets minus(com.google.accompanist.insets.Insets other);
- method @Deprecated public default operator com.google.accompanist.insets.Insets plus(com.google.accompanist.insets.Insets other);
- property @IntRange(from=0L) public abstract int bottom;
- property @IntRange(from=0L) public abstract int left;
- property @IntRange(from=0L) public abstract int right;
- property @IntRange(from=0L) public abstract int top;
- field @Deprecated public static final com.google.accompanist.insets.Insets.Companion Companion;
- }
-
- @Deprecated public static final class Insets.Companion {
- method @Deprecated public com.google.accompanist.insets.Insets Insets(optional int left, optional int top, optional int right, optional int bottom);
- method @Deprecated public com.google.accompanist.insets.Insets getEmpty();
- property public final com.google.accompanist.insets.Insets Empty;
- }
-
- public final class InsetsKt {
- method @Deprecated public static com.google.accompanist.insets.Insets coerceEachDimensionAtLeast(com.google.accompanist.insets.Insets, com.google.accompanist.insets.Insets minimumValue);
- }
-
- public final class PaddingKt {
- method @Deprecated public static inline androidx.compose.ui.Modifier cutoutPadding(androidx.compose.ui.Modifier, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom);
- method @Deprecated public static inline androidx.compose.ui.Modifier imePadding(androidx.compose.ui.Modifier);
- method @Deprecated public static inline androidx.compose.ui.Modifier navigationBarsPadding(androidx.compose.ui.Modifier, optional boolean bottom, optional boolean start, optional boolean end);
- method @Deprecated public static inline androidx.compose.ui.Modifier navigationBarsWithImePadding(androidx.compose.ui.Modifier);
- method @Deprecated @androidx.compose.runtime.Composable public static androidx.compose.foundation.layout.PaddingValues rememberInsetsPaddingValues(com.google.accompanist.insets.Insets insets, optional boolean applyStart, optional boolean applyTop, optional boolean applyEnd, optional boolean applyBottom, optional float additionalStart, optional float additionalTop, optional float additionalEnd, optional float additionalBottom);
- method @Deprecated public static inline androidx.compose.ui.Modifier statusBarsPadding(androidx.compose.ui.Modifier);
- method @Deprecated public static inline androidx.compose.ui.Modifier systemBarsPadding(androidx.compose.ui.Modifier, optional boolean enabled);
- method @Deprecated public static inline androidx.compose.ui.Modifier systemBarsPadding(androidx.compose.ui.Modifier, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom);
- method @Deprecated @androidx.compose.runtime.Composable public static inline androidx.compose.foundation.layout.PaddingValues toPaddingValues(com.google.accompanist.insets.WindowInsets.Type, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom, optional float additionalHorizontal, optional float additionalVertical);
- method @Deprecated @androidx.compose.runtime.Composable public static inline androidx.compose.foundation.layout.PaddingValues toPaddingValues(com.google.accompanist.insets.WindowInsets.Type, optional boolean start, optional boolean top, optional boolean end, optional boolean bottom, optional float additionalStart, optional float additionalTop, optional float additionalEnd, optional float additionalBottom);
- }
-
- public final class SimpleImeAnimationControllerKt {
- }
-
- public final class SizeKt {
- method @Deprecated public static androidx.compose.ui.Modifier navigationBarsHeight(androidx.compose.ui.Modifier, optional float additional);
- method @Deprecated public static androidx.compose.ui.Modifier navigationBarsWidth(androidx.compose.ui.Modifier, com.google.accompanist.insets.HorizontalSide side, optional float additional);
- method @Deprecated public static androidx.compose.ui.Modifier statusBarsHeight(androidx.compose.ui.Modifier, optional float additional);
- }
-
- @Deprecated public enum VerticalSide {
- method @Deprecated public static com.google.accompanist.insets.VerticalSide valueOf(String name) throws java.lang.IllegalArgumentException;
- method @Deprecated public static com.google.accompanist.insets.VerticalSide[] values();
- enum_constant @Deprecated public static final com.google.accompanist.insets.VerticalSide Bottom;
- enum_constant @Deprecated public static final com.google.accompanist.insets.VerticalSide Top;
- }
-
- @Deprecated public final class ViewWindowInsetObserver {
- ctor @Deprecated public ViewWindowInsetObserver(android.view.View view);
- method @Deprecated public boolean isObserving();
- method @Deprecated public com.google.accompanist.insets.WindowInsets start(optional boolean consumeWindowInsets, optional boolean windowInsetsAnimationsEnabled);
- method @Deprecated public void stop();
- property public final boolean isObserving;
- }
-
- @Deprecated @androidx.compose.runtime.Stable public interface WindowInsets {
- method @Deprecated public default com.google.accompanist.insets.WindowInsets copy(optional com.google.accompanist.insets.WindowInsets.Type navigationBars, optional com.google.accompanist.insets.WindowInsets.Type statusBars, optional com.google.accompanist.insets.WindowInsets.Type systemGestures, optional com.google.accompanist.insets.WindowInsets.Type ime, optional com.google.accompanist.insets.WindowInsets.Type displayCutout);
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getDisplayCutout();
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getIme();
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getNavigationBars();
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getStatusBars();
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getSystemBars();
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getSystemGestures();
- property public abstract com.google.accompanist.insets.WindowInsets.Type displayCutout;
- property public abstract com.google.accompanist.insets.WindowInsets.Type ime;
- property public abstract com.google.accompanist.insets.WindowInsets.Type navigationBars;
- property public abstract com.google.accompanist.insets.WindowInsets.Type statusBars;
- property public abstract com.google.accompanist.insets.WindowInsets.Type systemBars;
- property public abstract com.google.accompanist.insets.WindowInsets.Type systemGestures;
- field @Deprecated public static final com.google.accompanist.insets.WindowInsets.Companion Companion;
- }
-
- @Deprecated public static final class WindowInsets.Companion {
- method @Deprecated public com.google.accompanist.insets.WindowInsets getEmpty();
- property public final com.google.accompanist.insets.WindowInsets Empty;
- }
-
- @Deprecated @androidx.compose.runtime.Stable public static interface WindowInsets.Type extends com.google.accompanist.insets.Insets {
- method @Deprecated public com.google.accompanist.insets.Insets getAnimatedInsets();
- method @Deprecated @FloatRange(from=0.0, to=1.0) public float getAnimationFraction();
- method @Deprecated public boolean getAnimationInProgress();
- method @Deprecated public default int getBottom();
- method @Deprecated public com.google.accompanist.insets.Insets getLayoutInsets();
- method @Deprecated public default int getLeft();
- method @Deprecated public default int getRight();
- method @Deprecated public default int getTop();
- method @Deprecated public boolean isVisible();
- property public abstract com.google.accompanist.insets.Insets animatedInsets;
- property @FloatRange(from=0.0, to=1.0) public abstract float animationFraction;
- property public abstract boolean animationInProgress;
- property public default int bottom;
- property public abstract boolean isVisible;
- property public abstract com.google.accompanist.insets.Insets layoutInsets;
- property public default int left;
- property public default int right;
- property public default int top;
- field @Deprecated public static final com.google.accompanist.insets.WindowInsets.Type.Companion Companion;
- }
-
- @Deprecated public static final class WindowInsets.Type.Companion {
- method @Deprecated public com.google.accompanist.insets.WindowInsets.Type getEmpty();
- property public final com.google.accompanist.insets.WindowInsets.Type Empty;
- }
-
- public final class WindowInsetsKt {
- method @Deprecated @androidx.compose.runtime.Composable public static void ProvideWindowInsets(optional boolean consumeWindowInsets, optional boolean windowInsetsAnimationsEnabled, kotlin.jvm.functions.Function0 content);
- method @Deprecated public static androidx.compose.runtime.ProvidableCompositionLocal getLocalWindowInsets();
- property @Deprecated public static final androidx.compose.runtime.ProvidableCompositionLocal LocalWindowInsets;
- }
-
- public final class WindowInsetsTypeKt {
- method @Deprecated public static com.google.accompanist.insets.WindowInsets.Type derivedWindowInsetsTypeOf(com.google.accompanist.insets.WindowInsets.Type... types);
- }
-
-}
-
diff --git a/insets/build.gradle.kts b/insets/build.gradle.kts
deleted file mode 100644
index 7ee461ca5..000000000
--- a/insets/build.gradle.kts
+++ /dev/null
@@ -1,127 +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.insets"
-
- compileSdk = 33
-
- 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
- }
-
- 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")
- }
- }
-}
-
-metalava {
- sourcePaths.setFrom("src/main")
- filename.set("api/current.api")
- reportLintsAsErrors.set(true)
-}
-
-dependencies {
- implementation(libs.androidx.core)
- implementation(libs.androidx.dynamicanimation)
-
- implementation(libs.compose.foundation.foundation)
- 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/insets/gradle.properties b/insets/gradle.properties
deleted file mode 100644
index 214b56a69..000000000
--- a/insets/gradle.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-POM_ARTIFACT_ID=accompanist-insets
-POM_NAME=Accompanist Insets library
-POM_PACKAGING=aar
\ No newline at end of file
diff --git a/insets/src/androidTest/AndroidManifest.xml b/insets/src/androidTest/AndroidManifest.xml
deleted file mode 100644
index 22a862eb3..000000000
--- a/insets/src/androidTest/AndroidManifest.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/insets/src/androidTest/kotlin/com/google/accompanist/insets/InstrumentedInsetsTest.kt b/insets/src/androidTest/kotlin/com/google/accompanist/insets/InstrumentedInsetsTest.kt
deleted file mode 100644
index f93d175b3..000000000
--- a/insets/src/androidTest/kotlin/com/google/accompanist/insets/InstrumentedInsetsTest.kt
+++ /dev/null
@@ -1,40 +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.insets
-
-import androidx.compose.ui.unit.LayoutDirection
-import org.junit.runner.RunWith
-import org.junit.runners.Parameterized
-
-/**
- * Version of [BaseInsetsTest] which is designed to be run on device/emulators.
- */
-@RunWith(Parameterized::class)
-class InstrumentedInsetsTest(
- type: TestInsetType,
- applyStart: Boolean,
- applyTop: Boolean,
- applyEnd: Boolean,
- applyBottom: Boolean,
- layoutDirection: LayoutDirection,
-) : BaseInsetsTest(type, applyStart, applyTop, applyEnd, applyBottom, layoutDirection) {
- companion object {
- @JvmStatic
- @Parameterized.Parameters
- fun data(): Collection> = params()
- }
-}
diff --git a/insets/src/main/AndroidManifest.xml b/insets/src/main/AndroidManifest.xml
deleted file mode 100644
index 7de13f329..000000000
--- a/insets/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
diff --git a/insets/src/main/java/com/google/accompanist/insets/ImeNestedScrollConnection.kt b/insets/src/main/java/com/google/accompanist/insets/ImeNestedScrollConnection.kt
deleted file mode 100644
index 05a087541..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/ImeNestedScrollConnection.kt
+++ /dev/null
@@ -1,232 +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.insets
-
-import android.os.Build
-import android.view.View
-import android.view.WindowInsets
-import androidx.annotation.RequiresApi
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.remember
-import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
-import androidx.compose.ui.input.nestedscroll.NestedScrollSource
-import androidx.compose.ui.platform.LocalView
-import androidx.compose.ui.unit.Velocity
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.suspendCancellableCoroutine
-import kotlin.math.roundToInt
-
-/**
- * Remembers a [NestedScrollConnection] which scrolls the Android on-screen keyboard on/off
- * screen as appropriate.
- *
- * To be superceded: https://issuetracker.google.com/217770710
- *
- * @param scrollImeOffScreenWhenVisible Set to true to allow scrolling the IME off screen
- * (from being visible), by an downwards scroll. Defaults to `true`.
- * @param scrollImeOnScreenWhenNotVisible Set to true to allow scrolling the IME on screen
- * (from not being visible), by an upwards scroll. Defaults to `true`.
- */
-@ExperimentalAnimatedInsets
-@Composable
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "Modifier.imeNestedScroll()",
- "androidx.compose.foundation.layout.imeNestedScroll",
- "androidx.compose.ui.Modifier"
- )
-)
-fun rememberImeNestedScrollConnection(
- scrollImeOffScreenWhenVisible: Boolean = true,
- scrollImeOnScreenWhenNotVisible: Boolean = true,
-): NestedScrollConnection {
- val view = LocalView.current
- return remember(view, scrollImeOffScreenWhenVisible, scrollImeOnScreenWhenNotVisible) {
- ImeNestedScrollConnection(
- view = view,
- scrollImeOffScreenWhenVisible = scrollImeOffScreenWhenVisible,
- scrollImeOnScreenWhenNotVisible = scrollImeOnScreenWhenNotVisible
- )
- }
-}
-
-/**
- * A [NestedScrollConnection] which scrolls the Android on-screen keyboard on/off
- * screen as appropriate, when the user scrolls content. This class may be made an internal
- * library class in the future.
- *
- * You probably do not wish to use this directly, and should use
- * [rememberImeNestedScrollConnection] instead.
- *
- * @param view The host Compose [View]. Usually this comes from [LocalView].
- * @param scrollImeOffScreenWhenVisible Set to true to allow scrolling the IME off screen
- * (from being visible), by an downwards scroll. Defaults to `true`.
- * @param scrollImeOnScreenWhenNotVisible Set to true to allow scrolling the IME on screen
- * (from not being visible), by an upwards scroll. Defaults to `true`.
- */
-@ExperimentalAnimatedInsets
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "Modifier.imeNestedScroll()",
- "androidx.compose.foundation.layout.imeNestedScroll",
- "androidx.compose.ui.Modifier"
- )
-)
-class ImeNestedScrollConnection(
- private val view: View,
- private val scrollImeOffScreenWhenVisible: Boolean,
- private val scrollImeOnScreenWhenNotVisible: Boolean,
-) : NestedScrollConnection {
-
- @delegate:RequiresApi(30)
- private val imeAnimController by lazy(LazyThreadSafetyMode.NONE, ::SimpleImeAnimationController)
-
- @get:RequiresApi(30)
- private val imeVisible: Boolean
- get() = view.rootWindowInsets.isVisible(WindowInsets.Type.ime())
-
- override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
- if (Build.VERSION.SDK_INT < 30) {
- // SimpleImeAnimationController only works on API 30+
- return Offset.Zero
- }
-
- if (imeAnimController.isInsetAnimationRequestPending()) {
- // We're waiting for a controller to become ready. Consume and no-op the scroll
- return available
- }
-
- if (available.y > 0) {
- // If the user is scrolling down...
-
- if (imeAnimController.isInsetAnimationInProgress()) {
- // If we currently have control, we can update the IME insets using insetBy()
- return Offset(
- x = 0f,
- y = imeAnimController.insetBy(available.y.roundToInt()).toFloat()
- )
- }
-
- if (scrollImeOffScreenWhenVisible && imeVisible) {
- // If we're not in control, the IME is currently open, and,
- // 'scroll IME away when visible' is enabled, we start a control request
- imeAnimController.startControlRequest(view)
-
- // We consume the scroll to stop the list scrolling while we wait for a controller
- return available
- }
- }
-
- return Offset.Zero
- }
-
- override fun onPostScroll(
- consumed: Offset,
- available: Offset,
- source: NestedScrollSource
- ): Offset {
- if (Build.VERSION.SDK_INT < 30) {
- // SimpleImeAnimationController only works on API 30+
- return Offset.Zero
- }
-
- if (available.y < 0) {
- // If the user is scrolling up, and the scrolling view isn't consuming the scroll...
-
- if (imeAnimController.isInsetAnimationInProgress()) {
- // If we currently have control, we can update the IME insets
- return Offset(
- x = 0f,
- y = imeAnimController.insetBy(available.y.roundToInt()).toFloat()
- )
- }
-
- if (scrollImeOnScreenWhenNotVisible &&
- !imeAnimController.isInsetAnimationRequestPending() &&
- !imeVisible
- ) {
- // If we don't currently have control, the IME is not shown,
- // the user is scrolling up, and the view can't scroll up any more
- // (i.e. over-scrolling), we can start to control the IME insets
- imeAnimController.startControlRequest(view = view)
- // We consume the scroll to stop the list scrolling while we wait for a controller
- return available
- }
- }
-
- return Offset.Zero
- }
-
- @OptIn(ExperimentalCoroutinesApi::class)
- override suspend fun onPostFling(
- consumed: Velocity,
- available: Velocity
- ): Velocity {
- if (Build.VERSION.SDK_INT < 30) {
- // SimpleImeAnimationController only works on API 30+
- return Velocity.Zero
- }
-
- if (imeAnimController.isInsetAnimationInProgress()) {
- // If we have an IME animation in progress, from the user scrolling, we can
- // animate to the end state using the velocity
- return suspendCancellableCoroutine { cont ->
- imeAnimController.animateToFinish(available.y) { remainingVelocity ->
- cont.resume(
- value = Velocity(x = 0f, y = remainingVelocity),
- onCancellation = { imeAnimController.finish() }
- )
- }
- // If the coroutine is cancelled, cancel the IME animation
- cont.invokeOnCancellation {
- imeAnimController.cancel()
- }
- }
- }
-
- // If the fling is in a (upwards direction, and the IME is not visible)
- // start an control request with an immediate fling
- if (scrollImeOnScreenWhenNotVisible && available.y > 0 == imeVisible) {
- return suspendCancellableCoroutine { cont ->
- imeAnimController.startAndFling(view, available.y) { remainingVelocity ->
- cont.resume(
- value = Velocity(x = 0f, y = remainingVelocity),
- onCancellation = { imeAnimController.finish() }
- )
- }
- // If the coroutine is cancelled, cancel the IME animation
- cont.invokeOnCancellation {
- imeAnimController.cancel()
- }
- }
- }
-
- // If we reach here we just return zero velocity
- return Velocity.Zero
- }
-}
diff --git a/insets/src/main/java/com/google/accompanist/insets/Insets.kt b/insets/src/main/java/com/google/accompanist/insets/Insets.kt
deleted file mode 100644
index fcc74a102..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/Insets.kt
+++ /dev/null
@@ -1,176 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.insets
-
-import androidx.annotation.IntRange
-import androidx.compose.runtime.Immutable
-import androidx.compose.runtime.Stable
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-
-/**
- * Interface which represents a single set of inset values. Each instance holds four integer
- * offsets which describe changes to the four edges of a rectangle.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-The androidx.compose equivalent of Insets is WindowInsets.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-@Stable
-interface Insets {
- /**
- * The left dimension of these insets in pixels.
- */
- @get:IntRange(from = 0)
- val left: Int
-
- /**
- * The top dimension of these insets in pixels.
- */
- @get:IntRange(from = 0)
- val top: Int
-
- /**
- * The right dimension of these insets in pixels.
- */
- @get:IntRange(from = 0)
- val right: Int
-
- /**
- * The bottom dimension of these insets in pixels.
- */
- @get:IntRange(from = 0)
- val bottom: Int
-
- /**
- * Returns a copy of this instance with the given values.
- */
- fun copy(
- left: Int = this.left,
- top: Int = this.top,
- right: Int = this.right,
- bottom: Int = this.bottom,
- ): Insets = ImmutableInsets(left, top, right, bottom)
-
- operator fun minus(other: Insets): Insets = copy(
- left = this.left - other.left,
- top = this.top - other.top,
- right = this.right - other.right,
- bottom = this.bottom - other.bottom,
- )
-
- operator fun plus(other: Insets): Insets = copy(
- left = this.left + other.left,
- top = this.top + other.top,
- right = this.right + other.right,
- bottom = this.bottom + other.bottom,
- )
-
- companion object {
- /**
- * Creates an [Insets] instance with the given values.
- */
- fun Insets(
- left: Int = 0,
- top: Int = 0,
- right: Int = 0,
- bottom: Int = 0,
- ): Insets = ImmutableInsets(left, top, right, bottom)
-
- /**
- * An empty [Insets] instance, with each dimension set to a value of 0.
- */
- val Empty: Insets = ImmutableInsets()
- }
-}
-
-/**
- * Immutable implementation of [Insets].
- */
-@Immutable
-internal class ImmutableInsets(
- override val left: Int = 0,
- override val top: Int = 0,
- override val right: Int = 0,
- override val bottom: Int = 0,
-) : Insets
-
-/**
- * Mutable [androidx.compose.runtime.State] backed implementation of [Insets].
- */
-internal class MutableInsets(
- left: Int = 0,
- top: Int = 0,
- right: Int = 0,
- bottom: Int = 0,
-) : Insets {
- override var left by mutableStateOf(left)
- override var top by mutableStateOf(top)
- override var right by mutableStateOf(right)
- override var bottom by mutableStateOf(bottom)
-
- fun reset() {
- left = 0
- top = 0
- right = 0
- bottom = 0
- }
-}
-
-/**
- * Updates our mutable state backed [WindowInsets.Type] from an Android system insets.
- */
-internal fun MutableInsets.updateFrom(insets: androidx.core.graphics.Insets) {
- left = insets.left
- top = insets.top
- right = insets.right
- bottom = insets.bottom
-}
-
-/**
- * Ensures that each dimension is not less than corresponding dimension in the
- * specified [minimumValue].
- *
- * @return this if every dimension is greater than or equal to the corresponding
- * dimension value in [minimumValue], otherwise a copy of this with each dimension coerced with the
- * corresponding dimension value in [minimumValue].
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-The androidx.compose equivalent is WindowInsets.copy.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-fun Insets.coerceEachDimensionAtLeast(minimumValue: Insets): Insets {
- return takeIf {
- // Fast path, no need to copy if: this >= minimumValue
- it.left >= minimumValue.left && it.top >= minimumValue.top &&
- it.right >= minimumValue.right && it.bottom >= minimumValue.bottom
- } ?: MutableInsets(
- left = left.coerceAtLeast(minimumValue.left),
- top = top.coerceAtLeast(minimumValue.top),
- right = right.coerceAtLeast(minimumValue.right),
- bottom = bottom.coerceAtLeast(minimumValue.bottom),
- )
-}
diff --git a/insets/src/main/java/com/google/accompanist/insets/Padding.kt b/insets/src/main/java/com/google/accompanist/insets/Padding.kt
deleted file mode 100644
index 9a6a52870..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/Padding.kt
+++ /dev/null
@@ -1,474 +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.
- */
-
-@file:Suppress("NOTHING_TO_INLINE", "unused", "DEPRECATION")
-
-package com.google.accompanist.insets
-
-import androidx.compose.foundation.layout.PaddingValues
-import androidx.compose.foundation.layout.padding
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.Stable
-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.platform.LocalDensity
-import androidx.compose.ui.unit.Density
-import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.LayoutDirection
-import androidx.compose.ui.unit.dp
-
-/**
- * Selectively apply additional space which matches the width/height of any system bars present
- * on the respective edges of the screen.
- *
- * @param enabled Whether to apply padding using the system bars dimensions on the respective edges.
- * Defaults to `true`.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "systemBarsPadding()",
- "androidx.compose.foundation.layout.systemBarsPadding"
- )
-)
-inline fun Modifier.systemBarsPadding(enabled: Boolean = true): Modifier = composed {
- padding(
- rememberInsetsPaddingValues(
- insets = LocalWindowInsets.current.systemBars,
- applyStart = enabled,
- applyTop = enabled,
- applyEnd = enabled,
- applyBottom = enabled
- )
- )
-}
-
-/**
- * Selectively apply additional space which matches the width/height of any system bars present
- * on the respective edges of the screen.
- *
- * @param start Whether to apply padding to the start edge, which matches the system bars width
- * (if present) on the start edge of the screen. Defaults to `true`.
- * @param top Whether to apply padding to the top edge, which matches the system bars height
- * (if present) at the top edge of the screen. Defaults to `true`.
- * @param end Whether to apply padding to the end edge, which matches the system bars width
- * (if present) on the end edge of the screen. Defaults to `true`.
- * @param bottom Whether to apply padding to the bottom edge, which matches the system bars
- * height (if present) at the bottom edge of the screen. Defaults to `true`.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "systemBarsPadding()",
- "androidx.compose.foundation.layout.systemBarsPadding"
- )
-)
-inline fun Modifier.systemBarsPadding(
- start: Boolean = true,
- top: Boolean = true,
- end: Boolean = true,
- bottom: Boolean = true,
-): Modifier = composed {
- padding(
- rememberInsetsPaddingValues(
- insets = LocalWindowInsets.current.systemBars,
- applyStart = start,
- applyTop = top,
- applyEnd = end,
- applyBottom = bottom
- )
- )
-}
-
-/**
- * Apply additional space which matches the height of the status bars height along the top edge
- * of the content.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "statusBarsPadding()",
- "androidx.compose.foundation.layout.statusBarsPadding"
- )
-)
-inline fun Modifier.statusBarsPadding(): Modifier = composed {
- padding(
- rememberInsetsPaddingValues(
- insets = LocalWindowInsets.current.statusBars,
- applyTop = true
- )
- )
-}
-
-/**
- * Apply additional space which matches the height of the navigation bars height
- * along the [bottom] edge of the content, and additional space which matches the width of
- * the navigation bars on the respective [start] and [end] edges.
- *
- * @param bottom Whether to apply padding to the bottom edge, which matches the navigation bars
- * height (if present) at the bottom edge of the screen. Defaults to `true`.
- * @param start Whether to apply padding to the start edge, which matches the navigation bars width
- * (if present) on the start edge of the screen. Defaults to `true`.
- * @param end Whether to apply padding to the end edge, which matches the navigation bars width
- * (if present) on the end edge of the screen. Defaults to `true`.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "navigationBarsPadding()",
- "androidx.compose.foundation.layout.navigationBarsPadding"
- )
-)
-inline fun Modifier.navigationBarsPadding(
- bottom: Boolean = true,
- start: Boolean = true,
- end: Boolean = true,
-): Modifier = composed {
- padding(
- rememberInsetsPaddingValues(
- insets = LocalWindowInsets.current.navigationBars,
- applyStart = start,
- applyEnd = end,
- applyBottom = bottom
- )
- )
-}
-
-/**
- * Apply additional space which matches the height of the [WindowInsets.ime] (on-screen keyboard)
- * height along the bottom edge of the content.
- *
- * This method has no special handling for the [WindowInsets.navigationBars], which usually
- * intersect the [WindowInsets.ime]. Most apps will usually want to use the
- * [Modifier.navigationBarsWithImePadding] modifier.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "imePadding()",
- "androidx.compose.foundation.layout.imePadding"
- )
-)
-inline fun Modifier.imePadding(): Modifier = composed {
- padding(
- rememberInsetsPaddingValues(
- insets = LocalWindowInsets.current.ime,
- applyStart = true,
- applyEnd = true,
- applyBottom = true
- )
- )
-}
-
-/**
- * Selectively apply additional space which matches the width/height of any display cutout present
- * on the respective edges of the screen.
- *
- * @param start Whether to apply padding to the start edge, which matches the display cutout width
- * (if present) on the start edge of the screen. Defaults to `true`.
- * @param top Whether to apply padding to the top edge, which matches the display cutout height
- * (if present) at the top edge of the screen. Defaults to `true`.
- * @param end Whether to apply padding to the end edge, which matches the display cutout width
- * (if present) on the end edge of the screen. Defaults to `true`.
- * @param bottom Whether to apply padding to the bottom edge, which matches the display cutout
- * height (if present) at the bottom edge of the screen. Defaults to `true`.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "cutoutPadding()",
- "androidx.compose.foundation.layout.cutoutPadding"
- )
-)
-inline fun Modifier.cutoutPadding(
- start: Boolean = true,
- top: Boolean = true,
- end: Boolean = true,
- bottom: Boolean = true,
-): Modifier = composed {
- padding(
- rememberInsetsPaddingValues(
- insets = LocalWindowInsets.current.displayCutout,
- applyStart = start,
- applyTop = top,
- applyEnd = end,
- applyBottom = bottom
- )
- )
-}
-
-/**
- * Apply additional space which matches the height of the [WindowInsets.ime] (on-screen keyboard)
- * height and [WindowInsets.navigationBars]. This is what apps should use to handle any insets
- * at the bottom of the screen.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "navigationBarsPadding().imePadding()",
- "androidx.compose.foundation.layout.navigationBarsPadding",
- "androidx.compose.foundation.layout.imePadding"
- )
-)
-inline fun Modifier.navigationBarsWithImePadding(): Modifier = composed {
- val ime = LocalWindowInsets.current.ime
- val navBars = LocalWindowInsets.current.navigationBars
- val insets = remember(ime, navBars) { derivedWindowInsetsTypeOf(ime, navBars) }
- padding(
- rememberInsetsPaddingValues(
- insets = insets,
- applyStart = true,
- applyEnd = true,
- applyBottom = true
- )
- )
-}
-
-/**
- * Returns the current insets converted into a [PaddingValues].
- *
- * @param start Whether to apply the inset on the start dimension.
- * @param top Whether to apply the inset on the top dimension.
- * @param end Whether to apply the inset on the end dimension.
- * @param bottom Whether to apply the inset on the bottom dimension.
- * @param additionalHorizontal Value to add to the start and end dimensions.
- * @param additionalVertical Value to add to the top and bottom dimensions.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- ReplaceWith(
- """rememberInsetsPaddingValues(
- insets = this,
- applyStart = start,
- applyTop = top,
- applyEnd = end,
- applyBottom = bottom,
- additionalStart = additionalHorizontal,
- additionalTop = additionalVertical,
- additionalEnd = additionalHorizontal,
- additionalBottom = additionalVertical
- )""",
- "com.google.accompanist.insets.rememberInsetsPaddingValues"
- )
-)
-@Composable
-inline fun WindowInsets.Type.toPaddingValues(
- start: Boolean = true,
- top: Boolean = true,
- end: Boolean = true,
- bottom: Boolean = true,
- additionalHorizontal: Dp = 0.dp,
- additionalVertical: Dp = 0.dp,
-): PaddingValues = rememberInsetsPaddingValues(
- insets = this,
- applyStart = start,
- applyTop = top,
- applyEnd = end,
- applyBottom = bottom,
- additionalStart = additionalHorizontal,
- additionalTop = additionalVertical,
- additionalEnd = additionalHorizontal,
- additionalBottom = additionalVertical
-)
-
-/**
- * Returns the current insets converted into a [PaddingValues].
- *
- * @param start Whether to apply the inset on the start dimension.
- * @param top Whether to apply the inset on the top dimension.
- * @param end Whether to apply the inset on the end dimension.
- * @param bottom Whether to apply the inset on the bottom dimension.
- * @param additionalStart Value to add to the start dimension.
- * @param additionalTop Value to add to the top dimension.
- * @param additionalEnd Value to add to the end dimension.
- * @param additionalBottom Value to add to the bottom dimension.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- ReplaceWith(
- """rememberInsetsPaddingValues(
- insets = this,
- applyStart = start,
- applyTop = top,
- applyEnd = end,
- applyBottom = bottom,
- additionalStart = additionalStart,
- additionalTop = additionalTop,
- additionalEnd = additionalEnd,
- additionalBottom = additionalBottom
- )""",
- "com.google.accompanist.insets.rememberInsetsPaddingValues"
- )
-)
-@Composable
-inline fun WindowInsets.Type.toPaddingValues(
- start: Boolean = true,
- top: Boolean = true,
- end: Boolean = true,
- bottom: Boolean = true,
- additionalStart: Dp = 0.dp,
- additionalTop: Dp = 0.dp,
- additionalEnd: Dp = 0.dp,
- additionalBottom: Dp = 0.dp,
-): PaddingValues = rememberInsetsPaddingValues(
- insets = this,
- applyStart = start,
- applyTop = top,
- applyEnd = end,
- applyBottom = bottom,
- additionalStart = additionalStart,
- additionalTop = additionalTop,
- additionalEnd = additionalEnd,
- additionalBottom = additionalBottom
-)
-
-/**
- * Returns the provided insets [insets] in the form of a [PaddingValues] instance.
- *
- * The returned instance is stable, meaning that any changes to the inset values will result in
- * composition being notified, and these padding values being re-read.
- *
- * @param insets The [WindowInsets.Type] to read from.
- * @param applyStart Whether to apply the inset on the start dimension. Defaults to true.
- * @param applyTop Whether to apply the inset on the top dimension. Defaults to true.
- * @param applyEnd Whether to apply the inset on the end dimension. Defaults to true.
- * @param applyBottom Whether to apply the inset on the bottom dimension. Defaults to true.
- * @param additionalStart Value to add to the start dimension.
- * @param additionalTop Value to add to the top dimension.
- * @param additionalEnd Value to add to the end dimension.
- * @param additionalBottom Value to add to the bottom dimension.
- */
-@Composable
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "insets.asPaddingValues()",
- "androidx.compose.foundation.layout.asPaddingValues"
- )
-)
-fun rememberInsetsPaddingValues(
- insets: Insets,
- applyStart: Boolean = true,
- applyTop: Boolean = true,
- applyEnd: Boolean = true,
- applyBottom: Boolean = true,
- additionalStart: Dp = 0.dp,
- additionalTop: Dp = 0.dp,
- additionalEnd: Dp = 0.dp,
- additionalBottom: Dp = 0.dp,
-): PaddingValues {
- val density = LocalDensity.current
-
- return remember(density, insets) {
- InsetsPaddingValues(insets = insets, density = density)
- }.apply {
- this.applyStart = applyStart
- this.applyTop = applyTop
- this.applyEnd = applyEnd
- this.applyBottom = applyBottom
-
- this.additionalStart = additionalStart
- this.additionalTop = additionalTop
- this.additionalEnd = additionalEnd
- this.additionalBottom = additionalBottom
- }
-}
-
-/**
- * Our [PaddingValues] implementation which is state-backed, reading values from [insets] as
- * appropriate. Can be created via [rememberInsetsPaddingValues].
- */
-@Stable
-internal class InsetsPaddingValues(
- private val insets: Insets,
- private val density: Density,
-) : PaddingValues {
- var applyStart: Boolean by mutableStateOf(false)
- var applyTop: Boolean by mutableStateOf(false)
- var applyEnd: Boolean by mutableStateOf(false)
- var applyBottom: Boolean by mutableStateOf(false)
-
- var additionalStart: Dp by mutableStateOf(0.dp)
- var additionalTop: Dp by mutableStateOf(0.dp)
- var additionalEnd: Dp by mutableStateOf(0.dp)
- var additionalBottom: Dp by mutableStateOf(0.dp)
-
- override fun calculateLeftPadding(layoutDirection: LayoutDirection): Dp {
- return when (layoutDirection) {
- LayoutDirection.Ltr -> {
- additionalStart + if (applyStart) with(density) { insets.left.toDp() } else 0.dp
- }
- LayoutDirection.Rtl -> {
- additionalEnd + if (applyEnd) with(density) { insets.left.toDp() } else 0.dp
- }
- }
- }
-
- override fun calculateTopPadding(): Dp = additionalTop + when {
- applyTop -> with(density) { insets.top.toDp() }
- else -> 0.dp
- }
-
- override fun calculateRightPadding(layoutDirection: LayoutDirection): Dp {
- return when (layoutDirection) {
- LayoutDirection.Ltr -> {
- additionalEnd + if (applyEnd) with(density) { insets.right.toDp() } else 0.dp
- }
- LayoutDirection.Rtl -> {
- additionalStart + if (applyStart) with(density) { insets.right.toDp() } else 0.dp
- }
- }
- }
-
- override fun calculateBottomPadding(): Dp = additionalBottom + when {
- applyBottom -> with(density) { insets.bottom.toDp() }
- else -> 0.dp
- }
-}
diff --git a/insets/src/main/java/com/google/accompanist/insets/SimpleImeAnimationController.kt b/insets/src/main/java/com/google/accompanist/insets/SimpleImeAnimationController.kt
deleted file mode 100644
index 03ff4c116..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/SimpleImeAnimationController.kt
+++ /dev/null
@@ -1,414 +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.insets
-
-import android.graphics.Insets
-import android.os.CancellationSignal
-import android.view.View
-import android.view.WindowInsets
-import android.view.WindowInsetsAnimationControlListener
-import android.view.WindowInsetsAnimationController
-import android.view.animation.LinearInterpolator
-import androidx.annotation.RequiresApi
-import androidx.dynamicanimation.animation.SpringAnimation
-import androidx.dynamicanimation.animation.SpringForce
-import androidx.dynamicanimation.animation.springAnimationOf
-import androidx.dynamicanimation.animation.withSpringForceProperties
-import kotlin.math.abs
-import kotlin.math.roundToInt
-
-/**
- * A wrapper around the new [WindowInsetsAnimationController] APIs in Android 11, to simplify
- * the implementation of common use-cases around the IME.
- *
- * This is taken from the [WindowInsetsAnimation](https://github.com/android/user-interface-samples/tree/master/WindowInsetsAnimation/)
- * sample.
- */
-@RequiresApi(30)
-internal class SimpleImeAnimationController {
- private var insetsAnimationController: WindowInsetsAnimationController? = null
- private var pendingRequestCancellationSignal: CancellationSignal? = null
- private var pendingRequestOnReady: ((WindowInsetsAnimationController) -> Unit)? = null
-
- /* To take control of the an WindowInsetsAnimation, we need to pass in a listener to
- controlWindowInsetsAnimation() in startControlRequest(). The listener created here
- keeps track of the current WindowInsetsAnimationController and resets our state. */
- private val animationControlListener: WindowInsetsAnimationControlListener by lazy {
- object : WindowInsetsAnimationControlListener {
- /**
- * Once the request is ready, call our [onRequestReady] function
- */
- override fun onReady(
- controller: WindowInsetsAnimationController,
- types: Int
- ) = onRequestReady(controller)
-
- /**
- * If the request is finished, we should reset our internal state
- */
- override fun onFinished(controller: WindowInsetsAnimationController) = reset()
-
- /**
- * If the request is cancelled, we should reset our internal state
- */
- override fun onCancelled(controller: WindowInsetsAnimationController?) = reset()
- }
- }
-
- /**
- * True if the IME was shown at the start of the current animation.
- */
- private var isImeShownAtStart = false
-
- private var currentSpringAnimation: SpringAnimation? = null
-
- /**
- * Start a control request to the [view]s [android.view.WindowInsetsController]. This should
- * be called once the view is in a position to take control over the position of the IME.
- *
- * @param view The view which is triggering this request
- * @param onRequestReady optional listener which will be called when the request is ready and
- * the animation can proceed
- */
- fun startControlRequest(
- view: View,
- onRequestReady: ((WindowInsetsAnimationController) -> Unit)? = null
- ) {
- check(!isInsetAnimationInProgress()) {
- "Animation in progress. Can not start a new request to controlWindowInsetsAnimation()"
- }
-
- // Keep track of the IME insets, and the IME visibility, at the start of the request
- isImeShownAtStart = view.rootWindowInsets.isVisible(WindowInsets.Type.ime())
-
- // Create a cancellation signal, which we pass to controlWindowInsetsAnimation() below
- pendingRequestCancellationSignal = CancellationSignal()
- // Keep reference to the onReady callback
- pendingRequestOnReady = onRequestReady
-
- // Finally we make a controlWindowInsetsAnimation() request:
- view.windowInsetsController?.controlWindowInsetsAnimation(
- // We're only catering for IME animations in this listener
- WindowInsets.Type.ime(),
- // Animation duration. This is not used by the system, and is only passed to any
- // WindowInsetsAnimation.Callback set on views. We pass in -1 to indicate that we're
- // not starting a finite animation, and that this is completely controlled by
- // the user's touch.
- -1,
- // The time interpolator used in calculating the animation progress. The fraction value
- // we passed into setInsetsAndAlpha() which be passed into this interpolator before
- // being used by the system to inset the IME. LinearInterpolator is a good type
- // to use for scrolling gestures.
- linearInterpolator,
- // A cancellation signal, which allows us to cancel the request to control
- pendingRequestCancellationSignal,
- // The WindowInsetsAnimationControlListener
- animationControlListener
- )
- }
-
- /**
- * Start a control request to the [view]s [android.view.WindowInsetsController], similar to
- * [startControlRequest], but immediately fling to a finish using [velocityY] once ready.
- *
- * This function is useful for fire-and-forget operations to animate the IME.
- *
- * @param view The view which is triggering this request
- * @param velocityY the velocity of the touch gesture which caused this call
- */
- fun startAndFling(
- view: View,
- velocityY: Float,
- onFinished: ((remainingVelocity: Float) -> Unit)? = null
- ) = startControlRequest(view) {
- animateToFinish(velocityY, onFinished = onFinished)
- }
-
- /**
- * Update the inset position of the IME by the given [dy] value. This value will be coerced
- * into the hidden and shown inset values.
- *
- * This function should only be called if [isInsetAnimationInProgress] returns true.
- *
- * @return the amount of [dy] consumed by the inset animation, in pixels
- */
- fun insetBy(dy: Int): Int {
- val controller = insetsAnimationController
- ?: throw IllegalStateException(
- "Current WindowInsetsAnimationController is null." +
- "This should only be called if isAnimationInProgress() returns true"
- )
-
- // Call updateInsetTo() with the new inset value
- return insetTo(controller.currentInsets.bottom - dy)
- }
-
- /**
- * Update the inset position of the IME to be the given [inset] value. This value will be
- * coerced into the hidden and shown inset values.
- *
- * This function should only be called if [isInsetAnimationInProgress] returns true.
- *
- * @return the distance moved by the inset animation, in pixels
- */
- fun insetTo(inset: Int): Int {
- val controller = insetsAnimationController
- ?: throw IllegalStateException(
- "Current WindowInsetsAnimationController is null." +
- "This should only be called if isAnimationInProgress() returns true"
- )
-
- val hiddenBottom = controller.hiddenStateInsets.bottom
- val shownBottom = controller.shownStateInsets.bottom
- val startBottom = if (isImeShownAtStart) shownBottom else hiddenBottom
- val endBottom = if (isImeShownAtStart) hiddenBottom else shownBottom
-
- // We coerce the given inset within the limits of the hidden and shown insets
- val coercedBottom = inset.coerceIn(hiddenBottom, shownBottom)
-
- val consumedDy = controller.currentInsets.bottom - coercedBottom
-
- // Finally update the insets in the WindowInsetsAnimationController using
- // setInsetsAndAlpha().
- controller.setInsetsAndAlpha(
- // Here we update the animating insets. This is what controls where the IME is displayed.
- // It is also passed through to views via their WindowInsetsAnimation.Callback.
- Insets.of(0, 0, 0, coercedBottom),
- // This controls the alpha value. We don't want to alter the alpha so use 1f
- 1f,
- // Finally we calculate the animation progress fraction. This value is passed through
- // to any WindowInsetsAnimation.Callbacks, but it is not used by the system.
- (coercedBottom - startBottom) / (endBottom - startBottom).toFloat()
- )
-
- return consumedDy
- }
-
- /**
- * Return [true] if an inset animation is in progress.
- */
- fun isInsetAnimationInProgress(): Boolean {
- return insetsAnimationController != null
- }
-
- /**
- * Return [true] if an inset animation is currently finishing.
- */
- fun isInsetAnimationFinishing(): Boolean {
- return currentSpringAnimation != null
- }
-
- /**
- * Return [true] if a request to control an inset animation is in progress.
- */
- fun isInsetAnimationRequestPending(): Boolean {
- return pendingRequestCancellationSignal != null
- }
-
- /**
- * Cancel the current [WindowInsetsAnimationController]. We immediately finish the animation,
- * reverting back to the state at the start of the gesture.
- */
- fun cancel() {
- insetsAnimationController?.finish(isImeShownAtStart)
- pendingRequestCancellationSignal?.cancel()
-
- // Cancel the current spring animation
- currentSpringAnimation?.cancel()
-
- reset()
- }
-
- /**
- * Finish the current [WindowInsetsAnimationController] immediately.
- */
- fun finish() {
- val controller = insetsAnimationController
-
- if (controller == null) {
- // If we don't currently have a controller, cancel any pending request and return
- pendingRequestCancellationSignal?.cancel()
- return
- }
-
- val current = controller.currentInsets.bottom
- val shown = controller.shownStateInsets.bottom
- val hidden = controller.hiddenStateInsets.bottom
-
- when (current) {
- // The current inset matches either the shown/hidden inset, finish() immediately
- shown -> controller.finish(true)
- hidden -> controller.finish(false)
- else -> {
- // Otherwise, we'll look at the current position...
- if (controller.currentFraction >= SCROLL_THRESHOLD) {
- // If the IME is past the 'threshold' we snap to the toggled state
- controller.finish(!isImeShownAtStart)
- } else {
- // ...otherwise, we snap back to the original visibility
- controller.finish(isImeShownAtStart)
- }
- }
- }
- }
-
- /**
- * Finish the current [WindowInsetsAnimationController]. We finish the animation,
- * animating to the end state if necessary.
- *
- * @param velocityY the velocity of the touch gesture which caused this call to [animateToFinish].
- * Can be `null` if velocity is not available.
- */
- fun animateToFinish(
- velocityY: Float? = null,
- onFinished: ((Float) -> Unit)? = null
- ) {
- val controller = insetsAnimationController
-
- if (controller == null) {
- // If we don't currently have a controller, cancel any pending request and return
- pendingRequestCancellationSignal?.cancel()
- return
- }
-
- val current = controller.currentInsets.bottom
- val shown = controller.shownStateInsets.bottom
- val hidden = controller.hiddenStateInsets.bottom
-
- // If we have a velocity, we can use it's direction to determine
- // the visibility. Upwards == visible
- if (velocityY != null) {
- val flingDistance = calculateFlingDistance(velocityY)
- // If the velocity would cause a fling distance which covers the IME height,
- // fling...
- if (flingDistance > abs(shown - hidden)) {
- animateImeToVisibility(
- visible = velocityY < 0,
- velocityY = velocityY
- )
- return
- }
- }
-
- when {
- // The current inset matches either the shown/hidden inset, finish() immediately
- current == shown -> {
- controller.finish(true)
- onFinished?.invoke(0f)
- }
- current == hidden -> {
- controller.finish(false)
- onFinished?.invoke(0f)
- }
- controller.currentFraction >= SCROLL_THRESHOLD -> {
- // If the IME is past the 'threshold' we animate it to the toggled state
- animateImeToVisibility(!isImeShownAtStart, onFinished = onFinished)
- }
- else -> {
- // ...otherwise, we animate it back to the original visibility
- animateImeToVisibility(isImeShownAtStart, onFinished = onFinished)
- }
- }
- }
-
- private fun onRequestReady(controller: WindowInsetsAnimationController) {
- // The request is ready, so clear out the pending cancellation signal
- pendingRequestCancellationSignal = null
- // Store the current WindowInsetsAnimationController
- insetsAnimationController = controller
-
- // Call any pending callback
- pendingRequestOnReady?.invoke(controller)
- pendingRequestOnReady = null
- }
-
- /**
- * Resets all of our internal state.
- */
- private fun reset() {
- // Clear all of our internal state
- insetsAnimationController = null
- pendingRequestCancellationSignal = null
-
- isImeShownAtStart = false
-
- currentSpringAnimation?.cancel()
- currentSpringAnimation = null
-
- pendingRequestOnReady = null
- }
-
- /**
- * Animate the IME to a given visibility.
- *
- * @param visible `true` to animate the IME to it's fully shown state, `false` to it's
- * fully hidden state.
- * @param velocityY the velocity of the touch gesture which caused this call. Can be `null`
- * if velocity is not available.
- */
- private fun animateImeToVisibility(
- visible: Boolean,
- velocityY: Float? = null,
- onFinished: ((Float) -> Unit)? = null,
- ) {
- val controller = insetsAnimationController
- ?: throw IllegalStateException("Controller should not be null")
-
- currentSpringAnimation = springAnimationOf(
- setter = { insetTo(it.roundToInt()) },
- getter = { controller.currentInsets.bottom.toFloat() },
- finalPosition = when {
- visible -> controller.shownStateInsets.bottom.toFloat()
- else -> controller.hiddenStateInsets.bottom.toFloat()
- }
- ).withSpringForceProperties {
- // Tweak the damping value, to remove any bounciness.
- dampingRatio = SpringForce.DAMPING_RATIO_NO_BOUNCY
- // The stiffness value controls the strength of the spring animation, which
- // controls the speed. Medium (the default) is a good value, but feel free to
- // play around with this value.
- stiffness = SpringForce.STIFFNESS_MEDIUM
- }.apply {
- if (velocityY != null) {
- setStartVelocity(velocityY)
- }
- addEndListener { anim, _, _, velocity ->
- if (anim == currentSpringAnimation) {
- currentSpringAnimation = null
- }
- // Once the animation has ended, finish the controller
- finish()
- onFinished?.invoke(velocity)
- }
- }.also { it.start() }
- }
-
- private fun calculateFlingDistance(velocity: Float, friction: Float = 1.0f): Float {
- return velocity / (friction * -4.2f)
- }
-}
-
-/**
- * Scroll threshold for determining whether to animating to the end state, or to the start state.
- * Currently 15% of the total swipe distance distance
- */
-private const val SCROLL_THRESHOLD = 0.15f
-
-/**
- * A LinearInterpolator instance we can re-use across listeners.
- */
-private val linearInterpolator = LinearInterpolator()
diff --git a/insets/src/main/java/com/google/accompanist/insets/Size.kt b/insets/src/main/java/com/google/accompanist/insets/Size.kt
deleted file mode 100644
index 626e9c118..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/Size.kt
+++ /dev/null
@@ -1,320 +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.
- */
-
-@file:Suppress("NOTHING_TO_INLINE", "unused", "DEPRECATION")
-
-package com.google.accompanist.insets
-
-import androidx.compose.foundation.layout.height
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.composed
-import androidx.compose.ui.layout.IntrinsicMeasurable
-import androidx.compose.ui.layout.IntrinsicMeasureScope
-import androidx.compose.ui.layout.LayoutModifier
-import androidx.compose.ui.layout.Measurable
-import androidx.compose.ui.layout.MeasureResult
-import androidx.compose.ui.layout.MeasureScope
-import androidx.compose.ui.unit.Constraints
-import androidx.compose.ui.unit.Density
-import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.dp
-
-/**
- * Represents a horizontal side of the display.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-The androidx.compose equivalent of HorizontalSide is using Modifier.windowInsetsStartWidth or
-Modifier.windowInsetsEndWidth with the desired type of WindowInsets.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-enum class HorizontalSide { Left, Right }
-
-/**
- * Represents a vertical side of the display.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-The androidx.compose equivalent of VerticalSide is using Modifier.windowInsetsTopHeight or
-Modifier.windowInsetsBottomHeight with the desired type of WindowInsets.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-enum class VerticalSide { Top, Bottom }
-
-/**
- * Declare the height of the content to match the height of the status bars exactly.
- *
- * This is very handy when used with `Spacer` to push content below the status bars:
- * ```
- * Column {
- * Spacer(Modifier.statusBarHeight())
- *
- * // Content to be drawn below status bars (y-axis)
- * }
- * ```
- *
- * It's also useful when used to draw a scrim which matches the status bars:
- * ```
- * Spacer(
- * Modifier.statusBarHeight()
- * .fillMaxWidth()
- * .drawBackground(MaterialTheme.colors.background.copy(alpha = 0.3f)
- * )
- * ```
- *
- * Internally this matches the behavior of the [Modifier.height] modifier.
- *
- * @param additional Any additional height to add to the status bars size.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "windowInsetsTopHeight(WindowInsets.statusBars)",
- "androidx.compose.foundation.layout.WindowInsets",
- "androidx.compose.foundation.layout.statusBars",
- "androidx.compose.foundation.layout.windowInsetsTopHeight"
- )
-)
-fun Modifier.statusBarsHeight(
- additional: Dp = 0.dp,
-): Modifier = composed {
- InsetsSizeModifier(
- insetsType = LocalWindowInsets.current.statusBars,
- heightSide = VerticalSide.Top,
- additionalHeight = additional
- )
-}
-
-/**
- * Declare the preferred height of the content to match the height of the navigation bars when
- * present at the bottom of the screen.
- *
- * This is very handy when used with `Spacer` to push content below the navigation bars:
- * ```
- * Column {
- * // Content to be drawn above status bars (y-axis)
- * Spacer(Modifier.navigationBarHeight())
- * }
- * ```
- *
- * It's also useful when used to draw a scrim which matches the navigation bars:
- * ```
- * Spacer(
- * Modifier.navigationBarHeight()
- * .fillMaxWidth()
- * .drawBackground(MaterialTheme.colors.background.copy(alpha = 0.3f)
- * )
- * ```
- *
- * Internally this matches the behavior of the [Modifier.height] modifier.
- *
- * @param additional Any additional height to add to the status bars size.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "windowInsetsBottomHeight(WindowInsets.navigationBars)",
- "androidx.compose.foundation.layout.WindowInsets",
- "androidx.compose.foundation.layout.navigationBars",
- "androidx.compose.foundation.layout.windowInsetsBottomHeight"
- )
-)
-fun Modifier.navigationBarsHeight(
- additional: Dp = 0.dp
-): Modifier = composed {
- InsetsSizeModifier(
- insetsType = LocalWindowInsets.current.navigationBars,
- heightSide = VerticalSide.Bottom,
- additionalHeight = additional
- )
-}
-
-/**
- * Declare the preferred width of the content to match the width of the navigation bars,
- * on the given [side].
- *
- * This is very handy when used with `Spacer` to push content inside from any vertical
- * navigation bars (typically when the device is in landscape):
- * ```
- * Row {
- * Spacer(Modifier.navigationBarWidth(HorizontalSide.Left))
- *
- * // Content to be inside the navigation bars (x-axis)
- *
- * Spacer(Modifier.navigationBarWidth(HorizontalSide.Right))
- * }
- * ```
- *
- * It's also useful when used to draw a scrim which matches the navigation bars:
- * ```
- * Spacer(
- * Modifier.navigationBarWidth(HorizontalSide.Left)
- * .fillMaxHeight()
- * .drawBackground(MaterialTheme.colors.background.copy(alpha = 0.3f)
- * )
- * ```
- *
- * Internally this matches the behavior of the [Modifier.height] modifier.
- *
- * @param side The navigation bar side to use as the source for the width.
- * @param additional Any additional width to add to the status bars size.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "windowInsetsStartWidth(WindowInsets.navigationBars).windowInsetsEndWidth(WindowInsets.systemBars)",
- "androidx.compose.foundation.layout.WindowInsets",
- "androidx.compose.foundation.layout.navigationBars",
- "androidx.compose.foundation.layout.windowInsetsEndWidth",
- "androidx.compose.foundation.layout.windowInsetsStartWidth"
- )
-)
-fun Modifier.navigationBarsWidth(
- side: HorizontalSide,
- additional: Dp = 0.dp
-): Modifier = composed {
- InsetsSizeModifier(
- insetsType = LocalWindowInsets.current.navigationBars,
- widthSide = side,
- additionalWidth = additional
- )
-}
-
-/**
- * [Modifier] class which powers the modifiers above. This is the lower level modifier which
- * supports the functionality through a number of parameters.
- *
- * We may make this public at some point. If you need this, please let us know via the
- * issue tracker.
- */
-private data class InsetsSizeModifier(
- private val insetsType: WindowInsets.Type,
- private val widthSide: HorizontalSide? = null,
- private val additionalWidth: Dp = 0.dp,
- private val heightSide: VerticalSide? = null,
- private val additionalHeight: Dp = 0.dp
-) : LayoutModifier {
- private val Density.targetConstraints: Constraints
- get() {
- val additionalWidthPx = additionalWidth.roundToPx()
- val additionalHeightPx = additionalHeight.roundToPx()
- return Constraints(
- minWidth = additionalWidthPx + when (widthSide) {
- HorizontalSide.Left -> insetsType.left
- HorizontalSide.Right -> insetsType.right
- null -> 0
- },
- minHeight = additionalHeightPx + when (heightSide) {
- VerticalSide.Top -> insetsType.top
- VerticalSide.Bottom -> insetsType.bottom
- null -> 0
- },
- maxWidth = when (widthSide) {
- HorizontalSide.Left -> insetsType.left + additionalWidthPx
- HorizontalSide.Right -> insetsType.right + additionalWidthPx
- null -> Constraints.Infinity
- },
- maxHeight = when (heightSide) {
- VerticalSide.Top -> insetsType.top + additionalHeightPx
- VerticalSide.Bottom -> insetsType.bottom + additionalHeightPx
- null -> Constraints.Infinity
- }
- )
- }
-
- override fun MeasureScope.measure(
- measurable: Measurable,
- constraints: Constraints
- ): MeasureResult {
- val wrappedConstraints = targetConstraints.let { targetConstraints ->
- val resolvedMinWidth = if (widthSide != null) {
- targetConstraints.minWidth
- } else {
- constraints.minWidth.coerceAtMost(targetConstraints.maxWidth)
- }
- val resolvedMaxWidth = if (widthSide != null) {
- targetConstraints.maxWidth
- } else {
- constraints.maxWidth.coerceAtLeast(targetConstraints.minWidth)
- }
- val resolvedMinHeight = if (heightSide != null) {
- targetConstraints.minHeight
- } else {
- constraints.minHeight.coerceAtMost(targetConstraints.maxHeight)
- }
- val resolvedMaxHeight = if (heightSide != null) {
- targetConstraints.maxHeight
- } else {
- constraints.maxHeight.coerceAtLeast(targetConstraints.minHeight)
- }
- Constraints(
- resolvedMinWidth,
- resolvedMaxWidth,
- resolvedMinHeight,
- resolvedMaxHeight
- )
- }
- val placeable = measurable.measure(wrappedConstraints)
- return layout(placeable.width, placeable.height) {
- placeable.place(0, 0)
- }
- }
-
- override fun IntrinsicMeasureScope.minIntrinsicWidth(
- measurable: IntrinsicMeasurable,
- height: Int
- ) = measurable.minIntrinsicWidth(height).let {
- val constraints = targetConstraints
- it.coerceIn(constraints.minWidth, constraints.maxWidth)
- }
-
- override fun IntrinsicMeasureScope.maxIntrinsicWidth(
- measurable: IntrinsicMeasurable,
- height: Int
- ) = measurable.maxIntrinsicWidth(height).let {
- val constraints = targetConstraints
- it.coerceIn(constraints.minWidth, constraints.maxWidth)
- }
-
- override fun IntrinsicMeasureScope.minIntrinsicHeight(
- measurable: IntrinsicMeasurable,
- width: Int
- ) = measurable.minIntrinsicHeight(width).let {
- val constraints = targetConstraints
- it.coerceIn(constraints.minHeight, constraints.maxHeight)
- }
-
- override fun IntrinsicMeasureScope.maxIntrinsicHeight(
- measurable: IntrinsicMeasurable,
- width: Int
- ) = measurable.maxIntrinsicHeight(width).let {
- val constraints = targetConstraints
- it.coerceIn(constraints.minHeight, constraints.maxHeight)
- }
-}
diff --git a/insets/src/main/java/com/google/accompanist/insets/WindowInsets.kt b/insets/src/main/java/com/google/accompanist/insets/WindowInsets.kt
deleted file mode 100644
index 5a2351163..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/WindowInsets.kt
+++ /dev/null
@@ -1,554 +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.insets
-
-import android.view.View
-import android.view.WindowInsetsAnimation
-import androidx.annotation.FloatRange
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.CompositionLocalProvider
-import androidx.compose.runtime.DisposableEffect
-import androidx.compose.runtime.ProvidableCompositionLocal
-import androidx.compose.runtime.Stable
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.staticCompositionLocalOf
-import androidx.compose.ui.platform.LocalView
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsAnimationCompat
-import androidx.core.view.WindowInsetsCompat
-
-/**
- * The main insets holder, containing instances of [WindowInsets.Type] which each refer to different
- * types of system display insets.
- */
-@Stable
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith(
- "WindowInsets",
- "androidx.compose.foundation.layout.WindowInsets"
- )
-)
-interface WindowInsets {
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.navigationBars]
- */
- val navigationBars: Type
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.statusBars]
- */
- val statusBars: Type
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.ime]
- */
- val ime: Type
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.systemGestures]
- */
- val systemGestures: Type
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.systemBars]
- */
- val systemBars: Type
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.displayCutout]
- */
- val displayCutout: Type
-
- /**
- * Returns a copy of this instance with the given values.
- */
- fun copy(
- navigationBars: Type = this.navigationBars,
- statusBars: Type = this.statusBars,
- systemGestures: Type = this.systemGestures,
- ime: Type = this.ime,
- displayCutout: Type = this.displayCutout,
- ): WindowInsets = ImmutableWindowInsets(
- systemGestures = systemGestures,
- navigationBars = navigationBars,
- statusBars = statusBars,
- ime = ime,
- displayCutout = displayCutout
- )
-
- companion object {
- /**
- * Empty and immutable instance of [WindowInsets].
- */
- val Empty: WindowInsets = ImmutableWindowInsets()
- }
-
- /**
- * Represents the values for a type of insets, and stores information about the layout insets,
- * animating insets, and visibility of the insets.
- *
- * [WindowInsets.Type] instances are commonly stored in a [WindowInsets] instance.
- */
- @Stable
- @Deprecated(
- "accompanist/insets is deprecated",
- replaceWith = ReplaceWith(
- "WindowInsets",
- "androidx.compose.foundation.layout.WindowInsets"
- )
- )
- interface Type : Insets {
- /**
- * The layout insets for this [WindowInsets.Type]. These are the insets which are defined from the
- * current window layout.
- *
- * You should not normally need to use this directly, and instead use [left], [top],
- * [right], and [bottom] to return the correct value for the current state.
- */
- val layoutInsets: Insets
-
- /**
- * The animated insets for this [WindowInsets.Type]. These are the insets which are updated from
- * any on-going animations. If there are no animations in progress, the returned [Insets] will
- * be empty.
- *
- * You should not normally need to use this directly, and instead use [left], [top],
- * [right], and [bottom] to return the correct value for the current state.
- */
- val animatedInsets: Insets
-
- /**
- * Whether the insets are currently visible.
- */
- val isVisible: Boolean
-
- /**
- * Whether this insets type is being animated at this moment.
- */
- val animationInProgress: Boolean
-
- /**
- * The left dimension of the insets in pixels.
- */
- override val left: Int
- get() = (if (animationInProgress) animatedInsets else layoutInsets).left
-
- /**
- * The top dimension of the insets in pixels.
- */
- override val top: Int
- get() = (if (animationInProgress) animatedInsets else layoutInsets).top
-
- /**
- * The right dimension of the insets in pixels.
- */
- override val right: Int
- get() = (if (animationInProgress) animatedInsets else layoutInsets).right
-
- /**
- * The bottom dimension of the insets in pixels.
- */
- override val bottom: Int
- get() = (if (animationInProgress) animatedInsets else layoutInsets).bottom
-
- /**
- * The progress of any ongoing animations, in the range of 0 to 1.
- * If there is no animation in progress, this will return 0.
- */
- @get:FloatRange(from = 0.0, to = 1.0)
- val animationFraction: Float
-
- companion object {
- /**
- * Empty and immutable instance of [WindowInsets.Type].
- */
- val Empty: Type = ImmutableWindowInsetsType()
- }
- }
-}
-
-/**
- * This class sets up the necessary listeners on the given [view] to be able to observe
- * [WindowInsetsCompat] instances dispatched by the system.
- *
- * This class is useful for when you prefer to handle the ownership of the [WindowInsets]
- * yourself. One example of this is if you find yourself using [ProvideWindowInsets] in fragments.
- *
- * It is convenient to use [ProvideWindowInsets] in fragments, but that can result in a
- * delay in the initial inset update, which results in a visual flicker.
- * See [this issue](https://github.com/google/accompanist/issues/155) for more information.
- *
- * The alternative is for fragments to manage the [WindowInsets] themselves, like so:
- *
- * ```
- * override fun onCreateView(
- * inflater: LayoutInflater,
- * container: ViewGroup?,
- * savedInstanceState: Bundle?
- * ): View = ComposeView(requireContext()).apply {
- * layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT)
- *
- * // Create an ViewWindowInsetObserver using this view
- * val observer = ViewWindowInsetObserver(this)
- *
- * // Call start() to start listening now.
- * // The WindowInsets instance is returned to us.
- * val windowInsets = observer.start()
- *
- * setContent {
- * // Instead of calling ProvideWindowInsets, we use CompositionLocalProvider to provide
- * // the WindowInsets instance from above to LocalWindowInsets
- * CompositionLocalProvider(LocalWindowInsets provides windowInsets) {
- * /* Content */
- * }
- * }
- * }
- * ```
- *
- * @param view The view to observe [WindowInsetsCompat]s from.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-ViewWindowInsetObserver is not necessary in androidx.compose and can be removed.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-class ViewWindowInsetObserver(private val view: View) {
- private val attachListener = object : View.OnAttachStateChangeListener {
- override fun onViewAttachedToWindow(v: View) = v.requestApplyInsets()
- override fun onViewDetachedFromWindow(v: View) = Unit
- }
-
- /**
- * Whether this [ViewWindowInsetObserver] is currently observing.
- */
- @Suppress("MemberVisibilityCanBePrivate")
- var isObserving: Boolean = false
- private set
-
- /**
- * Start observing window insets from [view]. Make sure to call [stop] if required.
- *
- * @param windowInsetsAnimationsEnabled Whether to listen for [WindowInsetsAnimation]s, such as
- * IME animations.
- * @param consumeWindowInsets Whether to consume any [WindowInsetsCompat]s which are
- * dispatched to the host view. Defaults to `true`.
- */
- fun start(
- consumeWindowInsets: Boolean = true,
- windowInsetsAnimationsEnabled: Boolean = true,
- ): WindowInsets = RootWindowInsets().also {
- observeInto(
- windowInsets = it,
- consumeWindowInsets = consumeWindowInsets,
- windowInsetsAnimationsEnabled = windowInsetsAnimationsEnabled
- )
- }
-
- internal fun observeInto(
- windowInsets: RootWindowInsets,
- consumeWindowInsets: Boolean,
- windowInsetsAnimationsEnabled: Boolean,
- ) {
- require(!isObserving) {
- "start() called, but this ViewWindowInsetObserver is already observing"
- }
-
- ViewCompat.setOnApplyWindowInsetsListener(view) { _, wic ->
- // Go through each inset type and update its layoutInsets from the
- // WindowInsetsCompat values
- windowInsets.statusBars.run {
- layoutInsets.updateFrom(wic.getInsets(WindowInsetsCompat.Type.statusBars()))
- isVisible = wic.isVisible(WindowInsetsCompat.Type.statusBars())
- }
- windowInsets.navigationBars.run {
- layoutInsets.updateFrom(wic.getInsets(WindowInsetsCompat.Type.navigationBars()))
- isVisible = wic.isVisible(WindowInsetsCompat.Type.navigationBars())
- }
- windowInsets.systemGestures.run {
- layoutInsets.updateFrom(wic.getInsets(WindowInsetsCompat.Type.systemGestures()))
- isVisible = wic.isVisible(WindowInsetsCompat.Type.systemGestures())
- }
- windowInsets.ime.run {
- layoutInsets.updateFrom(wic.getInsets(WindowInsetsCompat.Type.ime()))
- isVisible = wic.isVisible(WindowInsetsCompat.Type.ime())
- }
- windowInsets.displayCutout.run {
- layoutInsets.updateFrom(wic.getInsets(WindowInsetsCompat.Type.displayCutout()))
- isVisible = wic.isVisible(WindowInsetsCompat.Type.displayCutout())
- }
-
- if (consumeWindowInsets) WindowInsetsCompat.CONSUMED else wic
- }
-
- // Add an OnAttachStateChangeListener to request an inset pass each time we're attached
- // to the window
- view.addOnAttachStateChangeListener(attachListener)
-
- if (windowInsetsAnimationsEnabled) {
- ViewCompat.setWindowInsetsAnimationCallback(
- view,
- InnerWindowInsetsAnimationCallback(windowInsets)
- )
- } else {
- ViewCompat.setWindowInsetsAnimationCallback(view, null)
- }
-
- if (view.isAttachedToWindow) {
- // If the view is already attached, we can request an inset pass now
- view.requestApplyInsets()
- }
-
- isObserving = true
- }
-
- /**
- * Removes any listeners from the [view] so that we no longer observe inset changes.
- *
- * This is only required to be called from hosts which have a shorter lifetime than the [view].
- * For example, if you're using [ViewWindowInsetObserver] from a `@Composable` function,
- * you should call [stop] from an `onDispose` block, like so:
- *
- * ```
- * DisposableEffect(view) {
- * val observer = ViewWindowInsetObserver(view)
- * // ...
- * onDispose {
- * observer.stop()
- * }
- * }
- * ```
- *
- * Whereas if you're using this class from a fragment (or similar), it is not required to
- * call this function since it will live as least as longer as the view.
- */
- fun stop() {
- require(isObserving) {
- "stop() called, but this ViewWindowInsetObserver is not currently observing"
- }
- view.removeOnAttachStateChangeListener(attachListener)
- ViewCompat.setOnApplyWindowInsetsListener(view, null)
- isObserving = false
- }
-}
-
-/**
- * Applies any [WindowInsetsCompat] values to [LocalWindowInsets], which are then available
- * within [content].
- *
- * If you're using this in fragments, you may wish to take a look at
- * [ViewWindowInsetObserver] for a more optimal solution.
- *
- * @param windowInsetsAnimationsEnabled Whether to listen for [WindowInsetsAnimation]s, such as
- * IME animations.
- * @param consumeWindowInsets Whether to consume any [WindowInsetsCompat]s which are dispatched to
- * the host view. Defaults to `true`.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-""",
- replaceWith = ReplaceWith("content")
-)
-@Composable
-fun ProvideWindowInsets(
- consumeWindowInsets: Boolean = true,
- windowInsetsAnimationsEnabled: Boolean = true,
- content: @Composable () -> Unit
-) {
- val view = LocalView.current
- val windowInsets = remember { RootWindowInsets() }
-
- DisposableEffect(view) {
- val observer = ViewWindowInsetObserver(view)
- observer.observeInto(
- windowInsets = windowInsets,
- consumeWindowInsets = consumeWindowInsets,
- windowInsetsAnimationsEnabled = windowInsetsAnimationsEnabled
- )
- onDispose { observer.stop() }
- }
-
- CompositionLocalProvider(LocalWindowInsets provides windowInsets) {
- content()
- }
-}
-
-private class InnerWindowInsetsAnimationCallback(
- private val windowInsets: RootWindowInsets,
-) : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_STOP) {
- override fun onPrepare(animation: WindowInsetsAnimationCompat) {
- // Go through each type and flag that an animation has started
- if (animation.typeMask and WindowInsetsCompat.Type.ime() != 0) {
- windowInsets.ime.onAnimationStart()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.statusBars() != 0) {
- windowInsets.statusBars.onAnimationStart()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.navigationBars() != 0) {
- windowInsets.navigationBars.onAnimationStart()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.systemGestures() != 0) {
- windowInsets.systemGestures.onAnimationStart()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.displayCutout() != 0) {
- windowInsets.displayCutout.onAnimationStart()
- }
- }
-
- override fun onProgress(
- platformInsets: WindowInsetsCompat,
- runningAnimations: List
- ): WindowInsetsCompat {
- // Update each inset type with the given parameters
- windowInsets.ime.updateAnimation(
- platformInsets = platformInsets,
- runningAnimations = runningAnimations,
- type = WindowInsetsCompat.Type.ime()
- )
- windowInsets.statusBars.updateAnimation(
- platformInsets = platformInsets,
- runningAnimations = runningAnimations,
- type = WindowInsetsCompat.Type.statusBars()
- )
- windowInsets.navigationBars.updateAnimation(
- platformInsets = platformInsets,
- runningAnimations = runningAnimations,
- type = WindowInsetsCompat.Type.navigationBars()
- )
- windowInsets.systemGestures.updateAnimation(
- platformInsets = platformInsets,
- runningAnimations = runningAnimations,
- type = WindowInsetsCompat.Type.systemGestures()
- )
- windowInsets.displayCutout.updateAnimation(
- platformInsets = platformInsets,
- runningAnimations = runningAnimations,
- type = WindowInsetsCompat.Type.displayCutout()
- )
- return platformInsets
- }
-
- private fun MutableWindowInsetsType.updateAnimation(
- platformInsets: WindowInsetsCompat,
- runningAnimations: List,
- type: Int,
- ) {
- // If there are animations of the given type...
- if (runningAnimations.any { it.typeMask or type != 0 }) {
- // Update our animated inset values
- animatedInsets.updateFrom(platformInsets.getInsets(type))
- // And update the animation fraction. We use the maximum animation progress of any
- // ongoing animations for this type.
- animationFraction = runningAnimations.maxOf { it.fraction }
- }
- }
-
- override fun onEnd(animation: WindowInsetsAnimationCompat) {
- // Go through each type and flag that an animation has ended
- if (animation.typeMask and WindowInsetsCompat.Type.ime() != 0) {
- windowInsets.ime.onAnimationEnd()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.statusBars() != 0) {
- windowInsets.statusBars.onAnimationEnd()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.navigationBars() != 0) {
- windowInsets.navigationBars.onAnimationEnd()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.systemGestures() != 0) {
- windowInsets.systemGestures.onAnimationEnd()
- }
- if (animation.typeMask and WindowInsetsCompat.Type.displayCutout() != 0) {
- windowInsets.displayCutout.onAnimationEnd()
- }
- }
-}
-
-/**
- * Holder of our root inset values.
- */
-internal class RootWindowInsets : WindowInsets {
- /**
- * Inset values which match [WindowInsetsCompat.Type.systemGestures]
- */
- override val systemGestures: MutableWindowInsetsType = MutableWindowInsetsType()
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.navigationBars]
- */
- override val navigationBars: MutableWindowInsetsType = MutableWindowInsetsType()
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.statusBars]
- */
- override val statusBars: MutableWindowInsetsType = MutableWindowInsetsType()
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.ime]
- */
- override val ime: MutableWindowInsetsType = MutableWindowInsetsType()
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.displayCutout]
- */
- override val displayCutout: MutableWindowInsetsType = MutableWindowInsetsType()
-
- /**
- * Inset values which match [WindowInsetsCompat.Type.systemBars]
- */
- override val systemBars: WindowInsets.Type = derivedWindowInsetsTypeOf(statusBars, navigationBars)
-}
-
-/**
- * Shallow-immutable implementation of [WindowInsets].
- */
-internal class ImmutableWindowInsets(
- override val systemGestures: WindowInsets.Type = WindowInsets.Type.Empty,
- override val navigationBars: WindowInsets.Type = WindowInsets.Type.Empty,
- override val statusBars: WindowInsets.Type = WindowInsets.Type.Empty,
- override val ime: WindowInsets.Type = WindowInsets.Type.Empty,
- override val displayCutout: WindowInsets.Type = WindowInsets.Type.Empty,
-) : WindowInsets {
- override val systemBars: WindowInsets.Type = derivedWindowInsetsTypeOf(statusBars, navigationBars)
-}
-
-@RequiresOptIn(message = "Animated Insets support is experimental. The API may be changed in the future.")
-@Retention(AnnotationRetention.BINARY)
-@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
-annotation class ExperimentalAnimatedInsets
-
-/**
- * Composition local containing the current [WindowInsets].
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-The androidx.compose equivalent of LocalWindowInsets is the extensions on WindowInsets.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-val LocalWindowInsets: ProvidableCompositionLocal =
- staticCompositionLocalOf { WindowInsets.Empty }
diff --git a/insets/src/main/java/com/google/accompanist/insets/WindowInsetsType.kt b/insets/src/main/java/com/google/accompanist/insets/WindowInsetsType.kt
deleted file mode 100644
index c55d259e5..000000000
--- a/insets/src/main/java/com/google/accompanist/insets/WindowInsetsType.kt
+++ /dev/null
@@ -1,146 +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.insets
-
-import androidx.annotation.FloatRange
-import androidx.compose.runtime.derivedStateOf
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.setValue
-
-/**
- * Mutable [androidx.compose.runtime.State] backed implementation of [WindowInsets.Type].
- */
-internal class MutableWindowInsetsType : WindowInsets.Type {
- private var ongoingAnimationsCount by mutableStateOf(0)
-
- /**
- * The layout inset values for this [WindowInsets.Type]. These are the insets which are defined from
- * the current window layout.
- *
- * You should not normally need to use this directly, and instead use [left], [top],
- * [right], and [bottom] to return the correct value for the current state.
- */
- override val layoutInsets: MutableInsets = MutableInsets()
-
- /**
- * The animated inset values for this [WindowInsets.Type]. These are the insets which are updated from
- * any on-going animations. If there are no animations in progress, the returned
- * [Insets] will be empty.
- *
- * You should not normally need to use this directly, and instead use [left], [top],
- * [right], and [bottom] to return the correct value for the current state.
- */
- override val animatedInsets: MutableInsets = MutableInsets()
-
- /**
- * Whether the insets are currently visible.
- */
- override var isVisible by mutableStateOf(true)
-
- /**
- * Whether this insets type is being animated at this moment.
- */
- override val animationInProgress: Boolean by derivedStateOf {
- ongoingAnimationsCount > 0
- }
-
- /**
- * The progress of any ongoing animations, in the range of 0 to 1.
- * If there is no animation in progress, this will return 0.
- */
- @get:FloatRange(from = 0.0, to = 1.0)
- override var animationFraction by mutableStateOf(0f)
-
- fun onAnimationStart() {
- ongoingAnimationsCount++
- }
-
- fun onAnimationEnd() {
- ongoingAnimationsCount--
-
- if (ongoingAnimationsCount == 0) {
- // If there are no on-going animations, clear out the animated insets
- animatedInsets.reset()
- animationFraction = 0f
- }
- }
-}
-
-/**
- * Shallow-immutable implementation of [WindowInsets.Type].
- */
-internal class ImmutableWindowInsetsType(
- override val layoutInsets: Insets = Insets.Empty,
- override val animatedInsets: Insets = Insets.Empty,
- override val isVisible: Boolean = false,
- override val animationInProgress: Boolean = false,
- override val animationFraction: Float = 0f,
-) : WindowInsets.Type
-
-/**
- * Returns an instance of [WindowInsets.Type] whose values are calculated and derived from the
- * [WindowInsets.Type] instances passed in to [types].
- *
- * Each [WindowInsets.Type] passed in will be coerced with each other, such that the maximum value for
- * each dimension is calculated and used. This is typically used for two purposes:
- *
- * 1) Creating semantic types. [WindowInsets.systemBars] is a good example, as it is the derived
- * insets of [WindowInsets.statusBars] and [WindowInsets.navigationBars].
- * 2) Combining insets for specific usages. [navigationBarsWithImePadding] is a good example, as it
- * is the derived insets of the [WindowInsets.ime] insets, coerced by the
- * [WindowInsets.navigationBars] insets.
- */
-@Deprecated(
-"""
-accompanist/insets is deprecated.
-The androidx.compose equivalent is WindowInsets.union.
-For more migration information, please visit https://google.github.io/accompanist/insets/#migration
-"""
-)
-fun derivedWindowInsetsTypeOf(vararg types: WindowInsets.Type): WindowInsets.Type = CalculatedWindowInsetsType(*types)
-
-/**
- * Implementation of [WindowInsets.Type] which is the backing implementation for [derivedWindowInsetsTypeOf].
- */
-private class CalculatedWindowInsetsType(vararg types: WindowInsets.Type) : WindowInsets.Type {
- override val layoutInsets: Insets by derivedStateOf {
- types.fold(Insets.Empty) { acc, insetsType ->
- acc.coerceEachDimensionAtLeast(insetsType)
- }
- }
-
- override val animatedInsets: Insets by derivedStateOf {
- types.fold(Insets.Empty) { acc, insetsType ->
- acc.coerceEachDimensionAtLeast(insetsType)
- }
- }
-
- override val isVisible: Boolean by derivedStateOf {
- types.all { it.isVisible }
- }
-
- override val animationInProgress: Boolean by derivedStateOf {
- types.any { it.animationInProgress }
- }
-
- override val animationFraction: Float by derivedStateOf {
- types.maxOf { it.animationFraction }
- }
-}
diff --git a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/BaseInsetsTest.kt b/insets/src/sharedTest/kotlin/com/google/accompanist/insets/BaseInsetsTest.kt
deleted file mode 100644
index 86e26c72f..000000000
--- a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/BaseInsetsTest.kt
+++ /dev/null
@@ -1,163 +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.insets
-
-import androidx.compose.foundation.layout.PaddingValues
-import androidx.compose.foundation.layout.calculateEndPadding
-import androidx.compose.foundation.layout.calculateStartPadding
-import androidx.compose.runtime.CompositionLocalProvider
-import androidx.compose.ui.platform.LocalDensity
-import androidx.compose.ui.platform.LocalLayoutDirection
-import androidx.compose.ui.test.junit4.createComposeRule
-import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.LayoutDirection
-import androidx.compose.ui.unit.dp
-import com.google.accompanist.internal.test.combineWithParameters
-import com.google.accompanist.internal.test.parameterizedParams
-import com.google.common.truth.Truth.assertThat
-import org.junit.Rule
-import org.junit.Test
-
-/**
- * Contains the base insets tests. This class is extended in both the `androidTest` and
- * `test` source sets for setup of the relevant test runner.
- */
-abstract class BaseInsetsTest(
- private val type: TestInsetType,
- private val applyStart: Boolean,
- private val applyTop: Boolean,
- private val applyEnd: Boolean,
- private val applyBottom: Boolean,
- private val layoutDirection: LayoutDirection,
-) {
- @get:Rule
- val composeTestRule = createComposeRule()
-
- @Test
- fun paddingValues() {
- // Calculate left/right values which are used later
- val applyLeft = applyStart && layoutDirection == LayoutDirection.Ltr ||
- applyEnd && layoutDirection == LayoutDirection.Rtl
- val applyRight = applyStart && layoutDirection == LayoutDirection.Rtl ||
- applyEnd && layoutDirection == LayoutDirection.Ltr
-
- val windowInsets = RootWindowInsets()
- lateinit var paddingValues: PaddingValues
- var expectedPxInDp: Dp = 0.dp
-
- composeTestRule.setContent {
- CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
- expectedPxInDp = with(LocalDensity.current) { ExpectedPx.toDp() }
-
- paddingValues = rememberInsetsPaddingValues(
- insets = windowInsets.getTestTypeToRead(type),
- applyStart = applyStart,
- applyTop = applyTop,
- applyEnd = applyEnd,
- applyBottom = applyBottom,
- )
- }
- }
-
- composeTestRule.waitForIdle()
-
- // Assert that the expectedPxInDp value was resolved
- assertThat(expectedPxInDp.value).isAtLeast(1f)
-
- // Assert that everything is 0.dp to start
- assertThat(paddingValues.calculateStartPadding(layoutDirection)).isEqualTo(0.dp)
- assertThat(paddingValues.calculateTopPadding()).isEqualTo(0.dp)
- assertThat(paddingValues.calculateEndPadding(layoutDirection)).isEqualTo(0.dp)
- assertThat(paddingValues.calculateBottomPadding()).isEqualTo(0.dp)
-
- // Now update the WindowInsets as appropriately for the test
- windowInsets.getTestTypeToUpdate(type).layoutInsets.apply {
- left = if (applyLeft) ExpectedPx else 0
- top = if (applyTop) ExpectedPx else 0
- right = if (applyRight) ExpectedPx else 0
- bottom = if (applyBottom) ExpectedPx else 0
- }
-
- // Wait for composition to happen
- composeTestRule.waitForIdle()
-
- // And assert that the PaddingValues return the correct values
- assertThat(paddingValues.calculateStartPadding(layoutDirection))
- .isEqualTo(if (applyStart) expectedPxInDp else 0.dp)
- assertThat(paddingValues.calculateTopPadding())
- .isEqualTo(if (applyTop) expectedPxInDp else 0.dp)
- assertThat(paddingValues.calculateEndPadding(layoutDirection))
- .isEqualTo(if (applyEnd) expectedPxInDp else 0.dp)
- assertThat(paddingValues.calculateBottomPadding())
- .isEqualTo(if (applyBottom) expectedPxInDp else 0.dp)
- }
-
- internal companion object {
- private const val ExpectedPx: Int = 32
-
- @JvmStatic
- protected fun params(): Collection> {
- return parameterizedParams()
- .combineWithParameters(*TestInsetType.values()) // type
- .combineWithParameters(true, false) // applyStart
- .combineWithParameters(true, false) // applyTop
- .combineWithParameters(true, false) // applyEnd
- .combineWithParameters(true, false) // applyBottom
- .combineWithParameters(*LayoutDirection.values()) // layoutDirection
- }
- }
-}
-
-enum class TestInsetType {
- StatusBars,
- NavigationBars,
- SystemGesture,
- Ime,
- SystemBars,
-}
-
-/**
- * Return the [WindowInsets.Type] to assert values for, for the given [type].
- */
-private fun WindowInsets.getTestTypeToRead(
- type: TestInsetType,
-): WindowInsets.Type = when (type) {
- TestInsetType.StatusBars -> statusBars
- TestInsetType.NavigationBars -> navigationBars
- TestInsetType.SystemGesture -> systemGestures
- TestInsetType.Ime -> ime
- TestInsetType.SystemBars -> systemBars
-}
-
-/**
- * Return the [MutableWindowInsetsType] to update and instrument for the given [type].
- *
- * This may not be the same return values as [getTestTypeToRead] since some types are computed.
- */
-private fun WindowInsets.getTestTypeToUpdate(type: TestInsetType): MutableWindowInsetsType {
- return when (type) {
- TestInsetType.StatusBars -> statusBars
- TestInsetType.NavigationBars -> navigationBars
- TestInsetType.SystemGesture -> systemGestures
- TestInsetType.Ime -> ime
- // For SystemBars we return statusBars as SystemBars is a computed
- // result of statusBars + navigationBars
- TestInsetType.SystemBars -> statusBars
- } as MutableWindowInsetsType
-}
diff --git a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/FakeTests.kt b/insets/src/sharedTest/kotlin/com/google/accompanist/insets/FakeTests.kt
deleted file mode 100644
index fd2f99561..000000000
--- a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/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.insets
-
-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/insets/src/sharedTest/kotlin/com/google/accompanist/insets/InsetsAssertions.kt b/insets/src/sharedTest/kotlin/com/google/accompanist/insets/InsetsAssertions.kt
deleted file mode 100644
index 4794f0615..000000000
--- a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/InsetsAssertions.kt
+++ /dev/null
@@ -1,51 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.insets
-
-import android.graphics.Rect
-import androidx.core.view.WindowInsetsCompat
-import com.google.common.truth.Truth.assertThat
-
-internal fun WindowInsets.assertEqualTo(insets: WindowInsetsCompat) {
- statusBars.assertEqualTo(insets.getInsets(WindowInsetsCompat.Type.statusBars()))
- assertThat(statusBars.isVisible)
- .isEqualTo(insets.isVisible(WindowInsetsCompat.Type.statusBars()))
-
- navigationBars.assertEqualTo(insets.getInsets(WindowInsetsCompat.Type.navigationBars()))
- assertThat(navigationBars.isVisible)
- .isEqualTo(insets.isVisible(WindowInsetsCompat.Type.navigationBars()))
-
- ime.assertEqualTo(insets.getInsets(WindowInsetsCompat.Type.ime()))
- assertThat(ime.isVisible)
- .isEqualTo(insets.isVisible(WindowInsetsCompat.Type.ime()))
-
- systemBars.assertEqualTo(insets.getInsets(WindowInsetsCompat.Type.systemBars()))
-
- // It's difficult to create an expected value for isVisible as it depends on the system ui
- // of the device.
-
- displayCutout.assertEqualTo(insets.getInsets(WindowInsetsCompat.Type.displayCutout()))
-}
-
-internal fun WindowInsets.Type.assertEqualTo(insets: androidx.core.graphics.Insets) {
- // This might look a bit weird, why are we using a Rect? Well, it makes the assertion
- // error message much easier to read, by containing all of the dimensions.
- assertThat(Rect(left, top, right, bottom))
- .isEqualTo(Rect(insets.left, insets.top, insets.right, insets.bottom))
-}
diff --git a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/InsetsTestActivity.kt b/insets/src/sharedTest/kotlin/com/google/accompanist/insets/InsetsTestActivity.kt
deleted file mode 100644
index 759f9114c..000000000
--- a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/InsetsTestActivity.kt
+++ /dev/null
@@ -1,31 +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.insets
-
-import android.os.Bundle
-import androidx.activity.ComponentActivity
-import androidx.core.view.WindowCompat
-
-/**
- * [ComponentActivity] which automatically requests for the decor not to fit system windows.
- */
-class InsetsTestActivity : ComponentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- WindowCompat.setDecorFitsSystemWindows(window, false)
- }
-}
diff --git a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/WindowInsetsTest.kt b/insets/src/sharedTest/kotlin/com/google/accompanist/insets/WindowInsetsTest.kt
deleted file mode 100644
index 875fa838c..000000000
--- a/insets/src/sharedTest/kotlin/com/google/accompanist/insets/WindowInsetsTest.kt
+++ /dev/null
@@ -1,61 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.insets
-
-import androidx.compose.ui.test.junit4.createAndroidComposeRule
-import androidx.core.view.ViewCompat
-import androidx.core.view.WindowInsetsCompat
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.SdkSuppress
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-
-@RunWith(AndroidJUnit4::class)
-class WindowInsetsTest {
- @get:Rule
- val composeTestRule = createAndroidComposeRule()
-
- /**
- * Needed due to https://issuetracker.google.com/174839536.
- * Otherwise this module has no tests when running on API < 23.
- */
- @Test
- fun fakeTest() = Unit
-
- @Test
- @SdkSuppress(minSdkVersion = 23) // ViewCompat.getRootWindowInsets
- fun assertValuesMatchViewInsets() {
- lateinit var composeWindowInsets: WindowInsets
- composeTestRule.setContent {
- ProvideWindowInsets {
- composeWindowInsets = LocalWindowInsets.current
- }
- }
-
- lateinit var rootWindowInsets: WindowInsetsCompat
- composeTestRule.activityRule.scenario.onActivity {
- rootWindowInsets = ViewCompat.getRootWindowInsets(it.window.decorView)!!
- }
-
- composeTestRule.runOnIdle {
- composeWindowInsets.assertEqualTo(rootWindowInsets)
- }
- }
-}
diff --git a/insets/src/test/AndroidManifest.xml b/insets/src/test/AndroidManifest.xml
deleted file mode 100644
index 22a862eb3..000000000
--- a/insets/src/test/AndroidManifest.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/insets/src/test/kotlin/com/google/accompanist/insets/RobolectricInsetsTest.kt b/insets/src/test/kotlin/com/google/accompanist/insets/RobolectricInsetsTest.kt
deleted file mode 100644
index a6fe19487..000000000
--- a/insets/src/test/kotlin/com/google/accompanist/insets/RobolectricInsetsTest.kt
+++ /dev/null
@@ -1,40 +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.insets
-
-import androidx.compose.ui.unit.LayoutDirection
-import org.junit.runner.RunWith
-import org.robolectric.ParameterizedRobolectricTestRunner
-
-/**
- * Version of [BaseInsetsTest] which is designed to be ran on Robolectric.
- */
-@RunWith(ParameterizedRobolectricTestRunner::class)
-class RobolectricInsetsTest(
- type: TestInsetType,
- applyStart: Boolean,
- applyTop: Boolean,
- applyEnd: Boolean,
- applyBottom: Boolean,
- layoutDirection: LayoutDirection,
-) : BaseInsetsTest(type, applyStart, applyTop, applyEnd, applyBottom, layoutDirection) {
- companion object {
- @JvmStatic
- @ParameterizedRobolectricTestRunner.Parameters
- fun data(): Collection> = params()
- }
-}
diff --git a/insets/src/test/resources/robolectric.properties b/insets/src/test/resources/robolectric.properties
deleted file mode 100644
index 2806eaffa..000000000
--- a/insets/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 103c6e886..b66c8408c 100644
--- a/sample/build.gradle.kts
+++ b/sample/build.gradle.kts
@@ -59,7 +59,6 @@ android {
dependencies {
implementation(project(":adaptive"))
implementation(project(":drawablepainter"))
- implementation(project(":insets"))
implementation(project(":insets-ui"))
implementation(project(":navigation-animation"))
implementation(project(":navigation-material"))
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index b24221b2d..413eb38d5 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -50,58 +50,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Box {
- // We apply the contentPadding passed to us from the Scaffold
- LazyColumn(
- contentPadding = contentPadding,
- modifier = Modifier.fillMaxSize(),
- ) {
- items(items = listItems) { imageUrl ->
- ListItem(imageUrl, Modifier.fillMaxWidth())
- }
- }
- }
- }
-}
-
-private val listItems = List(40) { randomSampleImageUrl(it) }
diff --git a/sample/src/main/java/com/google/accompanist/sample/insets/EdgeToEdgeLazyColumnWithBottomNav.kt b/sample/src/main/java/com/google/accompanist/sample/insets/EdgeToEdgeLazyColumnWithBottomNav.kt
deleted file mode 100644
index db2c5f169..000000000
--- a/sample/src/main/java/com/google/accompanist/sample/insets/EdgeToEdgeLazyColumnWithBottomNav.kt
+++ /dev/null
@@ -1,158 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.sample.insets
-
-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.layout.fillMaxWidth
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.material.BottomNavigationItem
-import androidx.compose.material.FabPosition
-import androidx.compose.material.FloatingActionButton
-import androidx.compose.material.Icon
-import androidx.compose.material.MaterialTheme
-import androidx.compose.material.Text
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Alarm
-import androidx.compose.material.icons.filled.CardTravel
-import androidx.compose.material.icons.filled.Face
-import androidx.compose.material.icons.filled.Fastfood
-import androidx.compose.material.icons.filled.HolidayVillage
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.SideEffect
-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.graphics.Color
-import androidx.compose.ui.res.stringResource
-import androidx.core.view.WindowCompat
-import com.google.accompanist.insets.LocalWindowInsets
-import com.google.accompanist.insets.ProvideWindowInsets
-import com.google.accompanist.insets.rememberInsetsPaddingValues
-import com.google.accompanist.insets.ui.BottomNavigation
-import com.google.accompanist.insets.ui.Scaffold
-import com.google.accompanist.insets.ui.TopAppBar
-import com.google.accompanist.sample.AccompanistSampleTheme
-import com.google.accompanist.sample.R
-import com.google.accompanist.sample.randomSampleImageUrl
-import com.google.accompanist.systemuicontroller.rememberSystemUiController
-
-class EdgeToEdgeLazyColumnWithBottomNav : ComponentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- // Turn off the decor fitting system windows, which means we need to through handling
- // insets
- WindowCompat.setDecorFitsSystemWindows(window, false)
-
- setContent {
- // Update the system bars to be translucent
- val systemUiController = rememberSystemUiController()
- val useDarkIcons = MaterialTheme.colors.isLight
- SideEffect {
- systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = useDarkIcons)
- }
-
- AccompanistSampleTheme {
- ProvideWindowInsets {
- Sample()
- }
- }
- }
- }
-}
-
-@Composable
-private fun Sample() {
- Scaffold(
- topBar = {
- // We use TopAppBar from accompanist-insets-ui which allows us to provide
- // content padding matching the system bars insets.
- TopAppBar(
- title = { Text(stringResource(R.string.insets_title_list_bottomnav)) },
- backgroundColor = MaterialTheme.colors.surface.copy(alpha = 0.95f),
- contentPadding = rememberInsetsPaddingValues(
- LocalWindowInsets.current.statusBars,
- applyBottom = false,
- ),
- )
- },
- bottomBar = {
- var selected by remember { mutableStateOf(0) }
-
- BottomNavigation(
- backgroundColor = MaterialTheme.colors.surface.copy(alpha = 0.95f),
- contentPadding = rememberInsetsPaddingValues(
- LocalWindowInsets.current.navigationBars
- )
- ) {
- BottomNavigationItem(
- selected = selected == 0,
- onClick = { selected = 0 },
- icon = { Icon(Icons.Default.Fastfood, contentDescription = null) }
- )
- BottomNavigationItem(
- selected = selected == 1,
- onClick = { selected = 1 },
- icon = { Icon(Icons.Default.CardTravel, contentDescription = null) }
- )
- BottomNavigationItem(
- selected = selected == 2,
- onClick = { selected = 2 },
- icon = { Icon(Icons.Default.HolidayVillage, contentDescription = null) }
- )
- BottomNavigationItem(
- selected = selected == 3,
- onClick = { selected = 3 },
- icon = { Icon(Icons.Default.Alarm, contentDescription = null) }
- )
- }
- },
- floatingActionButton = {
- FloatingActionButton(onClick = { /* TODO */ }) {
- Icon(
- imageVector = Icons.Default.Face,
- contentDescription = "Face icon"
- )
- }
- },
- floatingActionButtonPosition = FabPosition.Center,
- isFloatingActionButtonDocked = true,
- ) { contentPadding ->
- Box {
- // We apply the contentPadding passed to us from the Scaffold
- LazyColumn(
- contentPadding = contentPadding,
- modifier = Modifier.fillMaxSize(),
- ) {
- items(items = listItems) { imageUrl ->
- ListItem(imageUrl, Modifier.fillMaxWidth())
- }
- }
- }
- }
-}
-
-private val listItems = List(40) { randomSampleImageUrl(it) }
diff --git a/sample/src/main/java/com/google/accompanist/sample/insets/ImeAnimationSample.kt b/sample/src/main/java/com/google/accompanist/sample/insets/ImeAnimationSample.kt
deleted file mode 100644
index 85ceeea6a..000000000
--- a/sample/src/main/java/com/google/accompanist/sample/insets/ImeAnimationSample.kt
+++ /dev/null
@@ -1,133 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.sample.insets
-
-import android.os.Bundle
-import androidx.activity.ComponentActivity
-import androidx.activity.compose.setContent
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.lazy.items
-import androidx.compose.material.MaterialTheme
-import androidx.compose.material.OutlinedTextField
-import androidx.compose.material.Surface
-import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.SideEffect
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.input.nestedscroll.nestedScroll
-import androidx.compose.ui.res.stringResource
-import androidx.compose.ui.text.input.TextFieldValue
-import androidx.compose.ui.unit.dp
-import androidx.core.view.WindowCompat
-import com.google.accompanist.insets.ExperimentalAnimatedInsets
-import com.google.accompanist.insets.LocalWindowInsets
-import com.google.accompanist.insets.ProvideWindowInsets
-import com.google.accompanist.insets.navigationBarsWithImePadding
-import com.google.accompanist.insets.rememberImeNestedScrollConnection
-import com.google.accompanist.insets.rememberInsetsPaddingValues
-import com.google.accompanist.insets.ui.Scaffold
-import com.google.accompanist.insets.ui.TopAppBar
-import com.google.accompanist.sample.AccompanistSampleTheme
-import com.google.accompanist.sample.R
-import com.google.accompanist.sample.randomSampleImageUrl
-import com.google.accompanist.systemuicontroller.rememberSystemUiController
-
-class ImeAnimationSample : ComponentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- // Turn off the decor fitting system windows, which means we need to through handling
- // insets
- WindowCompat.setDecorFitsSystemWindows(window, false)
-
- setContent {
- // Update the system bars to be translucent
- val systemUiController = rememberSystemUiController()
- val useDarkIcons = MaterialTheme.colors.isLight
- SideEffect {
- systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = useDarkIcons)
- }
-
- AccompanistSampleTheme {
- ProvideWindowInsets(windowInsetsAnimationsEnabled = true) {
- Sample()
- }
- }
- }
- }
-}
-
-private val listItems = List(40) { randomSampleImageUrl(it) }
-
-@OptIn(ExperimentalAnimatedInsets::class)
-@Composable
-private fun Sample() {
- Scaffold(
- topBar = {
- // We use TopAppBar from accompanist-insets-ui which allows us to provide
- // content padding matching the system bars insets.
- TopAppBar(
- title = { Text(stringResource(R.string.insets_title_imeanim)) },
- backgroundColor = MaterialTheme.colors.surface,
- contentPadding = rememberInsetsPaddingValues(
- LocalWindowInsets.current.statusBars,
- applyBottom = false,
- ),
- modifier = Modifier.fillMaxWidth(),
- )
- },
- bottomBar = {
- Surface(elevation = 1.dp) {
- val text = remember { mutableStateOf(TextFieldValue()) }
- OutlinedTextField(
- value = text.value,
- onValueChange = { text.value = it },
- placeholder = { Text(text = "Watch me animate...") },
- modifier = Modifier
- .fillMaxWidth()
- .padding(horizontal = 16.dp, vertical = 8.dp)
- .navigationBarsWithImePadding()
- )
- }
- },
- modifier = Modifier.fillMaxSize()
- ) { contentPadding ->
- Column {
- // We apply the contentPadding passed to us from the Scaffold
- LazyColumn(
- contentPadding = contentPadding,
- reverseLayout = true,
- modifier = Modifier
- .weight(1f)
- .nestedScroll(connection = rememberImeNestedScrollConnection())
- ) {
- items(listItems) { imageUrl ->
- ListItem(imageUrl, Modifier.fillMaxWidth())
- }
- }
- }
- }
-}
diff --git a/sample/src/main/java/com/google/accompanist/sample/insets/InsetsBasicSample.kt b/sample/src/main/java/com/google/accompanist/sample/insets/InsetsBasicSample.kt
deleted file mode 100644
index f59518258..000000000
--- a/sample/src/main/java/com/google/accompanist/sample/insets/InsetsBasicSample.kt
+++ /dev/null
@@ -1,114 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.sample.insets
-
-import android.os.Bundle
-import androidx.activity.ComponentActivity
-import androidx.activity.compose.setContent
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.padding
-import androidx.compose.material.FloatingActionButton
-import androidx.compose.material.Icon
-import androidx.compose.material.MaterialTheme
-import androidx.compose.material.Text
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Face
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.SideEffect
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.res.stringResource
-import androidx.core.view.WindowCompat
-import com.google.accompanist.insets.LocalWindowInsets
-import com.google.accompanist.insets.ProvideWindowInsets
-import com.google.accompanist.insets.navigationBarsHeight
-import com.google.accompanist.insets.rememberInsetsPaddingValues
-import com.google.accompanist.insets.ui.Scaffold
-import com.google.accompanist.insets.ui.TopAppBar
-import com.google.accompanist.sample.AccompanistSampleTheme
-import com.google.accompanist.sample.R
-import com.google.accompanist.systemuicontroller.rememberSystemUiController
-
-class InsetsBasicSample : ComponentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- // Turn off the decor fitting system windows, which means we need to through handling
- // insets
- WindowCompat.setDecorFitsSystemWindows(window, false)
-
- setContent {
- // Update the system bars to be translucent
- val systemUiController = rememberSystemUiController()
- val useDarkIcons = MaterialTheme.colors.isLight
- SideEffect {
- systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = useDarkIcons)
- }
-
- AccompanistSampleTheme {
- // We need to use ProvideWindowInsets to setup the necessary listeners which
- // power the library
- ProvideWindowInsets {
- InsetsBasics()
- }
- }
- }
- }
-}
-
-@Composable
-internal fun InsetsBasics() {
- Scaffold(
- topBar = {
- // We use TopAppBar from accompanist-insets-ui which allows us to provide
- // content padding matching the system bars insets.
- TopAppBar(
- title = { Text(stringResource(R.string.insets_title_list)) },
- backgroundColor = MaterialTheme.colors.surface.copy(alpha = 0.9f),
- contentPadding = rememberInsetsPaddingValues(
- LocalWindowInsets.current.statusBars,
- applyBottom = false,
- ),
- modifier = Modifier.fillMaxWidth()
- )
- },
- bottomBar = {
- // We add a spacer as a bottom bar, which is the same height as
- // the navigation bar
- Spacer(Modifier.navigationBarsHeight().fillMaxWidth())
- },
- floatingActionButton = {
- FloatingActionButton(
- onClick = { /* TODO */ },
- ) {
- Icon(
- imageVector = Icons.Default.Face,
- contentDescription = "Face icon"
- )
- }
- }
- ) { contentPadding ->
- // We apply the contentPadding passed to us from the Scaffold
- Box(Modifier.padding(contentPadding)) {
- // content
- }
- }
-}
diff --git a/sample/src/main/java/com/google/accompanist/sample/insets/InsetsFragmentSample.kt b/sample/src/main/java/com/google/accompanist/sample/insets/InsetsFragmentSample.kt
deleted file mode 100644
index 9b60d5949..000000000
--- a/sample/src/main/java/com/google/accompanist/sample/insets/InsetsFragmentSample.kt
+++ /dev/null
@@ -1,91 +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.
- */
-
-@file:Suppress("DEPRECATION")
-
-package com.google.accompanist.sample.insets
-
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import android.view.ViewGroup.LayoutParams
-import android.view.ViewGroup.LayoutParams.MATCH_PARENT
-import android.widget.FrameLayout
-import androidx.compose.material.MaterialTheme
-import androidx.compose.runtime.CompositionLocalProvider
-import androidx.compose.runtime.SideEffect
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.platform.ComposeView
-import androidx.core.view.WindowCompat
-import androidx.fragment.app.Fragment
-import androidx.fragment.app.FragmentActivity
-import androidx.fragment.app.commit
-import com.google.accompanist.insets.LocalWindowInsets
-import com.google.accompanist.insets.ViewWindowInsetObserver
-import com.google.accompanist.sample.AccompanistSampleTheme
-import com.google.accompanist.systemuicontroller.rememberSystemUiController
-
-class InsetsFragmentSample : FragmentActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- // Turn off the decor fitting system windows, which means we need to through handling
- // insets
- WindowCompat.setDecorFitsSystemWindows(window, false)
-
- val content = FrameLayout(this)
- content.id = View.generateViewId()
- setContentView(content)
-
- supportFragmentManager.commit {
- replace(content.id, InsetsFragment())
- }
- }
-}
-
-class InsetsFragment : Fragment() {
- override fun onCreateView(
- inflater: LayoutInflater,
- container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View = ComposeView(requireContext()).apply {
- layoutParams = LayoutParams(MATCH_PARENT, MATCH_PARENT)
-
- // Create an ViewWindowInsetObserver using this view
- val observer = ViewWindowInsetObserver(this)
- // Call start() to start listening now.
- // The WindowInsets instance is returned to us.
- val windowInsets = observer.start()
-
- setContent {
- // Update the system bars to be translucent
- val systemUiController = rememberSystemUiController()
- val useDarkIcons = MaterialTheme.colors.isLight
- SideEffect {
- systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = useDarkIcons)
- }
-
- AccompanistSampleTheme {
- // Instead of calling ProvideWindowInsets, we use CompositionLocalProvider to provide
- // the WindowInsets instance from above to LocalWindowInsets
- CompositionLocalProvider(LocalWindowInsets provides windowInsets) {
- InsetsBasics()
- }
- }
- }
- }
-}
diff --git a/sample/src/main/java/com/google/accompanist/sample/insets/ListItems.kt b/sample/src/main/java/com/google/accompanist/sample/insets/ListItems.kt
deleted file mode 100644
index 0027b9400..000000000
--- a/sample/src/main/java/com/google/accompanist/sample/insets/ListItems.kt
+++ /dev/null
@@ -1,63 +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.sample.insets
-
-import androidx.compose.foundation.Image
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.size
-import androidx.compose.foundation.layout.width
-import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.material.MaterialTheme
-import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.draw.clip
-import androidx.compose.ui.unit.dp
-import coil.annotation.ExperimentalCoilApi
-import coil.compose.rememberImagePainter
-
-/**
- * Simple list item row which displays an image and text.
- */
-@OptIn(ExperimentalCoilApi::class)
-@Composable
-fun ListItem(
- imageUrl: String,
- modifier: Modifier = Modifier
-) {
- Row(modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
- Image(
- painter = rememberImagePainter(imageUrl),
- contentDescription = null,
- modifier = Modifier
- .size(64.dp)
- .clip(RoundedCornerShape(4.dp)),
- )
-
- Spacer(Modifier.width(16.dp))
-
- Text(
- text = "Text",
- style = MaterialTheme.typography.subtitle2,
- modifier = Modifier.weight(1f)
- .align(Alignment.CenterVertically)
- )
- }
-}
diff --git a/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshContentPaddingSample.kt b/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshContentPaddingSample.kt
index 2421be3b7..46cef1715 100644
--- a/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshContentPaddingSample.kt
+++ b/sample/src/main/java/com/google/accompanist/sample/swiperefresh/SwipeRefreshContentPaddingSample.kt
@@ -19,15 +19,22 @@ package com.google.accompanist.sample.swiperefresh
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.only
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
+import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
@@ -37,16 +44,20 @@ 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.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
+import coil.annotation.ExperimentalCoilApi
+import coil.compose.rememberImagePainter
import com.google.accompanist.insets.ui.Scaffold
import com.google.accompanist.insets.ui.TopAppBarContent
import com.google.accompanist.insets.ui.TopAppBarSurface
import com.google.accompanist.sample.AccompanistSampleTheme
import com.google.accompanist.sample.R
-import com.google.accompanist.sample.insets.ListItem
import com.google.accompanist.sample.randomSampleImageUrl
import com.google.accompanist.swiperefresh.SwipeRefresh
import com.google.accompanist.swiperefresh.SwipeRefreshIndicator
@@ -137,3 +148,29 @@ private fun Sample() {
}
}
}
+
+@OptIn(ExperimentalCoilApi::class)
+@Composable
+fun ListItem(
+ imageUrl: String,
+ modifier: Modifier = Modifier
+) {
+ Row(modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
+ Image(
+ painter = rememberImagePainter(imageUrl),
+ contentDescription = null,
+ modifier = Modifier
+ .size(64.dp)
+ .clip(RoundedCornerShape(4.dp)),
+ )
+
+ Spacer(Modifier.width(16.dp))
+
+ Text(
+ text = "Text",
+ style = MaterialTheme.typography.subtitle2,
+ modifier = Modifier.weight(1f)
+ .align(Alignment.CenterVertically)
+ )
+ }
+}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 724bdc043..de77a3c45 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -27,7 +27,6 @@ gradleEnterprise {
include(":adaptive")
include(":internal-testutils")
-include(":insets")
include(":insets-ui")
include(":appcompat-theme")
include(":drawablepainter")