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

usesSafeAreaLayoutGuideLeadingTrailing #174

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Expose `forceLayout` in `EpoxySwiftUIHostingView` for updating the hosting view size from outside.
- Added `CollectionViewConfiguration.usesSafeAreaLayoutGuideLeadingTrailingAnchors` to respect leading/trailing layoutGuide anchors which are needed for landscape orientation. Defaults to `false` and uses the view's `leadingAnchor` and `trailingAnchor`. When `true` it will use the view's `safeAreaLayoutGuide` `leadingAnchor` and `trailingAnchor`.

### Changed
- `AnyItemModel` now implements the `ErasedContentProviding` protocol.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public struct CollectionViewConfiguration {
public init(
usesBatchUpdatesForAllReloads: Bool = true,
usesCellPrefetching: Bool = true,
usesAccurateScrollToItem: Bool = true)
usesAccurateScrollToItem: Bool = true,
usesSafeAreaLayoutGuideLeadingTrailingAnchors: Bool = false)
{
self.usesBatchUpdatesForAllReloads = usesBatchUpdatesForAllReloads
self.usesCellPrefetching = usesCellPrefetching
self.usesAccurateScrollToItem = usesAccurateScrollToItem
self.usesSafeAreaLayoutGuideLeadingTrailingAnchors = usesSafeAreaLayoutGuideLeadingTrailingAnchors
}

// MARK: Public
Expand Down Expand Up @@ -66,4 +68,10 @@ public struct CollectionViewConfiguration {
///
/// - SeeAlso: `CollectionViewScrollToItemHelper`
public var usesAccurateScrollToItem: Bool

/// Respects leading and trailing safe areas from the `UILayoutGuide` when `true`. Helpful
/// for supporting landscape orientation so that content is not rendered in the notch area.
///
/// Defaults to `false`
public var usesSafeAreaLayoutGuideLeadingTrailingAnchors: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,17 @@ open class CollectionViewController: UIViewController {
view.addSubview(collectionView)
collectionView.layoutDelegate = self

let layoutGuide = view.safeAreaLayoutGuide
let useLayoutGuide = configuration.usesSafeAreaLayoutGuideLeadingTrailingAnchors
let leadingAnchor = useLayoutGuide ? layoutGuide.leadingAnchor : view.leadingAnchor
let trailingAnchor = useLayoutGuide ? layoutGuide.trailingAnchor : view.trailingAnchor

collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
])

if let sections = initialSections {
Expand Down
Loading