Tusker/Tusker/Extensions/NSCollectionLayoutSection+R...

46 lines
1.3 KiB
Swift

//
// NSCollectionLayoutSection+Readable.swift
// Tusker
//
// Created by Shadowfacts on 9/28/23.
// Copyright © 2023 Shadowfacts. All rights reserved.
//
import UIKit
extension NSCollectionLayoutSection {
// The .readableContent insets reference has a bunch of weird behavior,
// so just calculate the content inset ourselves.
func readableContentInset(in environment: NSCollectionLayoutEnvironment) {
let maxWidth: CGFloat
switch environment.traitCollection.preferredContentSizeCategory {
case .extraSmall:
maxWidth = 560
case .small:
maxWidth = 600
case .medium:
maxWidth = 632
case .large:
maxWidth = 664
case .extraLarge:
maxWidth = 744
case .extraExtraLarge:
maxWidth = 816
case .extraExtraExtraLarge:
maxWidth = 896
case .accessibilityMedium:
maxWidth = 1096
default:
// greater accessibility sizes don't have a limit
return
}
let inset = max(0, (environment.container.contentSize.width - maxWidth) / 2)
// make sure not to overwrite the vertical insets, which are non-zero for grouped styles
contentInsets.leading = inset
contentInsets.trailing = inset
}
}