Skip to content

Instantly share code, notes, and snippets.

@grishko188
Last active January 25, 2023 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grishko188/574ea1eddc8abe530bdaf342ea1719da to your computer and use it in GitHub Desktop.
Save grishko188/574ea1eddc8abe530bdaf342ea1719da to your computer and use it in GitHub Desktop.
Access shared data in ViewModel
@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