Created
May 24, 2019 22:13
-
-
Save alashow/10fbbd933cb9da8e042dcd9544706d04 to your computer and use it in GitHub Desktop.
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
// activity | |
private val onAppBarLiftListeners = HashSet<AppBarLiftListener>() | |
val appBar = findViewById<AppBarLayout>(R.id.appBar) | |
if (appBar != null) { | |
appBar.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> | |
onAppBarLiftListeners.forEach { it.onAppBarLift(verticalOffset) } | |
}) | |
} | |
fun addOnAppBarLiftListener(listener: AppBarLiftListener) = onAppBarLiftListeners.add(listener) | |
fun removeOnAppBarLiftListener(listener: AppBarLiftListener) = onAppBarLiftListeners.remove(listener) | |
// file | |
interface AppBarLiftListener { | |
fun onAppBarLift(offset: Int) | |
} | |
// base fragment | |
addOnAppBarLiftListener(this@BaseFragment) | |
removeOnAppBarLiftListener(this@BaseFragment) | |
override fun onAppBarLift(offset: Int) { | |
} | |
// some fragment, but need to move to base | |
override fun onAppBarLift(offset: Int) { | |
val y = -((147 / 2).toFloat() + offset.toFloat()) | |
if (y < 0) { | |
binding.progressRetry.progress.translationY = y | |
binding.progressRetry.errorLayout.view.translationY = y | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment