24
loading...
This website collects cookies to deliver better user experience
Build high-fidelity hybrid apps with native navigation and a single shared web view. Turbo Native for iOS provides the tooling to wrap your Turbo 7-enabled web app in a native iOS shell. It manages a single WKWebView instance across multiple view controllers, giving you native navigation UI with all the client-side performance benefits of Turbo. - github.com/hotwired/turbo-ios
git clone https://github.com/dalezak/turbo-ios-base.git
turbo-rails
to your Gemfile.gem "turbo-rails"
yarn add @hotwired/turbo-rails
npm add @hotwired/turbo-rails
import { Turbo } from "@hotwired/turbo-rails";
window.Turbo = Turbo;
export default class Bridge {
static sayHello() {
document.body.innerHTML = "<h1>Hello!</h1>"
}
}
import Bridge from "../turbo/bridge.js";
window.bridge = Bridge;
application_helper.rb
def turbo?
request.user_agent.include?("Turbo-")
end
def turbo_ios?
request.user_agent.include?("Turbo-iOS")
end
def turbo_android?
request.user_agent.include?("Turbo-Android")
end
<head>
so the app knows if a user is logged in or not.<meta name="turbo:authenticated" content="<%= user_signed_in? %>">
unless turbo?
check around where you usually render your navbar in your Rails app.<% unless turbo? %>
<nav class="d-block">
<%= render 'partials/navbar' %>
</nav>
<% end %>
turbo.json
used for rules and settings, here's a sample to get you started.class TurboController < ApplicationController
def index
render json: {
"settings": {
"navbar": {
"background": "#888888",
"foreground": "#ffffff"
},
"tabbar": {
"background": "#888888",
"selected": "#ffffff",
"unselected": "#bbbbbb"
},
"tabs": [
{
"title": "Home",
"visit": "/",
"icon_ios": "house",
"protected": false
},
{
"title": "Profile",
"visit": "/profile",
"icon_ios": "person",
"protected": true
}
],
"buttons": [
{
"path": "/",
"side": "left",
"icon_ios": "line.horizontal.3",
"script": "window.bridge.showMenu();",
"protected": false
},
{
"path": "/",
"side": "right",
"title": "Add",
"visit": "/posts/new",
"protected": true
}
]
},
"rules": [
{
"patterns": [
"/new$",
"/edit$"
],
"properties": {
"presentation": "modal"
}
},
{
"patterns": [
"/users/login"
],
"properties": {
"presentation": "modal"
}
},
{
"patterns": [
"/users/logout"
],
"properties": {
"presentation": "replace"
}
}
]
}
end
end
turbo#index
.get 'turbo', to: "turbo#index", as: :turbo
turbo.json
returned from the turbo_controller.rb
. protected
property if the user is authenticated or not. Your navbar buttons can either visit a page or trigger javascript on your server.