-
Notifications
You must be signed in to change notification settings - Fork 13
/
ListDetailComposable.kt
75 lines (69 loc) · 2.49 KB
/
ListDetailComposable.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
62
63
64
65
66
67
68
69
70
71
72
73
74
package dev.enro.example.destinations.listdetail.compose
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.platform.LocalConfiguration
import dev.enro.annotations.NavigationDestination
import dev.enro.core.NavigationContainerKey
import dev.enro.core.NavigationKey
import dev.enro.core.compose.rememberNavigationContainer
import dev.enro.core.container.EmptyBehavior
import dev.enro.core.container.accept
import kotlinx.parcelize.Parcelize
@Parcelize
class ListDetailComposable : NavigationKey.SupportsPush
val listContainerKey = NavigationContainerKey.FromName("listContainerKey")
val detailContainerKey = NavigationContainerKey.FromName("detailContainerKey")
@Composable
@NavigationDestination(ListDetailComposable::class)
fun ListDetailComposeScreen() {
val listContainerController = rememberNavigationContainer(
root = ListComposable(),
key = listContainerKey,
emptyBehavior = EmptyBehavior.CloseParent,
filter = accept { key<ListComposable>() }
)
val detailContainerController = rememberNavigationContainer(
key = detailContainerKey,
emptyBehavior = EmptyBehavior.AllowEmpty,
filter = accept { key<DetailComposable>() }
)
val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
if (isLandscape) {
Row(
modifier = Modifier
.background(MaterialTheme.colors.background)
.fillMaxSize()
) {
Box(
modifier = Modifier
.weight(1f, true)
.clipToBounds()
) {
listContainerController.Render()
}
Box(
modifier = Modifier
.weight(1f, true)
.clipToBounds()
) {
detailContainerController.Render()
}
}
} else {
Box(
modifier = Modifier
.background(MaterialTheme.colors.background)
.fillMaxSize()
) {
listContainerController.Render()
detailContainerController.Render()
}
}
}