uias / Tabman

ℒ️ A powerful paging view controller with interactive indicator bars
https://uias.github.io/Tabman
MIT License
2.84k stars 235 forks source link

SwiftUI NavigationBar Glitch #533

Closed otymartin closed 3 years ago

otymartin commented 4 years ago

Issue Description

@msaps I'm experiencing a weird NavigationBar Glitch. Since SwiftUI's TabView resets views when you navigate from them (iOS 13), I use Tabman and add my SwiftUI View's as ChildController with frame equal to the host view controllers frame. On initial launch, the First View's NavigationBar is laid out above the status bar but upon navigating to another Tab and coming back, the NavigationBar is properly laid out. Why is that, I can't trace the cause? I recreated the problem in this Example Project.

Other useful things

giphy

otymartin commented 4 years ago

Recreating this problem with a vanilla UIPageViewController subclass was giving the error Unbalanced calls to begin/end appearance transitions for UIViewController

Apparently the ChildViewControllers are being presented before the ParentViewController has been fully presented.

I solved this by delaying the loading of data source in viewDidLoad. Is there a better way Tabman can address this problem?

    override func viewDidLoad() {
        super.viewDidLoad()
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            self.loadViewControllers()
            self.addTabBar()
            self.dataSource = self
        }
    }
msaps commented 4 years ago

@otymartin hmm I'll take a look at the Example today and see if I can figure anything out...

Quick one though - have you ever thought about just using UIKit / UITabBarController for the tabs and then use SwiftUI for the VCs etc? In my experience the rough edges of SwiftUI are usually solved by interoperability with UIKit πŸ˜„

otymartin commented 4 years ago

Hi @msaps

I've actually never used UITabBarController in my life Tabman spoiled me in that regard. I also chose it due to the TabBar delegate giving me control when user selects a tab where i need to present a VC modally - i hear that requires extra work for UITabBar

msaps commented 4 years ago

@otymartin ah sorry I might have got confused here - you're using Tabman as the tab bar and then NavigationView etc within each child view controller (the tabs)?

otymartin commented 4 years ago

YesπŸ˜„

msaps commented 3 years ago

@otymartin the example project link seems to be broken! 😬

otymartin commented 3 years ago

@msaps Fixed! πŸ‘

msaps commented 3 years ago

@otymartin I've managed to do a workaround that seems to behave itself - by using UINavigationController rather than NavigationView. Seems to be something to do with wanting the TabmanViewController to ignore safe areas that causes it (otherwise it behaves).

Screenshot 2020-09-19 at 08 20 26

Little example project attached here (this is also iOS 14 / Xcode 12 so mileage with 13 might vary?).

TabmanNavigationView.zip

otymartin commented 3 years ago

@msaps I'm actually blown away right now. I didn't know UINavigationController could act as a stand-in for SwiftUI NavigationView. That you could even set it's title within SwiftUI 🀯 This is incredible thanks so much!!