Skip to content

Instantly share code, notes, and snippets.

View ryanashcraft's full-sized avatar

Ryan Ashcraft ryanashcraft

View GitHub Profile
@ryanashcraft
ryanashcraft / UIKitTabView.swift
Created March 25, 2021 02:42 — forked from Amzd/UIKitTabView.swift
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem