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

Broken constraints when using custom view with UIStackView inside. #3

Open
denandreychuk opened this issue Oct 31, 2022 · 0 comments
Open

Comments

@denandreychuk
Copy link

Something wrong with UIStackView inside UIViewAdaptor, but I can't figure out what exactly. I tried to use different flexibility, idealSizeCalculator but still got this errors in console:

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x28241fed0 UIView:0x13dd10ce0.height == 100 (active)>",
"<NSLayoutConstraint:0x28241fb60 'UISV-alignment' UIView:0x13dd0ec50.bottom == UIView:0x13dd10ce0.bottom (active)>",
"<NSLayoutConstraint:0x28241fb10 'UISV-alignment' UIView:0x13dd0ec50.top == UIView:0x13dd10ce0.top (active)>",
"<NSLayoutConstraint:0x28241fc00 'UISV-canvas-connection' UIStackView:0x13dd10950.top == UIView:0x13dd0ec50.top (active)>",
"<NSLayoutConstraint:0x28241fbb0 'UISV-canvas-connection' V:[UIView:0x13dd0ec50]-(0)-| (active, names: '|':UIStackView:0x13dd10950 )>",
"<NSLayoutConstraint:0x28241f610 'UIView-Encapsulated-Layout-Height' UIStackView:0x13dd10950.height == 711 (active)>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x28241fed0 UIView:0x13dd10ce0.height == 100 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

var body: some View {
    VStack {
        UIViewAdaptor {
            let stack = UIStackView()
            
            let firstView = UIView()
            firstView.backgroundColor = .red
            
            let secondView = UIView()
            secondView.backgroundColor = .blue
            
            
            [firstView, secondView].forEach {
                $0.translatesAutoresizingMaskIntoConstraints = false
            }
        
            NSLayoutConstraint.activate([
                firstView.heightAnchor.constraint(equalToConstant: 100),
                secondView.heightAnchor.constraint(equalToConstant: 100)
            ])
            
            stack.addArrangedSubview(firstView)
            stack.addArrangedSubview(secondView)
            
            return stack
        }
        Spacer()
    }
}
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