chrisbanes / insetter

Insetter is a library to help apps handle WindowInsets more easily
https://chrisbanes.github.io/insetter
Apache License 2.0
1.13k stars 42 forks source link

Migration from 0.3.1 to 0.6.0 #113

Closed osipxd closed 2 years ago

osipxd commented 3 years ago

Just created functions with annotation @Deprecated and replaceWith expressions to make migration easier in simple cases.

@file:Suppress("PackageDirectoryMismatch", "unused")

package dev.chrisbanes.insetter

import android.view.View

@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Use applyInsetter instead",
    replaceWith = ReplaceWith(
        "this.applyInsetter { type(statusBars = top, navigationBars = bottom) { padding() } }",
        "dev.chrisbanes.insetter.applyInsetter"
    )
)
fun View.applySystemWindowInsetsToPadding(top: Boolean = false, bottom: Boolean = false) {
    error("should not be used")
}

@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Use applyInsetter instead",
    replaceWith = ReplaceWith(
        "this.applyInsetter { type(statusBars = top, navigationBars = bottom) { margin() } }",
        "dev.chrisbanes.insetter.applyInsetter"
    )
)
fun View.applySystemWindowInsetsToMargin(top: Boolean = false, bottom: Boolean = false) {
    error("should not be used")
}

object Insetter {
    @Deprecated(
        level = DeprecationLevel.ERROR,
        message = "Use WindowCompat.setDecorFitsSystemWindows() instead",
        replaceWith = ReplaceWith(
            "WindowCompat.setDecorFitsSystemWindows(window, !enabled)",
            "androidx.core.view.WindowCompat"
        )
    )
    fun setEdgeToEdgeSystemUiFlags(view: View, enabled: Boolean = true) {
        error("should not be used")
    }
}
osipxd commented 3 years ago

For example:

// Before
view.applySystemWindowInsetsToPadding(top = true)

// After replace
view.applyInsetter { type(statusBars = true) { padding() } }

// Before
view.applySystemWindowInsetsToMargin(top = true, bottom = true)

// After replace
view.applyInsetter { type(statusBars = true, navigationBars = true) { margin() } }

It is not the exact equivalent, but the migration gets easier.

chrisbanes commented 3 years ago

Feel free to submit a PR and we'll get them merged 👍