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



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

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.



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



41
42
43
# File 'app/controllers/turbo/native/navigation.rb', line 41

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.



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



37
38
39
# File 'app/controllers/turbo/native/navigation.rb', line 37

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.



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