Skip to content

Commit

Permalink
Added RetainedStateHolder to star sample
Browse files Browse the repository at this point in the history
  • Loading branch information
vulpeszerda committed Jan 12, 2025
1 parent afebc7a commit 9714ce3
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.IntOffset
import com.slack.circuit.codegen.annotations.CircuitInject
import com.slack.circuit.foundation.CircuitContent
import com.slack.circuit.foundation.LocalCircuit
import com.slack.circuit.foundation.NavEvent
import com.slack.circuit.foundation.onNavEvent
import com.slack.circuit.retained.rememberRetained
import com.slack.circuit.retained.rememberRetainedStateHolder
import com.slack.circuit.runtime.CircuitUiEvent
import com.slack.circuit.runtime.CircuitUiState
import com.slack.circuit.runtime.Navigator
Expand Down Expand Up @@ -127,12 +130,19 @@ fun HomeContent(state: HomeScreen.State, modifier: Modifier = Modifier) =
},
) { paddingValues ->
contentComposed = true
val screen = state.navItems[state.selectedIndex].screen
CircuitContent(
screen,
modifier = Modifier.padding(paddingValues),
onNavEvent = { event -> state.eventSink(ChildNav(event)) },
)
val saveableStateHolder = rememberSaveableStateHolder()
val retainedStateHolder = rememberRetainedStateHolder()
val currentScreen = state.navItems[state.selectedIndex].screen
saveableStateHolder.SaveableStateProvider(currentScreen) {
retainedStateHolder.RetainedStateProvider(state.selectedIndex.toString()) {
CircuitContent(
currentScreen,
modifier = Modifier.padding(paddingValues),
onNavEvent = { event -> state.eventSink(ChildNav(event)) },
)
}
}
contentComposed = true
}
Platform.ReportDrawnWhen { contentComposed }
}
Expand Down

0 comments on commit 9714ce3

Please sign in to comment.