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

Wrong layout when rotating screen #515

Closed
flowbe opened this issue Nov 19, 2021 · 6 comments
Closed

Wrong layout when rotating screen #515

flowbe opened this issue Nov 19, 2021 · 6 comments

Comments

@flowbe
Copy link

flowbe commented Nov 19, 2021

Description

We recently transitioned one of our floating panels from a UITableView to a UICollectionView using compositional layouts. After transitioning, we noticed that when rotating the screen (portrait > landscape > portrait), our layout would keep the landscape size. We didn't have this issue before.

Before After 
Before After

We tried updating both the collection view layout and the panel layout in viewWillTransition but nothing works. Could this be a bug related to collection views?

Expected behavior

Update the layout width accordingly to the orientation.

Actual behavior

When switching from landscape to portrait, the landscape width is kept.

Steps to reproduce

Code example that reproduces the issue

Our collection view layout looks like this:

let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets = NSDirectionalEdgeInsets(top: 5, leading: 5, bottom: 5, trailing: 5)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(100))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: 2)
group.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15)
let section = NSCollectionLayoutSection(group: group)
let layout = UICollectionViewCompositionalLayout(section: section)

The complete code is available here.

How do you display panel(s)?

  • Add as child view controllers
  • Present modally

How many panels do you displays?

  • 1
  • 2+

Environment

Library version

2.5.0

Installation method

  • CocoaPods
  • Carthage
  • Swift Package Manager

iOS version(s)

15.0

Xcode version

13.1

@flowbe
Copy link
Author

flowbe commented Nov 22, 2021

After investigating, I noticed that the constraints on the content view are given a lower priority ($0.priority = .required - 1) which leads to this issue. When commenting the line, everything works fine. Why are you doing this?

@scenee
Copy link
Owner

scenee commented Nov 23, 2021

@flowbe Could you please let me know whether your panel'sFloatingPanelController.contentMode is .static or . fitToBounds? The reason why the priority was set to .required - 1 is #359, which fixed #294. However #294 was an issue on . fitToBounds content mode. So if your panel’s content mode is .static, I’d like to the priory will be set to .required on .static content mode.

@flowbe
Copy link
Author

flowbe commented Nov 23, 2021

Hi @scenee, we didn't change the contentMode variable so it is set to the default value, which is apparently .static

@scenee
Copy link
Owner

scenee commented Nov 24, 2021

@flowbe Thanks for your information. I will change the priority on .static content mode.

scenee added a commit that referenced this issue Nov 29, 2021
…nt mode (#519)

They were set to `.required - 1` is #359, which fixed #294. However #294
was an issue on `.fitToBounds` content mode. But because of #444 and #515,
if your panel’s content mode is `.static`, their priorities should be set to
`.required` on `.static` content mode.
@flowbe
Copy link
Author

flowbe commented Dec 2, 2021

Hi @scenee, I saw that you made a PR for this issue, thanks a lot! Can you create a new release so I can update my project?
Thanks a lot

@scenee
Copy link
Owner

scenee commented Dec 3, 2021

I've released v2.5.1 now 👍 Thanks for your support and patient.

@scenee scenee closed this as completed Dec 3, 2021
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

2 participants