-
Notifications
You must be signed in to change notification settings - Fork 70
/
ComposeStep.kt
34 lines (29 loc) · 1.14 KB
/
ComposeStep.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
package com.wealthfront.magellan.sample.migration.tide
import androidx.annotation.VisibleForTesting
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.saveable.SaveableStateHolder
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import com.wealthfront.magellan.core.Navigable
import com.wealthfront.magellan.lifecycle.LifecycleAwareComponent
import com.wealthfront.magellan.lifecycle.createAndAttachFieldToLifecycleWhenShown
import java.util.UUID
abstract class ComposeStep : Navigable, LifecycleAwareComponent() {
private var state: SaveableStateHolder? = null
final override var view: ComposeView? by createAndAttachFieldToLifecycleWhenShown { ComposeView(it) }
@VisibleForTesting set
fun setContent(content: @Composable () -> Unit) {
view?.setContent {
if (state == null) {
state = rememberSaveableStateHolder()
}
Box(modifier = Modifier) {
state!!.SaveableStateProvider(UUID.randomUUID()) {
content()
}
}
}
}
}