Skip to content

Commit 8cb5453

Browse files
author
李泽鹏
committed
动画可自定义
1 parent ea9df19 commit 8cb5453

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

lib_base/src/main/java/com/gxyj/base/helper/RouterHelper.kt

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import com.gxyj.base.IS_DEBUG_MODE
1717
class RouterHelper {
1818
companion object {
1919
@AnimRes
20-
var mEnterAnim: Int = android.R.anim.fade_in
20+
var mEnterAnim: Int = 0
2121
@AnimRes
22-
var mExitAnim: Int = android.R.anim.fade_out
22+
var mExitAnim: Int = 0
2323

2424
fun init(
2525
context: Application,
@@ -39,34 +39,49 @@ class RouterHelper {
3939
/**
4040
* 添加动画的话必须传入aty的context(v的context也是),代表这个aty,不然默认是application,动画不生效
4141
*/
42-
fun gotoAty(path: String): Postcard {
42+
fun gotoAty(
43+
path: String,
44+
@AnimRes enterAnim: Int = mEnterAnim,
45+
@AnimRes exitAnim: Int = mEnterAnim
46+
): Postcard {
4347
return ARouter.getInstance().build(path)
44-
.withTransition(mEnterAnim, mExitAnim)
48+
.withTransition(enterAnim, exitAnim)
4549
}
4650

4751
/**
4852
* 去单个实例的栈位置,并清除跳转之前的所有的栈
4953
* 参数通过onNewIntent接收
5054
*/
51-
fun gotoAtySingleTask(path: String): Postcard {
52-
return gotoAty(path)
55+
fun gotoAtySingleTask(
56+
path: String,
57+
@AnimRes enterAnim: Int = mEnterAnim,
58+
@AnimRes exitAnim: Int = mEnterAnim
59+
): Postcard {
60+
return gotoAty(path, enterAnim, exitAnim)
5361
.withFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
5462
}
5563

56-
fun gotoFrag(navController: NavController, @IdRes path: Int, bundle: Bundle? = null) {
64+
fun gotoFrag(
65+
navController: NavController,
66+
@IdRes path: Int,
67+
@AnimRes enterAnim: Int = mEnterAnim,
68+
@AnimRes exitAnim: Int = mEnterAnim,
69+
bundle: Bundle? = null
70+
) {
5771
navController.navigate(path, bundle, navOptions {
5872
anim {
59-
enter = mEnterAnim
60-
exit = mExitAnim
61-
popEnter = mEnterAnim
62-
popExit = mExitAnim
73+
enter = enterAnim
74+
exit = exitAnim
75+
popEnter = enterAnim
76+
popExit = exitAnim
6377
}
6478
})
6579
}
6680

6781
/**
6882
* 去单个实例的栈位置,并清除跳转之前的所有的栈
6983
* 如果要传参数通过aty的vm共享
84+
* 自动使用了去的时候的动画
7085
*/
7186
fun gotoFragSingleTask(navController: NavController, @IdRes path: Int) {
7287
navController.popBackStack(path, false)

0 commit comments

Comments
 (0)