Code Monkey home page Code Monkey logo

Comments (7)

colinhumber avatar colinhumber commented on August 30, 2024

This could certainly be fixed in a custom StackViewCell subclass. Mostly curious if this is something that could be included in the base implementation without needed to implement a custom cell class.

from aloestackview.

colinhumber avatar colinhumber commented on August 30, 2024

Playing around with this some more, since the separator view and constraints are all private, fixing this in a custom cell subclass would require a bunch of messy code and workarounds.

from aloestackview.

colinhumber avatar colinhumber commented on August 30, 2024

I was able to get this sorted by responding to safeAreaInsetsDidChange in a custom AloeStackView subclass and adjusting each row's separator and row inset to adjust for the new safeAreaInsets.

Since this is likely a common issue in popovers on iOS 13, it would be awesome if this was built into the base class. Any feedback on this would be great and I'd be happy to work on a fix.

from aloestackview.

apang42 avatar apang42 commented on August 30, 2024

hey @colinhumber thanks for reporting this! We'll take a look at this - if you could share some of your code for a fix, we'll get back to you with a proposed solution for this issue.

from aloestackview.

colinhumber avatar colinhumber commented on August 30, 2024

Awesome!

This fixes it if the fix is directly within StackViewCell.

// this could be removed, since insetsLayoutMarginsFromSafeArea = false is the default 
if #available(iOS 11.0, *) {
  insetsLayoutMarginsFromSafeArea = true
}

private func setUpSeparatorViewConstraints() {
  if #available(iOS 11.0, *) {
    separatorTopConstraint = separatorView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
    separatorBottomConstraint = separatorView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
    separatorLeadingConstraint = separatorView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor)
    separatorTrailingConstraint = separatorView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor)
  } else {
    separatorTopConstraint = separatorView.topAnchor.constraint(equalTo: topAnchor)
    separatorBottomConstraint = separatorView.bottomAnchor.constraint(equalTo: bottomAnchor)
    separatorLeadingConstraint = separatorView.leadingAnchor.constraint(equalTo: leadingAnchor)
    separatorTrailingConstraint = separatorView.trailingAnchor.constraint(equalTo: trailingAnchor)

  }
}

Since the separator constraints are private, I wasn't able to fix it in a StackViewCell subclass, so I created an AloeStackView subclass to handle it instead. This fix assumes all rows are added upfront before any safeAreaInsets would change.

class SafeAreaAdjustingStackView: AloeStackView {
  @available(iOS 11.0, *)
  public override func safeAreaInsetsDidChange() {
    super.safeAreaInsetsDidChange()

    getAllRows().forEach {
      guard let cell = $0.superview as? StackViewCell else { return }

      // adjust separator inset for the new safe area
      let currentSeparatorInset = cell.separatorInset
      let adjustedSeparatorInset = UIEdgeInsets(top: currentSeparatorInset.top,
                                                left: currentSeparatorInset.left + safeAreaInsets.left,
                                                bottom: currentSeparatorInset.bottom,
                                                right: currentSeparatorInset.right + safeAreaInsets.right)
      setSeparatorInset(forRow: $0, inset: adjustedSeparatorInset)

      // adjust row inset for the new safe area
      let currentRowInset = cell.rowInset
      let adjustedRowInset = UIEdgeInsets(top: currentRowInset.top,
                                          left: currentRowInset.left + safeAreaInsets.left,
                                          bottom: currentRowInset.bottom,
                                          right: currentRowInset.right + safeAreaInsets.right)
      setInset(forRow: $0, inset: adjustedRowInset)
    }
  }
}

from aloestackview.

colinhumber avatar colinhumber commented on August 30, 2024

@apang42 Hey! Just wanted to follow up and see if there had been any internal discussions about this. Thanks!

from aloestackview.

colinhumber avatar colinhumber commented on August 30, 2024

Any updates on this fix?

from aloestackview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.