scenee / FloatingPanel

A clean and easy-to-use floating panel UI component for iOS
MIT License
5.6k stars 510 forks source link

Wrong layout when rotating screen #515

Closed flowbe closed 2 years ago

flowbe commented 2 years ago

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)?

How many panels do you displays?

Environment

Library version

2.5.0

Installation method

iOS version(s)

15.0

Xcode version

13.1

flowbe commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

scenee commented 2 years ago

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

flowbe commented 2 years ago

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 commented 2 years ago

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