Skip to content

Conversation

@jayohms
Copy link
Contributor

@jayohms jayohms commented Mar 25, 2025

This coincides with work in the iOS library in hotwired/hotwire-native-ios#105. To handle more complex scenarios, we need more flexibility to return the route decision after running logic in the handle() method.

An implemented RouteDecisionHandler will now look like:

class BrowserRouteDecisionHandler : Router.RouteDecisionHandler {
    override val name = "browser"

    override fun matches(
        location: String,
        configuration: NavigatorConfiguration
    ): Boolean {
        return configuration.startLocation.toUri().host != location.toUri().host
    }

    override fun handle(
        location: String,
        configuration: NavigatorConfiguration,
        activity: HotwireActivity
    ): Router.Decision {
        val intent = Intent(Intent.ACTION_VIEW, location.toUri())

        try {
            activity.startActivity(intent)
        } catch (e: ActivityNotFoundException) {
            logError("BrowserRouteDecisionHandler", e)
        }

        // New: Decision return value
        return Router.Decision.CANCEL
    }
}

@jayohms jayohms requested a review from svara March 25, 2025 11:47
Copy link

@svara svara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@jayohms jayohms merged commit 95a7cd4 into main Mar 31, 2025
1 check passed
@jayohms jayohms deleted the route-decision-change branch March 31, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants