File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ internal fun rememberCurrentRouteAsState(currentBackStackEntryAsState: State<Nav
1515 currentBackStackEntryAsState.value
1616 ?.destination
1717 ?.route
18- ?.let (Route . Companion ::ofOrNull)
18+ ?.let (Route ::ofOrNull)
1919 }
2020 }
2121
@@ -55,6 +55,8 @@ internal sealed class Route {
5555 RegisterStepOne ,
5656 RegisterStepTwo ,
5757 RegisterStepThree ,
58+ Home ,
59+ Detail ,
5860 )
5961 }
6062
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ fun DetailScreen(
4343 Column (
4444 modifier = Modifier .matchParentSize(),
4545 horizontalAlignment = Alignment .CenterHorizontally ,
46- verticalArrangement = Arrangement .Center ,
46+ verticalArrangement = Arrangement .Top ,
4747 ) {
4848 Text (
4949 text = " Detail" ,
@@ -69,6 +69,7 @@ fun DetailScreen(
6969 Spacer (modifier = Modifier .height(16 .dp))
7070
7171 ElevatedButton (
72+ enabled = text.isNotBlank(),
7273 onClick = {
7374 vm.sendResultToHome()
7475 navigateBack()
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import kotlinx.collections.immutable.plus
1010import kotlinx.coroutines.CancellationException
1111import kotlinx.coroutines.flow.SharingStarted
1212import kotlinx.coroutines.flow.StateFlow
13- import kotlinx.coroutines.flow.map
13+ import kotlinx.coroutines.flow.mapNotNull
1414import kotlinx.coroutines.flow.onCompletion
1515import kotlinx.coroutines.flow.scan
1616import kotlinx.coroutines.flow.stateIn
@@ -25,8 +25,14 @@ class HomeVM(
2525 // Close the bus when this ViewModel is cleared.
2626 channelEventBus.closeKey(DetailResultToHomeEvent )
2727 }
28- .map { it.value }
29- .scan(persistentListOf<String >()) { acc, e -> acc + e }
28+ .mapNotNull { it.value.takeIf (String ::isNotBlank) }
29+ .scan(persistentListOf<String >()) { acc, e ->
30+ if (e in acc) {
31+ acc
32+ } else {
33+ acc + e
34+ }
35+ }
3036 .stateIn(
3137 scope = viewModelScope,
3238 // Using SharingStarted.Lazily is enough, because the event bus is backed by a channel.
You can’t perform that action at this time.
0 commit comments