Skip to content

Helpers of the Chrome Custom tabs re-written in Kotlin and with Architecture Components to offer a simpler API

License

Notifications You must be signed in to change notification settings

saurabharora90/CustomTabs-Kotlin

Repository files navigation

Chrome Custom Tabs - Kotlin and Lifecycle Aware

This is a rewrite of the helpers offered by Google.

The ones offered by Google are written in JAVA and require integration with the Activity lifecycle if the user needs to support warmup of the browser for performance gains.

  • This new implementaion uses Lifecycle to hide away the service binding logic.
  • Rewritting in Kotlin makes the code consixe and offers a cleaner and easier to work with API, espcially with the support of optional paramters.

Usage

Add a dependency to your build.gradle:

dependencies {
    implementation 'com.saurabharora.customtabs:customtabs:1.1'
}

Now in your Activity/Fragment from where you want to launch the Chrome Custom Tabs:

private val  customTabActivityHelper: CustomTabActivityHelper =
    CustomTabActivityHelper(context = this, lifecycle = lifecycle, connectionCallback = this)
    
//If you know the potential URL that will be loaded:
customTabActivityHelper.mayLaunchUrl(uri)
    
val customTabsIntent = CustomTabsIntent.Builder(customTabActivityHelper.session)
                       .build()
                       
customTabsIntent.launchWithFallback(activity = this, uri = uri)

See the demo app for more details.

About

Helpers of the Chrome Custom tabs re-written in Kotlin and with Architecture Components to offer a simpler API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages