Skip to content

Upgrade Hotwire Native from 1.1.3 to 1.2.0 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/hotwired/hotwire-native-ios",
"state" : {
"revision" : "56196ac91a63a619ef13e8d2c135b6346b541192",
"version" : "1.1.3"
"revision" : "f18b87938f55cbe8976e96702b5512fa9afcd674",
"version" : "1.2.0"
}
},
{
Expand Down
67 changes: 22 additions & 45 deletions RubyEvents/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,91 +11,68 @@ import UIKit

class App {
static var instance = App()

var isTabbed: Bool = true

var sceneDelegate: SceneDelegate?

lazy var navigator = Navigator(delegate: self)
lazy var tabBarController = TabBarController(app: self)

var navigators: [Navigator] {
if isTabbed {
return tabBarController.navigators
}
return [navigator]
}

var viewControllers: [UIViewController] {
navigators.map(\.rootViewController)
}

lazy var tabBarController = HotwireTabBarController(navigatorDelegate: self)

var window: UIWindow? {
sceneDelegate?.window
}

var isDebug: Bool {
#if DEBUG
return true
#else
return false
#endif
}

var isTestFlight: Bool {
Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
}

var environment: Environment {
if isDebug {
return .development
}

if isTestFlight {
return .staging
}

return .production
}

func start(sceneDelegate: SceneDelegate) {
self.sceneDelegate = sceneDelegate
self.tabBarController.setupTabs()

switchToTabController()
window?.rootViewController = tabBarController
Appearance.configure()
tabBarController.load(HotwireTab.all)
}

func switchToNavigationController() {
sceneDelegate?.window?.rootViewController = navigator.rootViewController
self.isTabbed = false

func hideNavigationBar() {
tabBarController.activeNavigator.rootViewController.navigationBar.isHidden = true
}

func switchToTabController() {
sceneDelegate?.window?.rootViewController = tabBarController
self.isTabbed = true
}

func navigatorFor(title: String) -> Navigator? {
tabBarController.navigatorFor(title: title)

func showNavigationBar() {
tabBarController.activeNavigator.rootViewController.navigationBar.isHidden = false
}
}

extension App: NavigatorDelegate {
func handle(proposal: VisitProposal) -> ProposalResult {
func handle(proposal: VisitProposal, from navigator: Navigator) -> ProposalResult {
switch proposal.viewController {
case "home":
let viewController = UIHostingController(
rootView: HomeView(
navigator: App.instance.navigatorFor(title: "Home")
navigator: tabBarController.activeNavigator
)
)

App.instance.tabBarController.hideNavigationBarFor(title: "Home")

hideNavigationBar()
return .acceptCustom(viewController)
default:
App.instance.tabBarController.showNavigationBarFor(title: "Home")

showNavigationBar()
return .accept
}
}
Expand Down
2 changes: 1 addition & 1 deletion RubyEvents/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let versionNumber = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
let uniqueDeviceId = UIDevice.current.identifierForVendor?.uuidString ?? ""

Hotwire.config.applicationUserAgentPrefix = "Hotwire Native iOS; app_version: \(versionNumber); unique_device_id: \(uniqueDeviceId);"
Hotwire.config.applicationUserAgentPrefix = "app_version: \(versionNumber); unique_device_id: \(uniqueDeviceId);"

Hotwire.registerBridgeComponents([
ButtonComponent.self
Expand Down
31 changes: 31 additions & 0 deletions RubyEvents/Appearance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UIKit

struct Appearance {
static func configure() {
configureNavigationBar()
configureTabBar()
}

private static func configureNavigationBar() {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithDefaultBackground()
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
UINavigationBar.appearance().isOpaque = false
UINavigationBar.appearance().isTranslucent = true
navigationBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.black]

}

private static func configureTabBar() {
let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.configureWithDefaultBackground()
tabBarAppearance.backgroundColor = UIColor.white
UITabBar.appearance().standardAppearance = tabBarAppearance
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
UITabBar.appearance().isOpaque = true
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().tintColor = .red
UITabBar.appearance().unselectedItemTintColor = .black
}
}
2 changes: 1 addition & 1 deletion RubyEvents/bridge/ButtonComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ButtonComponent: BridgeComponent {
}

private var viewController: UIViewController? {
delegate.destination as? UIViewController
delegate?.destination as? UIViewController
}

private func addButton(via message: Message, to viewController: UIViewController) {
Expand Down
2 changes: 1 addition & 1 deletion RubyEvents/bridge/LargeTitleComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class LargeTitleComponent: BridgeComponent {
}

private var viewController: UIViewController? {
delegate.destination as? UIViewController
delegate?.destination as? UIViewController
}

private func addTitle(via message: Message, to viewController: UIViewController) {
Expand Down
196 changes: 0 additions & 196 deletions RubyEvents/controllers/TabBarController.swift

This file was deleted.

Loading