FlexColorPicker: Crash iOS15

I use a very simple color picker, just the default:

let colorPickerController = DefaultColorPickerViewController()
colorPickerController.delegate = self
colorPickerController.selectedColor = UIColor.init(hex: user.invoice_color_hex)
colorPickerController.navigationItem.title = "Settings_InvoiceLayout_HeadersColor".localized()
self.navigationController?.pushViewController(colorPickerController, animated: true)

It has always worked perfectly, until iOS15. It seems to crash on this line:

public var contentBounds: CGRect {
    layoutIfNeeded()
    return contentView.frame
}

//Previous functions before it arrived here

private func updateCornerRadius() {
    gradientBackgroundView.cornerRadius_ = contentBounds.height / 2
}
open override var bounds: CGRect {
    didSet {
        updateCornerRadius()
        updateThumbAndGradient(isInteractive: false)
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 19 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I didn’t have time to fully dive into it and I needed an update fast, so I fixed it using the ugliest code possible. I knew it was calling some methods over and over, probably a layoutIfNeeded() that automatically called something that then again called layoutIfNeeded(). So I just needed some booleans to only call these one time. I finally found 3 places where I needed to intervene. Here are the classes and the methods that got it working again for me. FYI, obviously this is not a correct fix and I will not submit a pull request for this. But this might help someone who is trying to fix it in a good way 😃

First class: AdjustedHitBoxColorControl

private var adjustedHitBoxControlAlreadySet = false
public var contentBounds: CGRect {
    #warning("Fix 1")
    if !adjustedHitBoxControlAlreadySet {
        adjustedHitBoxControlAlreadySet = true
        layoutIfNeeded()            
    }
    return contentView.frame
}

Second class: ColorPaletteControl

private var colorPaletteControlAlreadySet = false
open override var bounds: CGRect {
    didSet {
        if !colorPaletteControlAlreadySet {
            #warning("Fix 2")
            colorPaletteControlAlreadySet = true
            updatePaletteImagesAndThumb(isInteractive: false)
        }
    }
}

Third class: ColorSliderControl

private var colorSliderControlAlreadySet = false
open override var bounds: CGRect {
    didSet {
        #warning("Fix 3")
        if !colorSliderControlAlreadySet {
            colorSliderControlAlreadySet = true
            updateCornerRadius()
            updateThumbAndGradient(isInteractive: false)
        }
    }
}

This should be fixed in 1.4.4