forked from ikarenkov/Modo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiScreenActions.kt
48 lines (37 loc) · 2.07 KB
/
MultiScreenActions.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
package com.github.terrakok.modo.multiscreen
import com.github.terrakok.modo.NavigationAction
import com.github.terrakok.modo.NavigationContainer
import com.github.terrakok.modo.ReducerAction
interface MultiScreenAction : NavigationAction<MultiScreenState>
fun interface MultiScreenReducerAction : MultiScreenAction, ReducerAction<MultiScreenState>
@Deprecated(
message = "Class with this name was renamed to SelectScreen. This typealias will be removed in further releases.",
replaceWith = ReplaceWith("SetMultiScreenState")
)
typealias SetContainers = SetMultiScreenState
class SetMultiScreenState(val state: MultiScreenState) : MultiScreenReducerAction {
override fun reduce(oldState: MultiScreenState): MultiScreenState =
state
}
@Deprecated(
message = "Class with this name was renamed to SelectScreen. This typealias will be removed in further releases.",
replaceWith = ReplaceWith("SelectScreen")
)
typealias SelectContainer = SelectScreen
class SelectScreen(private val pos: Int) : MultiScreenReducerAction {
override fun reduce(oldState: MultiScreenState): MultiScreenState =
oldState.copy(selected = pos)
}
fun MultiScreenNavContainer.dispatch(action: (MultiScreenState) -> MultiScreenState) = dispatch(MultiScreenReducerAction(action))
@Deprecated(
message = "This function was renamed to setState. This function will be removed in further releases.",
replaceWith = ReplaceWith("setState(state)")
)
fun NavigationContainer<MultiScreenState, MultiScreenAction>.setContainers(state: MultiScreenState) = setState(state)
@Deprecated(
message = "This function was renamed to selectScreen. This function will be removed in further releases.",
replaceWith = ReplaceWith("selectScreen(index)")
)
fun NavigationContainer<MultiScreenState, MultiScreenAction>.selectContainer(index: Int) = selectScreen(index)
fun NavigationContainer<MultiScreenState, MultiScreenAction>.setState(state: MultiScreenState) = dispatch(SetMultiScreenState(state))
fun NavigationContainer<MultiScreenState, MultiScreenAction>.selectScreen(pos: Int) = dispatch(SelectScreen(pos))