Skip to content

Instantly share code, notes, and snippets.

View TizianoCoroneo's full-sized avatar
👹
Playing type-level Sudoku

TizianoCoroneo TizianoCoroneo

👹
Playing type-level Sudoku
View GitHub Profile
@Amzd
Amzd / UIKitTabView.swift
Last active July 14, 2024 20:28
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