aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt17
1 files changed, 13 insertions, 4 deletions
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() {
}