Skip to content

Commit

Permalink
Document Navigation and expose methods publicly (#438)
Browse files Browse the repository at this point in the history
* Document Navigation and expose methods publicly

* Note changes for turbo-android vs. turbo-ios

* Grammer fix in documentation

Co-authored-by: Jordan Elver <jordan@elver.me>

---------

Co-authored-by: Jordan Elver <jordan@elver.me>
  • Loading branch information
joemasilotti and jordelver authored Mar 4, 2023
1 parent 7402db8 commit 728b963
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/controllers/turbo/native/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
# 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: <tt>recede</tt>, <tt>resume</tt>, <tt>refresh</tt>.
#
# FIXME: Supply full description of when we use either.
# turbo-android handles these actions automatically. You are required to implement the handling on your own for turbo-ios.
module Turbo::Native::Navigation
private

# Turbo Native applications are identified by having the string "Turbo Native" as part of their user agent.
def turbo_native_app?

This comment has been minimized.

Copy link
@seanpdoyle

seanpdoyle Mar 5, 2023

Contributor

Would this predicate method be even more helpful if it were marked as a helper_method so that view templates can utilize it?

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

# Tell the Turbo Native app to dismiss a modal (if presented) or pop a screen off of the navigation stack.
def recede_or_redirect_to(url, **options)
turbo_native_action_or_redirect url, :recede, :to, options
end

# Tell the Turbo Native app to ignore this navigation.
def resume_or_redirect_to(url, **options)
turbo_native_action_or_redirect url, :resume, :to, options
end

# Tell the Turbo Native app to refresh the current screen.
def refresh_or_redirect_to(url, **options)
turbo_native_action_or_redirect url, :refresh, :to, options
end


def recede_or_redirect_back_or_to(url, **options)
turbo_native_action_or_redirect url, :recede, :back, options
end
Expand All @@ -30,6 +35,8 @@ def resume_or_redirect_back_or_to(url, **options)
def refresh_or_redirect_back_or_to(url, **options)
turbo_native_action_or_redirect url, :refresh, :back, options
end

private

# :nodoc:
def turbo_native_action_or_redirect(url, action, redirect_type, options = {})
Expand All @@ -43,9 +50,4 @@ def turbo_native_action_or_redirect(url, action, redirect_type, options = {})
redirect_to url, options
end
end

# Turbo Native applications are identified by having the string "Turbo Native" as part of their user agent.
def turbo_native_app?
request.user_agent.to_s.match?(/Turbo Native/)
end
end

0 comments on commit 728b963

Please sign in to comment.