Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Insets library #131

Merged
merged 22 commits into from Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions README.md
Expand Up @@ -2,9 +2,17 @@

Accompanist is a group of libraries that contains some utilities which I've found myself copying around projects which use [Jetpack Compose][compose]. Currently, it contains:

- 🖼️ [Coil image loading composables](./coil/README.md)
- 🖼️ [Picasso image loading composables](./picasso/README.md)
- 🖼️ [Glide image loading composables](./glide/README.md)
### Image loading
A number of libraries which aim to integrate some popular image loading libraries into Compose:

- 🖼️ [Coil image loading composables](./coil/)
- 🖼️ [Picasso image loading composables](./picasso/)
- 🖼️ [Glide image loading composables](./glide/)

### 📐 [Insets](./insets/)
TODO

---

[Jetpack Compose][compose] is a fast-moving project and I'll be updating these libraries to match the
latest tagged release as quickly as possible. Each [release listing](https://github.com/chrisbanes/accompanist/releases) will outline what version of Compose libraries it depends on.
Expand Down
Expand Up @@ -85,7 +85,7 @@ object Libs {
const val core = "androidx.core:core:1.2.0"
const val coreKtx = "androidx.core:core-ktx:1.2.0"

const val appcompat = "androidx.appcompat:appcompat:1.3.0-alpha02"
const val coreAlpha = "androidx.core:core:1.5.0-alpha04"
}

object Coil {
Expand Down
11 changes: 6 additions & 5 deletions generate_docs.sh
Expand Up @@ -25,11 +25,12 @@ cp CONTRIBUTING.md $DOCS_ROOT/contributing.md
cp images/social.png $DOCS_ROOT/header.png

sed -i.bak 's/CONTRIBUTING.md/contributing/' $DOCS_ROOT/index.md
sed -i.bak 's/coil\/README.md/glide/' $DOCS_ROOT/index.md
sed -i.bak 's/glide\/README.md/coil/' $DOCS_ROOT/index.md
sed -i.bak 's/picasso\/README.md/picasso/' $DOCS_ROOT/index.md
sed -i.bak 's/README.md//' $DOCS_ROOT/index.md
sed -i.bak 's/images\/social.png/header.png/' $DOCS_ROOT/index.md

# Convert docs/xxx.md links to just xxx/
sed -i.bak 's/docs\/\([a-zA-Z-]*\).md/\1/' $DOCS_ROOT/index.md

cp coil/README.md $DOCS_ROOT/coil.md
mkdir -p $DOCS_ROOT/coil
cp coil/images/crossfade.gif $DOCS_ROOT/coil/crossfade.gif
Expand All @@ -45,8 +46,8 @@ mkdir -p $DOCS_ROOT/glide
cp glide/images/crossfade.gif $DOCS_ROOT/glide/crossfade.gif
sed -i.bak 's/images\/crossfade.gif/crossfade.gif/' $DOCS_ROOT/glide.md

# Convert docs/xxx.md links to just xxx/
sed -i.bak 's/docs\/\([a-zA-Z-]*\).md/\1/' $DOCS_ROOT/index.md
cp insets/README.md $DOCS_ROOT/insets.md
mkdir -p $DOCS_ROOT/insets

#########################
# Tidy up Dokka output
Expand Down
63 changes: 63 additions & 0 deletions insets/README.md
@@ -0,0 +1,63 @@
# Insets for Jetpack Compose

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.chrisbanes.accompanist/accompanist-insets/badge.svg)](https://search.maven.org/search?q=g:dev.chrisbanes.accompanist)

Insets for Jetpack Compose takes a lot of the ideas which drove [Insetter][insetter-view] for views, and applies them for use in composables.

## Usage
To setup Insets in your composables, you need to call the `ProvideWindowInsets` function and
wrap your content. This would typically be done near the top level of your composable hierarchy:

``` kotlin
setContent {
MaterialTheme {
ProvideWindowInsets {
// your content
}
}
}
```

> Note: Whether `ProvideWindowInsets` is called outside or within `MaterialTheme` doesn't particularly matter.

`ProvideWindowInsets` allows the library to set an [`OnApplyWindowInsetsListener`][insetslistener] on your content's host view. That listener is used to update the value of an ambient bundled in this library: `AmbientWindowInsets`.

`AmbientWindowInsets` holds an instance of `WindowInsets` which contains the value of various [WindowInsets][insets] [types][insettypes]. You can use the values manually like so:

``` kotlin
@Composable
fun ImeAvoidingBox() {
val insets = AmbientWindowInsets.current

Box(Modifier.padding(bottom = insets.ime.bottom))
}
```

...but we also provide some easy-to-use [Modifier][modifier]s.

### Modifiers

TODO


## Download

```groovy
repositories {
mavenCentral()
}

dependencies {
implementation "dev.chrisbanes.accompanist:accompanist-insets:<version>"
}
```

Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. These are updated on every commit.

[compose]: https://developer.android.com/jetpack/compose
[snap]: https://oss.sonatype.org/content/repositories/snapshots/dev/chrisbanes/accompanist/accompanist-glide/
chrisbanes marked this conversation as resolved.
Show resolved Hide resolved
[insetter-view]: https://github.com/chrisbanes/insetter
[insets]: https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat
[insettypes]: https://developer.android.com/reference/kotlin/androidx/core/view/WindowInsetsCompat.Type
[insetslistener]: https://developer.android.com/reference/kotlin/androidx/core/view/OnApplyWindowInsetsListener
[modifier]: https://developer.android.com/reference/kotlin/androidx/ui/core/Modifier
49 changes: 49 additions & 0 deletions insets/api/insets.api
@@ -0,0 +1,49 @@
public final class dev/chrisbanes/accompanist/insets/ComposeInsets {
public static final fun ProvideWindowInsets (ZLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
public static final fun getAmbientWindowInsets ()Landroidx/compose/runtime/ProvidableAmbient;
public static final fun navigationBarsHeight-wxomhCo (Landroidx/compose/ui/Modifier;F)Landroidx/compose/ui/Modifier;
public static final fun navigationBarsHeight-wxomhCo$default (Landroidx/compose/ui/Modifier;FILjava/lang/Object;)Landroidx/compose/ui/Modifier;
public static final fun navigationBarsPadding (Landroidx/compose/ui/Modifier;ZZZ)Landroidx/compose/ui/Modifier;
public static final fun navigationBarsPadding$default (Landroidx/compose/ui/Modifier;ZZZILjava/lang/Object;)Landroidx/compose/ui/Modifier;
public static final fun navigationBarsWidth-UTaBBDU (Landroidx/compose/ui/Modifier;Ldev/chrisbanes/accompanist/insets/HorizontalSide;F)Landroidx/compose/ui/Modifier;
public static final fun navigationBarsWidth-UTaBBDU$default (Landroidx/compose/ui/Modifier;Ldev/chrisbanes/accompanist/insets/HorizontalSide;FILjava/lang/Object;)Landroidx/compose/ui/Modifier;
public static final fun statusBarsHeight-wxomhCo (Landroidx/compose/ui/Modifier;F)Landroidx/compose/ui/Modifier;
public static final fun statusBarsHeight-wxomhCo$default (Landroidx/compose/ui/Modifier;FILjava/lang/Object;)Landroidx/compose/ui/Modifier;
public static final fun statusBarsPadding (Landroidx/compose/ui/Modifier;)Landroidx/compose/ui/Modifier;
public static final fun systemBarsPadding (Landroidx/compose/ui/Modifier;Z)Landroidx/compose/ui/Modifier;
public static final fun systemBarsPadding$default (Landroidx/compose/ui/Modifier;ZILjava/lang/Object;)Landroidx/compose/ui/Modifier;
public static final fun toPaddingValues (Ldev/chrisbanes/accompanist/insets/Insets;ZZZZLandroidx/compose/runtime/Composer;II)Landroidx/compose/foundation/layout/PaddingValues;
}

public final class dev/chrisbanes/accompanist/insets/HorizontalSide : java/lang/Enum {
public static final field Left Ldev/chrisbanes/accompanist/insets/HorizontalSide;
public static final field Right Ldev/chrisbanes/accompanist/insets/HorizontalSide;
public static final fun valueOf (Ljava/lang/String;)Ldev/chrisbanes/accompanist/insets/HorizontalSide;
public static final fun values ()[Ldev/chrisbanes/accompanist/insets/HorizontalSide;
}

public final class dev/chrisbanes/accompanist/insets/Insets {
public fun <init> ()V
public final fun getBottom ()I
public final fun getLeft ()I
public final fun getRight ()I
public final fun getTop ()I
public final fun isVisible ()Z
}

public final class dev/chrisbanes/accompanist/insets/VerticalSide : java/lang/Enum {
public static final field Bottom Ldev/chrisbanes/accompanist/insets/VerticalSide;
public static final field Top Ldev/chrisbanes/accompanist/insets/VerticalSide;
public static final fun valueOf (Ljava/lang/String;)Ldev/chrisbanes/accompanist/insets/VerticalSide;
public static final fun values ()[Ldev/chrisbanes/accompanist/insets/VerticalSide;
}

public final class dev/chrisbanes/accompanist/insets/WindowInsets {
public fun <init> ()V
public final fun getIme ()Ldev/chrisbanes/accompanist/insets/Insets;
public final fun getNavigationBars ()Ldev/chrisbanes/accompanist/insets/Insets;
public final fun getStatusBars ()Ldev/chrisbanes/accompanist/insets/Insets;
public final fun getSystemBars ()Ldev/chrisbanes/accompanist/insets/Insets;
public final fun getSystemGestures ()Ldev/chrisbanes/accompanist/insets/Insets;
}

93 changes: 93 additions & 0 deletions insets/build.gradle
@@ -0,0 +1,93 @@
/*
* 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.
*/

import dev.chrisbanes.accompanist.buildsrc.Libs

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'org.jetbrains.dokka'
}

kotlin {
explicitApi()
}

android {
compileSdkVersion 30

defaultConfig {
minSdkVersion 21
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildFeatures {
buildConfig false
compose true
}

composeOptions {
kotlinCompilerVersion Libs.Kotlin.version
kotlinCompilerExtensionVersion Libs.AndroidX.Compose.version
}

lintOptions {
textReport true
textOutput 'stdout'
// We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks
checkReleaseBuilds false
}

testOptions {
unitTests {
includeAndroidResources = true
}
}
}

afterEvaluate {
tasks.withType(org.jetbrains.dokka.gradle.DokkaTask).configureEach {
outputDirectory.set(rootProject.file('docs/api'))
}
}

dependencies {
implementation Libs.AndroidX.coreAlpha
implementation Libs.AndroidX.Compose.runtime
implementation Libs.AndroidX.Compose.foundation

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

// ======================
// Test dependencies
// ======================

androidTestImplementation Libs.junit
androidTestImplementation Libs.truth

androidTestImplementation Libs.AndroidX.Compose.test
androidTestImplementation Libs.AndroidX.Compose.ui
androidTestImplementation Libs.AndroidX.Test.rules
androidTestImplementation Libs.AndroidX.Test.runner
}

apply plugin: "com.vanniktech.maven.publish"
3 changes: 3 additions & 0 deletions insets/gradle.properties
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=accompanist-insets
POM_NAME=Accompanist Insets library
POM_PACKAGING=aar
22 changes: 22 additions & 0 deletions insets/src/androidTest/AndroidManifest.xml
@@ -0,0 +1,22 @@
<!--
~ 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.chrisbanes.accompanist.insets.test">

<uses-sdk android:targetSdkVersion="30" />

</manifest>
@@ -0,0 +1,30 @@
/*
* 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 dev.chrisbanes.accompanist.insets

import androidx.test.filters.LargeTest
import androidx.ui.test.createComposeRule
import org.junit.Rule
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@LargeTest
@RunWith(JUnit4::class)
class InsetsTest {
@get:Rule
val composeTestRule = createComposeRule()
}
18 changes: 18 additions & 0 deletions insets/src/main/AndroidManifest.xml
@@ -0,0 +1,18 @@
<!--
~ 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.
-->

<manifest package="dev.chrisbanes.accompanist.insets">
</manifest>