Created
April 14, 2021 16:31
-
-
Save kibotu/86a9900dcf8a03ae57fb91488e64404c to your computer and use it in GitHub Desktop.
AppBarLayoutViewHolder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.coordinatorlayout.widget.CoordinatorLayout | |
import com.google.android.material.appbar.AppBarLayout | |
import java.io.Closeable | |
class AppBarLayoutViewHolder(appBarLayout: AppBarLayout) : Closeable { | |
var expandable: Boolean = true | |
set(value) { | |
field = value | |
layout?.setExpanded(value) | |
layout?.setLiftable(value) | |
// https://stackoverflow.com/a/46973974/1006741 | |
val params = layout?.layoutParams as CoordinatorLayout.LayoutParams | |
if (params.behavior == null) | |
params.behavior = DisableableAppBarLayoutBehavior(layout?.context) | |
val behaviour = params.behavior as DisableableAppBarLayoutBehavior | |
behaviour.isEnabled = value | |
} | |
var layout by weak<AppBarLayout?>() | |
init { | |
layout = appBarLayout | |
} | |
override fun close() { | |
layout = null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment