Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

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

@denandreychuk

Description

@denandreychuk

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()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions