-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBackDispatcher.kt
61 lines (51 loc) · 1.84 KB
/
BackDispatcher.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
package com.arkivanov.essenty.backhandler
import kotlin.js.JsName
/**
* Provides a way to manually trigger back button handlers.
*/
interface BackDispatcher : BackHandler {
/**
* Returns `true` if there is at least one enabled handler, `false` otherwise.
*/
val isEnabled: Boolean
/**
* Adds the provided [listener], which will be called every time the enabled state of
* this [BackDispatcher] changes.
*/
fun addEnabledChangedListener(listener: (isEnabled: Boolean) -> Unit)
/**
* Removes the provided enabled state changed [listener].
*/
fun removeEnabledChangedListener(listener: (isEnabled: Boolean) -> Unit)
/**
* If no predictive back gesture is currently in progress, finds the last enabled
* callback with the highest priority and calls [BackCallback.onBack].
*
* If the predictive back gesture is currently in progress, calls [BackCallback.onBack] on
* the previously selected callback.
*
* @return `true` if any callback was triggered, `false` otherwise.
*/
fun back(): Boolean
/**
* Starts handling the predictive back gesture. Picks one of the enabled callback (if any)
* that will be handling the gesture and calls [BackCallback.onBackStarted].
*
* @return `true` if any callback was triggered, `false` otherwise.
*/
fun startPredictiveBack(backEvent: BackEvent): Boolean
/**
* Calls [BackCallback.onBackProgressed] on the previously selected callback.
*/
fun progressPredictiveBack(backEvent: BackEvent)
/**
* Calls [BackCallback.onBackCancelled] on the previously selected callback.
*/
fun cancelPredictiveBack()
}
/**
* Creates and returns a default implementation of [BackDispatcher].
*/
@JsName("backDispatcher")
fun BackDispatcher(): BackDispatcher =
DefaultBackDispatcher()