Thursday, April 25, 2024
HomeRuby On RailsTurbo Native for iOS | Drifting Ruby

Turbo Native for iOS | Drifting Ruby


# layouts/utility.html.erb

<!DOCTYPE html>
<html>
  <head>
    <title>Template</title>
    <meta identify="viewport" content material="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag 'utility', media: 'all' %>
  </head>
  <physique>
    <div class="container">
      <% except cell? %>
        <%= link_to "Residence", root_path %>
        <%= link_to "Posts", posts_path %>
      <% finish %>
      <%= yield %>
    </div>
  </physique>
</html>
# application_helper.rb

module ApplicationHelper
  def cell?
    request.user_agent.embody?('DriftingRubyiOS')
  finish
finish
# config/improvement.rb

config.hosts = nil
# swift bundle url
https://github.com/hotwired/turbo-ios
# SceneDelegate.swift

import UIKit
import Turbo
import WebKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    personal lazy var navigationController = ViewController()
    let viewController = WebViewController()

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices connectionOptions: UIScene.ConnectionOptions) {
        guard let _ = (scene as? UIWindowScene) else { return }
        window!.rootViewController = navigationController
        navigationController.tabBar.delegate = self
        navigationController.pushViewController(viewController, animated: true)
        go to(url: URL(string: "https://35546c597679.ngrok.io")!)
    }
    
    personal func go to(url: URL) {
        viewController.visitableURL = url
        session.go to(viewController)
    }
    
    personal lazy var session: Session = {
        let configuration = WKWebViewConfiguration()
        configuration.applicationNameForUserAgent = "DriftingRubyiOS"
        
        let session = Session(webViewConfiguration: configuration)
        session.delegate = self
        return session
    }()

    func sceneDidDisconnect(_ scene: UIScene) {
        // Known as because the scene is being launched by the system.
        // This happens shortly after the scene enters the background, or when its session is discarded.
        // Launch any assets related to this scene that may be re-created the subsequent time the scene connects.
        // The scene could re-connect later, as its session was not essentially discarded (see `utility:didDiscardSceneSessions` as an alternative).
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
        // Known as when the scene has moved from an inactive state to an energetic state.
        // Use this technique to restart any duties that had been paused (or not but began) when the scene was inactive.
    }

    func sceneWillResignActive(_ scene: UIScene) {
        // Known as when the scene will transfer from an energetic state to an inactive state.
        // This may increasingly happen as a result of non permanent interruptions (ex. an incoming cellphone name).
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
        // Known as because the scene transitions from the background to the foreground.
        // Use this technique to undo the adjustments made on coming into the background.
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
        // Known as because the scene transitions from the foreground to the background.
        // Use this technique to avoid wasting information, launch shared assets, and retailer sufficient scene-specific state data
        // to revive the scene again to its present state.
    }


}

extension SceneDelegate: SessionDelegate {
    func session(_ session: Session, didProposeVisit proposal: VisitProposal) {
        go to(url: proposal.url)
    }
    
    func session(_ session: Session, didFailRequestForVisitable visitable: Visitable, error: Error) {
        print("didFailRequestForVisitable: (error)")
    }
}

extension SceneDelegate: UITabBarDelegate {
    func tabBar(_ tabBar: UITabBar, didSelect merchandise: UITabBarItem) {
        change(merchandise.tag) {
        case 0:
            house()
        case 1:
            go to(url: URL(string: "https://35546c597679.ngrok.io/posts")!)
        default:
            break
        }
    }
    
    func house() {
        go to(url: URL(string: "https://35546c597679.ngrok.io")!)
    }
}
# WebViewController.swift

import UIKit
import Turbo

class WebViewController: VisitableViewController {
    override func viewDidLoad() {
        tremendous.viewDidLoad()
    }
    
    override func visitableDidRender() {
        title = "Drifting Ruby"
    }
}
# ViewController.swift

import UIKit

class ViewController: UINavigationController, UITabBarDelegate {
    let tabBar = UITabBar()
    let itemHome = UITabBarItem(tabBarSystemItem: .favorites, tag: 0)
    let itemPosts = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 1)
    override func viewDidLoad() {
        tremendous.viewDidLoad()
        tabBar.body = CGRect(x: 0, y: self.view.body.peak - 75, width: self.view.body.width, peak: 49)
        tabBar.gadgets = [itemHome, itemPosts]
        self.view.addSubview(tabBar)
    }
}
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments