Last active
January 25, 2023 16:53
-
-
Save grishko188/574ea1eddc8abe530bdaf342ea1719da to your computer and use it in GitHub Desktop.
Access shared data in ViewModel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class SharingTargetViewModel @Inject constructor( | |
savedStateHandle: SavedStateHandle, | |
... | |
) : ViewModel() { | |
private val sharedContentState = savedStateHandle.getStateFlow(NavController.KEY_DEEP_LINK_INTENT, Intent()) | |
.map { intent -> intent.parseSharedContent() } | |
.map { | |
// map to ui state | |
} | |
.stateIn( | |
scope = viewModelScope, | |
started = SharingStarted.WhileSubscribed(5_000), | |
initialValue = SharedContent.EMPTY | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment