Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes because of constraint issues between MBProgressHud and child custom view. #660

Open
albertB4work opened this issue May 13, 2024 · 0 comments

Comments

@albertB4work
Copy link

This is the crash reported in Firebase after several workaround tried

Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint:<NSLayoutConstraint:0x300183b10 RTSpinKitView:0x115da6480.centerX == MBBackgroundView:0x127179510.centerX (active)> view:<MBBackgroundView: 0x127179510; frame = (0 0; 0 0); clipsToBounds = YES; alpha = 0; animations = { opacity=<CASpringAnimation: 0x302693b00>; }; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x30267b720>>

This is the only class where the library is used, the only methods:

func showLoading() {
        if !isAnimating {
            isAnimating = true
            hud = MBProgressHUD.showAdded(to: self.view, animated: true)
            
            guard let spinner = spinner, let hud = hud else {
                // Make sure spinner and hud are not nil
                return
            }
            
            hud.bezelView.color = .clear
            hud.bezelView.style = .solidColor
            hud.isSquare = true
            hud.mode = .customView
            hud.removeFromSuperViewOnHide = true
            hud.customView = spinner
            
            // Make sure spinner is a subview of hud and hud has height and width
            guard spinner.isDescendant(of: hud), hud.frame.height > 0, hud.frame.width > 0 else {
                return
            }
            
            NSLayoutConstraint.activate([
                spinner.widthAnchor.constraint(equalToConstant: 50),
                spinner.heightAnchor.constraint(equalToConstant: 50),
                spinner.centerXAnchor.constraint(equalTo: hud.centerXAnchor),
                spinner.centerYAnchor.constraint(equalTo: hud.centerYAnchor),
            ])
            spinner.startAnimating()
        }
    }
    
    func dismissLoading() {
        isAnimating = false
        MBProgressHUD.hide(for: self.view, animated: true)
    }

Any other workaround to avoid these kind of crash? It's the more reported crash in Crashlytics. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant