Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

3 Layout constraint warnings with recommended mitigations #262

Open
alexbbrown opened this issue Nov 27, 2022 · 1 comment
Open

3 Layout constraint warnings with recommended mitigations #262

alexbbrown opened this issue Nov 27, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@alexbbrown
Copy link

alexbbrown commented Nov 27, 2022

Describe the bug
When developing Metatext, very frequent layout warnings appear in console.

2022-11-27 11:41:31.469415-0800 Metatext[82387:3629457] [LayoutConstraints] Unable to simultaneously satisfy constraints.

these might have performance consequences.

To Reproduce
Steps to reproduce the behavior:

  1. download Metatext from this repo
  2. open in Xcode.
  3. adjust signing and capabilities so it can be run on device
  4. run on device
  5. observe messages in log
  6. set breakpoint on UIViewAlertForUnsatisfiableConstraints

Expected behavior

normal execution should not encounter layout issues.

Issue 1

the
breakpoint is hit on this call to shareButton.accessibilityLabel, oddly.

// StatusView.swift

 if shareButton.isEnabled {
            actions.append(UIAccessibilityCustomAction(
                name: shareButton.accessibilityLabel ?? "") { _ in
                viewModel.shareStatus()

                return true
            })
        }

it's unclear why accessibilityLabel: String would cause a layout, but it does.

suggest: replace this (and all other reads of accessibilityLabel) with a direct reference to the underlying string. This is obvious for reblog and reply, but share label comes from outside

Issue 2
too many constraints cause conflict

this error

2022-11-27 11:41:31.469415-0800 Metatext[82387:3629457] [LayoutConstraints] Unable to simultaneously satisfy constraints.

is caused in this code by temporarily having two constraints that conflict

    func hideNewItemsView() {
        UIView.animate(withDuration: .zeroIfReduceMotion(.defaultAnimationDuration)) {
            self.newItemsView.alpha = 0
            self.newItemsViewHiddenConstraint?.isActive = true // Here
            self.newItemsViewVisibleConstraint?.isActive = false // switch these calls
            self.view.layoutIfNeeded()
        } completion: { _ in
            self.reloadVisibleItems()
        }
    }

resolution: invert the order - deactivate the visible first, then activate the hidden one. This removes the conflict.

(please complete the following information):

  • Device: iPhone 12
  • OS: [e.g. iOS 16.2
  • App Version: b42dd28

issue 3

AccountHeaderView adds 1 new conflicting constraint each time it is laid out, resulting in 9 or 10 by the time I stopped counting.

    override func layoutSubviews() {
        super.layoutSubviews()

        if let pointSize = followingButton.titleLabel?.font.pointSize {

            relationshipButtonsStackView.heightAnchor
                .constraint(equalToConstant: pointSize + .defaultSpacing * 2).isActive = true

This logic should probably be moved, or replace with something like the following pseudoCode

         if let pointSize = followingButton.titleLabel?.font.pointSize {
             if let existingConstraint = constraints.first(where: { $0.identifier == "HA1" }) {
                 constraints.isActive = false
            }
             let newConstraint  = constraint(equalToConstant )
             newConstraint.identifier = "HA1"
             newConstraint.isActive = true

Additional context

other log message that are concerning

2022-11-27 11:28:01.013949-0800 Metatext[] [AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:82216 (
2022-11-27 11:28:00.481973-0800 Metatext[] [Application] -[UIApplication _touchesEvent] will no longer work as expected. Please stop using it.
Thread Performance Checker: Thread running at QOS_CLASS_USER_INITIATED waiting on a thread without a QoS class specified. Investigate ways to avoid priority inversions. Set environment variable 'PERFC_LOG_BACKTRACE_TO_STDERR' to 1 to see backtrace
2022-11-27 12:03:24.027885-0800 Metatext[] [TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at
@alexbbrown
Copy link
Author

Note: this change is really just personal vanity on my part and annoyance at having the console full of nonsense while debugging.

I don't actually know anything about NSLayout, I abandoned it for SwiftUI years ago.

@alexbbrown alexbbrown changed the title 2 Layout constraint warnings 2 Layout constraint warnings with recommended mitigations Nov 27, 2022
@jzzocc jzzocc added the bug Something isn't working label Nov 27, 2022
@alexbbrown alexbbrown changed the title 2 Layout constraint warnings with recommended mitigations 3 Layout constraint warnings with recommended mitigations Nov 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants