Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import UIKit

extension UIView {
/// Returns a `separatorInset` for a table view or cell that is measured from the edges of the
/// view's safe area instead of the view's own edges.
///
/// Setting an explicit `separatorInset` replaces the inset UIKit picks by default, which keeps
/// the separator out of the side safe areas. Without this, the separator runs under the iPhone
/// Duo's side strip, or under the sensor housing in landscape.
///
/// A separator inset follows the layout direction (its `left` is the leading side), but safe
/// area insets don't, so they are swapped in right-to-left layouts.
public func separatorInsets(leading: CGFloat, trailing: CGFloat = 0) -> UIEdgeInsets {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: probably can add a note to say using NSDirectionalEdgeInsets once the app's min os is 26.

let isRightToLeft = effectiveUserInterfaceLayoutDirection == .rightToLeft
let leadingSafeArea = isRightToLeft ? safeAreaInsets.right : safeAreaInsets.left
let trailingSafeArea = isRightToLeft ? safeAreaInsets.left : safeAreaInsets.right
return UIEdgeInsets(top: 0, left: leading + leadingSafeArea, bottom: 0, right: trailing + trailingSafeArea)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Testing
import UIKit
import WordPressUI

@MainActor
struct UIViewSeparatorInsetsTests {
@Test func withoutSideSafeAreasTheInsetsAreUnchanged() {
let view = SafeAreaView(safeAreaInsets: .zero)

#expect(view.separatorInsets(leading: 68) == UIEdgeInsets(top: 0, left: 68, bottom: 0, right: 0))
}

@Test func leftToRightAddsEachSideSafeArea() {
let view = SafeAreaView(safeAreaInsets: UIEdgeInsets(top: 82, left: 10, bottom: 34, right: 84))

#expect(view.separatorInsets(leading: 68, trailing: 4) == UIEdgeInsets(top: 0, left: 78, bottom: 0, right: 88))
}

@Test func rightToLeftSwapsTheSafeAreaSides() {
let view = SafeAreaView(safeAreaInsets: UIEdgeInsets(top: 82, left: 10, bottom: 34, right: 84))
view.semanticContentAttribute = .forceRightToLeft

// The leading side is on the right, where the 84 pt inset is.
#expect(view.separatorInsets(leading: 68, trailing: 4) == UIEdgeInsets(top: 0, left: 152, bottom: 0, right: 14))
}
}

private final class SafeAreaView: UIView {
private let stubbedSafeAreaInsets: UIEdgeInsets

init(safeAreaInsets: UIEdgeInsets) {
self.stubbedSafeAreaInsets = safeAreaInsets
super.init(frame: CGRect(x: 0, y: 0, width: 466, height: 678))
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override var safeAreaInsets: UIEdgeInsets {
stubbedSafeAreaInsets
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ class NoteBlockHeaderTableViewCell: NoteBlockTableViewCell {

override func refreshSeparators() {
separatorsView.bottomVisible = true
separatorsView.bottomInsets = UIEdgeInsets.zero
separatorsView.bottomInsets = fullSeparatorInsets
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import WordPressShared

class NoteBlockTableViewCell: WPTableViewCell {

/// Represents the (full, side to side) Separator Insets
/// Represents the (full, side to side) Separator Insets. They stop at the safe area, so the
/// separator stays clear of the iPhone Duo's side strip and the sensor housing in landscape.
///
private let fullSeparatorInsets = UIEdgeInsets.zero
var fullSeparatorInsets: UIEdgeInsets {
UIEdgeInsets(top: 0, left: safeAreaInsets.left, bottom: 0, right: safeAreaInsets.right)
}

/// Indicates if the receiver represents a Badge Block
///
Expand Down
9 changes: 8 additions & 1 deletion WordPress/Classes/ViewRelated/People/Views/PeopleCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class PeopleCell: WPTableViewCell {
@IBOutlet private weak var superAdminRoleBadge: PeopleRoleBadgeLabel!
@IBOutlet private weak var badgeStackView: UIStackView!

private static let separatorLeadingInset: CGFloat = 72

override func awakeFromNib() {
super.awakeFromNib()

Expand All @@ -21,7 +23,12 @@ class PeopleCell: WPTableViewCell {
usernameLabel.textColor = .secondaryLabel
usernameLabel.font = WPStyleGuide.fontForTextStyle(.footnote)

separatorInset = UIEdgeInsets(top: 0, left: 72, bottom: 0, right: 0)
separatorInset = separatorInsets(leading: Self.separatorLeadingInset)
}

override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
separatorInset = separatorInsets(leading: Self.separatorLeadingInset)
}

override func prepareForReuse() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import WordPressUI

class ReaderStreamBaseCell: UITableViewCell {
static let insets = UIEdgeInsets(top: 0, left: 46, bottom: 0, right: 16)
Expand Down Expand Up @@ -35,7 +36,13 @@ class ReaderStreamBaseCell: UITableViewCell {
}

private func updateSeparatorsInsets() {
separatorInset = UIEdgeInsets(.leading, isSeparatorHidden ? 9999 : Self.insets.left + (isCompact ? 0 : contentView.readableContentGuide.layoutFrame.minX))
if isSeparatorHidden {
separatorInset = UIEdgeInsets(.leading, 9999)
} else {
separatorInset = separatorInsets(
leading: Self.insets.left + (isCompact ? 0 : contentView.readableContentGuide.layoutFrame.minX)
)
}
}

func didUpdateCompact(_ isCompact: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class ReaderSiteHeaderView: ReaderBaseHeaderView, ReaderStreamHeader {
addSubview(separatorView)
separatorView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
separatorView.leadingAnchor.constraint(equalTo: leadingAnchor),
separatorView.trailingAnchor.constraint(equalTo: trailingAnchor),
// Stop at the safe area, like the separators between posts.
separatorView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
separatorView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
separatorView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
separatorView.heightAnchor.constraint(equalToConstant: 1)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class ListTableViewCell: UITableViewCell, NibReusable {
@IBOutlet private weak var snippetLabel: UILabel!
@IBOutlet private weak var indicatorWidthConstraint: NSLayoutConstraint!

/// The separator's leading inset from the nib.
private var separatorLeadingInset: CGFloat = 0

/// Convenience property to retain the overlay view when shown on top of the cell.
/// The overlay can be shown or dismissed through `showOverlay` and `dismissOverlay` respectively.
private var overlayView: UIView?
Expand Down Expand Up @@ -78,9 +81,15 @@ public class ListTableViewCell: UITableViewCell, NibReusable {

public override func awakeFromNib() {
super.awakeFromNib()
separatorLeadingInset = separatorInset.left
configureSubviews()
}

public override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
separatorInset = separatorInsets(leading: separatorLeadingInset)
}

// MARK: Public Methods

/// Configures the avatar image view with the provided URL.
Expand Down