Created
March 30, 2020 16:04
-
-
Save weverb2/744607a56e4484dc5b296c8ffc6f539c to your computer and use it in GitHub Desktop.
Tab Selected Inline Functions
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 com.google.android.material.tabs.TabLayout | |
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener | |
import com.google.android.material.tabs.TabLayout.Tab | |
inline fun TabLayout.doOnTabReselected( | |
crossinline action: (tab: Tab?) -> Unit | |
) = addOnTabSelectedListener(onTabReselected = action) | |
inline fun TabLayout.doOnTabUnselected( | |
crossinline action: (tab: Tab?) -> Unit | |
) = addOnTabSelectedListener(onTabUnselected = action) | |
inline fun TabLayout.doOnTabSelected( | |
crossinline action: (tab: Tab?) -> Unit | |
) = addOnTabSelectedListener(onTabSelected = action) | |
inline fun TabLayout.addOnTabSelectedListener( | |
crossinline onTabReselected: (tab: Tab?) -> Unit = {}, | |
crossinline onTabUnselected: (tab: Tab?) -> Unit = {}, | |
crossinline onTabSelected: (tab: Tab?) -> Unit = {} | |
): OnTabSelectedListener { | |
val tabSelectedListener = object : OnTabSelectedListener { | |
override fun onTabReselected(tab: Tab?) { | |
onTabReselected(tab) | |
} | |
override fun onTabUnselected(tab: Tab?) { | |
onTabUnselected(tab) | |
} | |
override fun onTabSelected(tab: Tab?) { | |
onTabSelected(tab) | |
} | |
} | |
addOnTabSelectedListener(tabSelectedListener) | |
return tabSelectedListener | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment