Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

evowizz/compose-to-edge

Repository files navigation

Compose-To-Edge

Build

Compose-To-Edge is a small library allowing you to easily set up edge-to-edge configurations for your Jetpack Compose app.

DEPRECATED

Compose-To-Edge was really fun to create. But since then, some libraries have evolved and are constantly maintained. If you are looking for something similar to Compose-To-Edge, I suggest you to look at Accompanist which you can use along with WindowCompat.setDecorFitsSystemWindows(window, false)

Setup

Let's start by adding Jitpack to your project.

    allprojects {
	    repositories {
		    ...
		    maven { url 'https://jitpack.io' }
	    }
    }

Finally, just add the dependency.

    dependencies {
        // Latest available version can be found at the very top of the README file
        implementation 'com.github.evowizz:compose-to-edge:$version'
    }

Usage

Here's how you would start a basic Jetpack Compose project.

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
      MyTheme {
        Greeting("Android")
      }
    }
  }

To get started with Compose-To-Edge, the only thing you need to do is to replace setContent with setEdgeToEdgeContent as seen in the following example.

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setEdgeToEdgeContent {
      MyTheme {
        Greeting("Android")
      }
    }
  }

Additionally, Compose-To-Edge provides 2 Ambients allowing you to better control your new edge-to-edge app:

  • AmbientWindow: Static Ambient of the current window which allows you to easily change the Status Bar and Navigation Bar colors.
  • AmbientWindowInsets: Static Ambient of the rootWindowInsets (as WindowInsetsCompat) allowing you to easily obtain details about system insets.

The setEdgeToEdge(edgeToEdge: Boolean) function is still accessible if for some reasons you want to disable the edge-to-edge configuration. (But you won't do that, right?... RIGHT?)

This project includes a small sample demonstrating the usage of setEdgeToEdgeContent and WindowInsetsAmbient.

License

 Copyright 2020 Dylan Roussel

 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.