layout icon indicating copy to clipboard operation
layout copied to clipboard

iOS 13, Xcode 11 infinite loop related to the swizzled layoutSubviews()

Open sebastienwindal opened this issue 4 years ago • 3 comments

We have a custom view and we overrode layoutSubviews() as recommended:

open override func layoutSubviews() {
        super.layoutSubviews()
        // Ensure layout is updated after screen rotation, etc
        self.layoutNode?.view.frame = self.bounds
        // Update frame to match layout
        self.frame.size = self.intrinsicContentSize
    }

and it would appear the app is stuck in some kind of infinite loop, our custom view layoutSubviews () and layout_layoutSubviews() being called forever and blocking the main thread

extension UIView {
    fileprivate static func _swizzle() {
        guard !viewSwizzled else { return }
        replace(#selector(layoutSubviews), of: self, with: #selector(layout_layoutSubviews))
        viewSwizzled = true
    }

    // Swizzled layoutSubviews implementation
    @objc private func layout_layoutSubviews() {
        layout_layoutSubviews()
        _layoutNode?.updateLayout()
    }
}

sebastienwindal avatar Sep 24 '19 00:09 sebastienwindal

Same here! Endless loop on iOS 13.1.1 with Layout. Just on loading the first VC using self.loadLayout() the app is running in endless loop.

Bildschirmfoto 2019-10-01 um 09 01 41

matape avatar Oct 01 '19 07:10 matape

@matape I got the same issue on 0.6.36. Updating to 0.6.38 fixed this issue.

comm1x avatar Oct 03 '19 23:10 comm1x

@sebastienwindal @matape can you provide a larger code sample? I'm having trouble reproducing the problem.

nicklockwood avatar Oct 04 '19 07:10 nicklockwood