aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-07-02 16:38:08 -0700
committerAllan Wang <me@allanwang.ca>2019-07-02 16:38:08 -0700
commit9cb9c1f057e5326f34cf2838177504df1fad64ed (patch)
tree5f911ff10d73ec2659cde222df3137f18f0acb34 /core/src/main/kotlin
parent347f820db539de4823572a22ae8c16611167af72 (diff)
downloadkau-9cb9c1f057e5326f34cf2838177504df1fad64ed.tar.gz
kau-9cb9c1f057e5326f34cf2838177504df1fad64ed.tar.bz2
kau-9cb9c1f057e5326f34cf2838177504df1fad64ed.zip
Expose swipe back
Diffstat (limited to 'core/src/main/kotlin')
-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() {
}