From 9cb9c1f057e5326f34cf2838177504df1fad64ed Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 2 Jul 2019 16:38:08 -0700 Subject: Expose swipe back --- .../kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'core/src/main/kotlin/ca') diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt index 1c6de12..90e6e6d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt @@ -34,8 +34,12 @@ internal object SwipeBackHelper { private operator fun get(activity: Activity): SwipeBackPage? = pageStack.firstOrNull { it.activityRef.get() === activity } - fun onCreate(activity: Activity, builder: SwipeBackContract.() -> Unit = {}) { - val page = this[activity] ?: pageStack.push(SwipeBackPage(activity).apply { builder() }) + fun onCreate( + activity: Activity, + builder: SwipeBackContract.() -> Unit = {} + ): SwipeBackContract { + val swipeBackPage = SwipeBackPage(activity).apply(builder) + val page = this[activity] ?: pageStack.push(swipeBackPage) val startAnimation: Int = when (page.edgeFlag) { SWIPE_EDGE_LEFT -> R.anim.kau_slide_in_right SWIPE_EDGE_RIGHT -> R.anim.kau_slide_in_left @@ -45,6 +49,7 @@ internal object SwipeBackHelper { activity.overridePendingTransition(startAnimation, 0) page.onPostCreate() KL.v { "KauSwipe onCreate ${activity.localClassName}" } + return swipeBackPage } fun onDestroy(activity: Activity) { @@ -73,13 +78,17 @@ internal object SwipeBackHelper { * * Lastly, don't forget to call [kauSwipeOnDestroy] as well when the activity is destroyed. */ -fun Activity.kauSwipeOnCreate(builder: SwipeBackContract.() -> Unit = {}) = SwipeBackHelper.onCreate(this, builder) +fun Activity.kauSwipeOnCreate(builder: SwipeBackContract.() -> Unit = {}): SwipeBackContract = + SwipeBackHelper.onCreate(this, builder) /** * Deprecated as onPostCreate seems unreliable. * We will instead initialize everything during [kauSwipeOnCreate] */ -@Deprecated(level = DeprecationLevel.WARNING, message = "All functionality has been moved to kauSwipeOnCreate") +@Deprecated( + level = DeprecationLevel.WARNING, + message = "All functionality has been moved to kauSwipeOnCreate" +) fun Activity.kauSwipeOnPostCreate() { } -- cgit v1.2.3