Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Migration from 0.3.1 to 0.6.0 #113

Closed
osipxd opened this issue Jun 5, 2021 · 2 comments · Fixed by #114
Closed

Migration from 0.3.1 to 0.6.0 #113

osipxd opened this issue Jun 5, 2021 · 2 comments · Fixed by #114

Comments

@osipxd
Copy link
Contributor

osipxd commented Jun 5, 2021

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
Copy link
Contributor Author

osipxd commented Jun 5, 2021

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
Copy link
Owner

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants