xmartlabs / PagerTabStripView

🚀 Elegant Pager View fully written in pure SwiftUI.
MIT License
772 stars 88 forks source link

Crash with fullScreencover #86

Closed alinless closed 1 year ago

alinless commented 2 years ago

Describe the bug Swift runtime crash

To Reproduce Steps to reproduce the behavior:

  1. open fullScreenCover with pagerTabStropView
  2. try to close it from parent view.

I use optional views and with closing I destroy it. So it seems that it is a GeometryReader bug

**Screens

image
cecipirotto commented 2 years ago

Hi, I tried to reproduce it and I couldn't. Could you please give us a minimal reproducible example?

iconico-us commented 2 years ago

For what it's worth, I was able to avoid the crash by commenting out this style line:

struct LocationsLanding: View {

var body: some View {
    VStack {
        PagerTabStripView() {
            LocationsMap()
                .pagerTabItem {
                    TitleNavBarItem(title: "Map")
                }

            LocationsList()
                .pagerTabItem {
                    TitleNavBarItem(title: "List")
                }
        }
        //.pagerTabStripViewStyle(.barButton(indicatorBarColor: .gray, tabItemSpacing: 0, tabItemHeight: 50))
    }
Macrid commented 2 years ago

import SwiftUI

struct PagerTabItemModifier<NavTabView: View> : ViewModifier {

    private var navTabView: () -> NavTabView

    init(navTabView: @escaping () -> NavTabView) {
        self.navTabView = navTabView
    }

    func body(content: Content) -> some View {
        GeometryReader { reader in
            content
                .onAppear {
                    DispatchQueue.main.async {
                        let frame = reader.frame(in: .named("PagerViewScrollView"))
                        if (!frame.equalTo(CGRect(x: 0, y: 0, width: 0, height: 0))){
                            index = Int(round(frame.minX / frame.width))
                        }
                        let tabView = navTabView()
                        let tabViewDelegate = tabView as? PagerTabViewDelegate
                        dataStore.setView(AnyView(tabView), at: index)
                        dataStore.setTabViewDelegate(tabViewDelegate, at: index)
                    }
                }.onDisappear {
                    dataStore.items[index]?.tabViewDelegate?.setState(state: .normal)
                    dataStore.remove(at: index)
                }
        }
    }

    @EnvironmentObject private var dataStore: DataStore
    @EnvironmentObject private var settings: PagerSettings
    @State private var index = -1
}

Had the same issue so made a quickfix that worked for me.

tinblanc91 commented 1 year ago

I had same issue

cecipirotto commented 1 year ago

Hi, I couldn't reproduce it in version 4.0.0. If it's still happening on this version, please reopen the issue.