Module: Turbo::Native::Navigation

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/turbo/native/navigation.rb

Overview

Turbo is built to work with native navigation principles and present those alongside what’s required for the web. When you have Turbo Native clients running (see the Turbo iOS and Turbo Android projects for details), you can respond to native requests with three dedicated responses: recede, resume, refresh.

turbo-android handles these actions automatically. You are required to implement the handling on your own for turbo-ios.

Instance Method Summary collapse

Instance Method Details

#recede_or_redirect_back_or_to(url, **options) ⇒ Object

Same as recede_or_redirect_to but redirects to the previous page or provided fallback location if the Turbo Native app is not present.



34
35
36
# File 'app/controllers/turbo/native/navigation.rb', line 34

def recede_or_redirect_back_or_to(url, **options)
  turbo_native_action_or_redirect url, :recede, :back, options
end

#recede_or_redirect_to(url, **options) ⇒ Object

Tell the Turbo Native app to dismiss a modal (if presented) or pop a screen off of the navigation stack. Otherwise redirect to the given URL if Turbo Native is not present.



19
20
21
# File 'app/controllers/turbo/native/navigation.rb', line 19

def recede_or_redirect_to(url, **options)
  turbo_native_action_or_redirect url, :recede, :to, options
end

#refresh_or_redirect_back_or_to(url, **options) ⇒ Object

Same as refresh_or_redirect_to but redirects to the previous page or provided fallback location if the Turbo Native app is not present.



44
45
46
# File 'app/controllers/turbo/native/navigation.rb', line 44

def refresh_or_redirect_back_or_to(url, **options)
  turbo_native_action_or_redirect url, :refresh, :back, options
end

#refresh_or_redirect_to(url, **options) ⇒ Object

Tell the Turbo Native app to refresh the current screen, otherwise redirect to the given URL if Turbo Native is not present.



29
30
31
# File 'app/controllers/turbo/native/navigation.rb', line 29

def refresh_or_redirect_to(url, **options)
  turbo_native_action_or_redirect url, :refresh, :to, options
end

#resume_or_redirect_back_or_to(url, **options) ⇒ Object

Same as resume_or_redirect_to but redirects to the previous page or provided fallback location if the Turbo Native app is not present.



39
40
41
# File 'app/controllers/turbo/native/navigation.rb', line 39

def resume_or_redirect_back_or_to(url, **options)
  turbo_native_action_or_redirect url, :resume, :back, options
end

#resume_or_redirect_to(url, **options) ⇒ Object

Tell the Turbo Native app to ignore this navigation, otherwise redirect to the given URL if Turbo Native is not present.



24
25
26
# File 'app/controllers/turbo/native/navigation.rb', line 24

def resume_or_redirect_to(url, **options)
  turbo_native_action_or_redirect url, :resume, :to, options
end

#turbo_native_app?Boolean

Turbo Native applications are identified by having the string “Turbo Native” as part of their user agent.

Returns:

  • (Boolean)


14
15
16
# File 'app/controllers/turbo/native/navigation.rb', line 14

def turbo_native_app?
  request.user_agent.to_s.match?(/Turbo Native/)
end