Skip to content

Instantly share code, notes, and snippets.

@oliverspryn
Created June 20, 2019 15:04
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 oliverspryn/4aa0ff2c4262a3979dc6aee66ff6e17b to your computer and use it in GitHub Desktop.
Save oliverspryn/4aa0ff2c4262a3979dc6aee66ff6e17b to your computer and use it in GitHub Desktop.
A custom navigator with a populated navigate method
@Navigator.Name("chrome")
class ChromeCustomTabsNavigator(
private val context: Context
) : Navigator<ChromeCustomTabsNavigator.Destination>() {
override fun navigate(destination: Destination, args: Bundle?, navOptions: NavOptions?, navigatorExtras: Extras?): NavDestination? {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(context, destination.toolbarColor))
builder.setSecondaryToolbarColor(ContextCompat.getColor(context, destination.secondaryToolbarColor))
val intent = builder.build()
val uri = args?.getParcelable<Uri>("uri")
intent.launchUrl(context, uri)
return null // Do not add to the back stack, managed by Chrome Custom Tabs
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment