Mijick / Popups

Popups, popovers, sheets, alerts, toasts, banners, (...) presentation made simple. Written with and for SwiftUI.
Apache License 2.0
1.38k stars 59 forks source link

[BUG] Still Crashes on 4.0.0 pre iOS 17 #162

Open bukira opened 5 days ago

bukira commented 5 days ago

Updated to 3.0.0 and 4.0.0 and the popup still crashes for iOS 16 and below

iOS 17 and iOS 18 work fine

// MARK: Popup Height
extension ViewModel {
    func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async {
        guard activePopupProperties.gestureTranslation == 0 else { return }

        let newHeight = await calculatePopupHeight(heightCandidate, popup)
        if newHeight != popup.height {
            await updatePopupAction(popup.updatedHeight(newHeight))
        }
    }
}

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

crashes on the line: await updatePopupAction(popup.updatedHeight(newHeight))

for centre and bottom popups

Printing description of newHeight: 0.0 Printing description of heightCandidate: 319.0 Printing description of popup.height: nil

Same popus didnt crash pre 3.0.0

FulcrumOne commented 5 days ago

Hey @bukira,

Thanks for letting me know. Could you please show me the part of the code where you call the .registerPopups() method, as a similar issue was recently created (#158) and I wonder if this is somehow related.

Thanks again for your help, Tomasz

bukira commented 5 days ago

Yes certainly

 var body: some Scene {
        WindowGroup {
            RootView()
                .registerPopups()
                .logRender("RootView")
        }
        .onChange(of: phase) { newPhase in
            switch newPhase {
            case .active:
                activePhase() //App became active
            case .inactive:
                inactivePhase() //App became inactive
            case .background:
                backgroundPhase() //App is running in the background no UI
            @unknown default: break
                //Fallback for future cases
            }
        }
    }
@main
struct App: App {

    @Environment(\.scenePhase) private var phase

    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    init() {
        setupFirebase()
        setupConfig()
        setupDependencies()
        setupAppearance()
        setupPageControl()
    }

    var body: some Scene {
        WindowGroup {
            RootView()
                .registerPopups()
                .logRender("RootView")
        }
        .onChange(of: phase) { newPhase in
            switch newPhase {
            case .active:
                activePhase() //App became active
            case .inactive:
                inactivePhase() //App became inactive
            case .background:
                backgroundPhase() //App is running in the background no UI
            @unknown default: break
                //Fallback for future cases
            }
        }
    }
}
FulcrumOne commented 5 days ago

@bukira, could you, for testing purposes comment out @Environment(`.scenePhase) private var phase and see if the crash still occurs? If not, I think I know how I can fix it

bukira commented 5 days ago

doesnt crash with that commented out

FulcrumOne commented 5 days ago

Great. I mean not great, but at least I know how to fix it. I will provide you with a solution in a moment.

bukira commented 5 days ago

awesome and yeah great if we know the cause and super awesome for such a quick response :-)

FulcrumOne commented 5 days ago

Could you check if the patch-4.0.1 branch solves your problem?

bukira commented 5 days ago

Your the man, that fixed it cheers

FulcrumOne commented 5 days ago

Haha, glad to hear that. Unfortunately, I'll have to do some additional testing before this goes public, as there were reasons why I wanted to avoid such a solution 😅

Have a nice day @bukira!

wwzzyying commented 1 day ago
image

Hi FulcrumOne, I also got this crash with iOS17, my registerPopups just like this.

image
FulcrumOne commented 1 day ago

Hey,

Did you try that branch? Thanks

wwzzyying commented 23 hours ago

I just tried it, and it really doesn't crash.