How to serve different view for native app with hotwire?

I have an android/ios app built with hotwire adapter (based on the demo app). How can I serve different views for it from my web app? I want to make sure that the views for the browser on mobile browser is different to the views served to my mobile app.

If you’re using Rails, you could use variants that are based on the request’s user agent. It looks like the demo app will send requests with the user agent "Turbo Native iOS". (Defined here.)

Some pseudo-code for this idea might look like:

class ApplicationController < ActionController::Base
  before_action :determine_variant

  private

  def determine_variant
    request.variant = :ios if request.user_agent.includes?("Turbo Native iOS")
  end
end

If you’re not on Rails, the same idea of switching on the user agent string would still be possible.

1 Like