-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathHelper.kt
65 lines (57 loc) · 2.02 KB
/
Helper.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.fxn.bubbletabbarapp.utils
import androidx.navigation.ActivityNavigator
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.viewpager.widget.ViewPager
import com.fxn.BubbleTabBar
import com.fxn.bubbletabbarapp.R
/**
* @author : Akshay Sharma
* @since : 11/01/21, Mon
* akshay2211.github.io
**/
fun BubbleTabBar.setupViewPager(viewPager: ViewPager) {
viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
}
override fun onPageSelected(position: Int) {
setSelected(position, false)
}
override fun onPageScrollStateChanged(state: Int) {
}
})
}
fun BubbleTabBar.onNavDestinationSelected(
itemId: Int,
navController: NavController
): Boolean {
val builder = NavOptions.Builder()
.setLaunchSingleTop(true)
if (navController.currentDestination!!.parent!!.findNode(itemId) is ActivityNavigator.Destination) {
builder.setEnterAnim(R.anim.nav_default_enter_anim)
.setExitAnim(R.anim.nav_default_exit_anim)
.setPopEnterAnim(R.anim.nav_default_pop_enter_anim)
.setPopExitAnim(R.anim.nav_default_pop_exit_anim)
} else {
builder.setEnterAnim(R.animator.nav_default_enter_anim)
.setExitAnim(R.animator.nav_default_exit_anim)
.setPopEnterAnim(R.animator.nav_default_pop_enter_anim)
.setPopExitAnim(R.animator.nav_default_pop_exit_anim)
}
//if (itemId == getChildAt(0).id) {
//builder.setPopUpTo(findStartDestination(navController.graph)!!.id, true)
// }
builder.setPopUpTo(itemId, true)
val options = builder.build()
return try {
//TODO provide proper API instead of using Exceptions as Control-Flow.
navController.navigate(itemId, null, options)
true
} catch (e: IllegalArgumentException) {
false
}
}