Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Added

- Added `isSelectable` to `ApplyItemContentInfo`, reflecting whether the item's `selectionStyle` is interactive (`.tappable`, `.selectable`, or `.toggles`). `ItemContent` implementations can read this to represent themselves as interactive, for example by applying the `.button` accessibility trait so VoiceOver users know the item responds to taps.

### Removed

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ extension PresentationState
cell.openTrailingSwipeActions()
},
isReorderable: self.model.reordering != nil,
isSelectable: self.model.selectionStyle.isSelectable,
environment: environment
)

Expand Down
7 changes: 6 additions & 1 deletion ListableUI/Sources/Item/ItemContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,12 @@ public struct ApplyItemContentInfo
/// If the item can be reordered.
/// Use this property to determine if your `ItemContent` should display a reorder control.
public var isReorderable : Bool


/// If the item is selectable; that is, if its `selectionStyle` is `.tappable`, `.selectable`, or `.toggles`.
/// Use this property to determine if your `ItemContent` should represent itself as interactive, for example
/// by applying the `.button` accessibility trait so VoiceOver users know the item responds to taps.
public var isSelectable : Bool

/// The environment of the containing list.
/// See `ListEnvironment` for usage information.
public var environment : ListEnvironment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,58 @@ class PresentationState_ItemStateTests : XCTestCase
XCTAssertEqual(state.coordination.coordinator?.willDisplay_calls.count, 1)
XCTAssertEqual(state.coordination.coordinator?.didEndDisplay_calls.count, 1)
}

func test_applyTo_isSelectable()
{
XCTAssertEqual(appliedInfo(for: .tappable).isSelectable, true)
XCTAssertEqual(appliedInfo(for: .notSelectable).isSelectable, false)
}

/// Builds an `ItemState` for the given `selectionStyle`, applies it to a cell, and returns the `ApplyItemContentInfo` passed to the content.
private func appliedInfo(for selectionStyle : ItemSelectionStyle) -> ApplyItemContentInfo
{
var applied : ApplyItemContentInfo?

let item = Item(CapturingContent { applied = $0 }, selectionStyle: selectionStyle)

let state = PresentationState.ItemState(
with: item,
dependencies: ItemStateDependencies(
reorderingDelegate: ReorderingActionsDelegateMock(),
coordinatorDelegate: ItemContentCoordinatorDelegateMock(),
environmentProvider: { .empty }
),
updateCallbacks: UpdateCallbacks(.immediate, wantsAnimations: false),
performsContentCallbacks: true
)

state.applyTo(
cell: ItemCell<CapturingContent>(frame: .zero),
itemState: .init(isSelected: false, isHighlighted: false, isReordering: false),
reason: .willDisplay,
environment: .empty
)

return applied!
}
}


fileprivate struct CapturingContent : ItemContent
{
typealias ContentView = UIView

let onApply : (ApplyItemContentInfo) -> ()

var identifierValue : String { "" }

func isEquivalent(to other : CapturingContent) -> Bool { false }

func apply(to views : ItemContentViews<CapturingContent>, for reason : ApplyReason, with info : ApplyItemContentInfo) {
onApply(info)
}

static func createReusableContentView(frame : CGRect) -> UIView { UIView(frame: frame) }
}


Expand Down
Loading