Skip to content

Compatability with Navigation 3 #201

@andreas-umbricht

Description

@andreas-umbricht

Is there an existing issue for this?

  • I have searched existing issues and found no similar bug report.

Description of the problem

We are currently working on migrating our app to Navigation-3. Upon migration I noticed that the app suddenly crashes whenever I want to play a (Pillarbox) video if there is a MediaRouterButton.

After some quick investigation I found that in the MediaRouteButtonViewModel.Factory a key called APPLICATION_KEY is required to gain access to the context of the application. With jetpack navigation, this was set by the framework but with Navigation-3 sadly this value is not provided anymore, since it's a KMP library.

I found a workaround for the moment, but it's a quite complex copy-paste-style class that basically extends the standard-implementation of ViewModelStoreProvider , so that Application is still passed to the extras like before. We would like to avoid to have this class, but this is only possible if the MediaRouteButtonViewModel.Factory and maybe other Factories (I haven't checked them all) does not rely on the application in the extras. So maybe we could use an AndroidViewModel or maybe we could pass the context of compose to that factory. I am not really sure about side effects here with these two solutions.

Relevant stack trace or log output

Reproducibility

Always

Steps to reproduce

    NavDisplay(
        entryDecorators = listOf(
            rememberSaveableStateHolderNavEntryDecorator(),
            rememberViewModelStoreNavEntryDecorator(),
        ),
        ....
        entryProvider = entryProvider {
            entry<Route.TopNews>(
                metadata = Route.TopNews.metadata,
            ) {
                TopNewsScreen(
                    mainViewModel = mainViewModel,
                    activity = activity,
                )
            }
       ....
    )


@Composable
fun TopNewsScreen() {
      MediaRouteButton(
          routeSelector = MediaRouteSelector.Builder()
              .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
              .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
              .build(),
          colors = IconButtonColors(
              containerColor = Color.Transparent,
              contentColor = LocalPlayerColors.current.controls,
              disabledContainerColor = Color.Transparent,
              disabledContentColor = LocalPlayerColors.current.controls,
          ),
          onDialogTypeChange = {
              state.onControlsInteracted(it != DialogType.None)
          },
      )
}

Library version

1.1.0

Android version(s)

All Android Versions

Code sample

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions