Insetter is a library to help apps handle WindowInsets more easily. The library contains implementations of many of the concepts described in our "Listeners to Layouts" blog post.
There are a number of libraries available:
The base library which is written in Java, and provides an easy-to-use Builder for OnApplyWindowInsetsListener instances:
Insetter.builder()
// This will apply the system window insets as padding to left, bottom and right of the view,
// maintaining the original padding (from the layout XML, style, etc)
.applySystemWindowInsetsToPadding(Side.LEFT | Side.BOTTOM | Side.RIGHT)
// This is a shortcut for view.setOnApplyWindowInsetsListener(builder.build())
.applyToView(view);
A Kotlin extension library, providing Kotlin-specific functionality. This library contains extension functions allowing easy access to the helper functions from the base library:
bottomNav.applySystemWindowInsetsToPadding(bottom = true)
btnConfirm.applySystemWindowInsetsToMargin(bottom = true, right = true)
A Data Binding extension library, providing Data Binding specific functionality. This primarily contains binding adapters, which allow access to the helper functions from your layouts:
<BottomNavigationView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingVertical="24dp"
app:paddingBottomSystemWindowInsets="@{true}"
app:paddingLeftSystemWindowInsets="@{true}" />
📖 You can read more information here.
An extension library which provides versions of commonly used ViewGroups with enhanced inset handling. Currently this library is focusing on building upon ConstraintLayout.
A example of a widget is InsetterConstraintLayout,
which enables new attributes to define inset behavior on child views.
The behavior enabled through InsetterConstraintLayout
is similar to that provided by
the insetter-dbx
library, but without the requirement of using data-binding.
<dev.chrisbanes.insetter.widgets.constraintlayout.InsetterConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:paddingSystemWindowInsets="left|top|right|bottom"
android:src="@drawable/rectangle" />
</dev.chrisbanes.insetter.widgets.constraintlayout.InsetterConstraintLayout>
📖 You can read more information here.
The library is being written to production quality, but it is not adhering to semantic versioning, mean we may change the API if needed, though we'll try not to. We're using this repository to allow quick and easy prototyping. The contents of this library may eventually be moved into Android Jetpack at a later date.
repositories {
mavenCentral()
}
dependencies {
// The base library. If you're using either the dbx and/or ktx libraries, you don't need this
implementation "dev.chrisbanes:insetter:<latest version>"
// If you're using data-binding use this
implementation "dev.chrisbanes:insetter-dbx:<latest version>"
// If you're using Kotlin use this too
implementation "dev.chrisbanes:insetter-ktx:<latest version>"
// If you would like to use the enhanced widget set, use this
implementation "dev.chrisbanes:insetter-widgets:<latest version>"
}
Snapshots of the current development version are available, which track the latest commit.
Snapshot repository instructions
The snapshots are deployed to
Sonatype's snapshots
repository:
repositories {
// ...
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
// Check the latest SNAPSHOT version from the link above
implementation "dev.chrisbanes:insetter:<latest version>-SNAPSHOT"
implementation "dev.chrisbanes:insetter-dbx:<latest version>-SNAPSHOT"
implementation "dev.chrisbanes:insetter-ktx:<latest version>-SNAPSHOT"
implementation "dev.chrisbanes:insetter-widgets:<latest version>-SNAPSHOT"
}
Please contribute! We will gladly review any pull requests. Make sure to read the Contributing page first though.
Copyright 2019 Google LLC.
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.