Skip to content

Commit

Permalink
undo me
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed May 29, 2024
1 parent 20fcfbc commit 21fcbe5
Show file tree
Hide file tree
Showing 25 changed files with 676 additions and 2,382 deletions.
48 changes: 11 additions & 37 deletions PlatformUI/PlatformUI/PlatformListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ open class PlatformListViewModel: PlatformViewModeling {
contentChanged?()
}
}
public var header: PlatformViewModel? {
didSet {
contentChanged?()
}
}

public var footer: PlatformViewModel? {
didSet {
contentChanged?()
}
}

public var placeholder: PlatformViewModel? {
didSet {
contentChanged?()
}
}


public var width: CGFloat? {
Expand All @@ -46,50 +29,40 @@ open class PlatformListViewModel: PlatformViewModeling {
}
}

open var header: PlatformViewModel? { nil }
open var footer: PlatformViewModel? { nil }
open var placeholder: PlatformViewModel? { nil }

// contentChanged is required because the list view model returns a ForEach struct
// which does not observe the content change. Caller should supply a contentChanged block
// that manually triggers the parent view model's objectWillChange.send()

public var contentChanged: (() -> Void)?

public init(items: [PlatformViewModel] = [],
header: PlatformViewModel? = nil,
placeholder: PlatformViewModel? = nil,
intraItemSeparator: Bool = true,
firstListItemTopSeparator: Bool = false,
lastListItemBottomSeparator: Bool = false,
contentChanged: (() -> Void)? = nil) {
self.items = items
self.header = header
self.placeholder = placeholder
self.intraItemSeparator = intraItemSeparator
self.firstListItemTopSeparator = firstListItemTopSeparator
self.lastListItemBottomSeparator = lastListItemBottomSeparator
self.contentChanged = contentChanged
}

open func createView(parentStyle: ThemeStyle = ThemeStyle.defaultStyle, styleKey: String? = nil) -> AnyView {
guard items.count > 0 else {
let cell = Group {
if let placeholder = self.placeholder {
placeholder.createView(parentStyle: parentStyle)
} else {
PlatformView.nilView
}
}
.frame(width: width)
return AnyView(cell)
}

let itemsOrPlaceholder = items.count > 0 ? items : [placeholder ?? .init(bodyBuilder: nil)]
let list: [PlatformViewModel]
if let header, let footer {
list = [header] + items + [footer]
list = [header] + itemsOrPlaceholder + [footer]
} else if let header {
list = [header] + items
list = [header] + itemsOrPlaceholder
} else if let footer {
list = items + [footer]
list = itemsOrPlaceholder + [footer]
} else {
list = items
list = itemsOrPlaceholder
}

return AnyView(
Expand All @@ -99,7 +72,8 @@ open class PlatformListViewModel: PlatformViewModeling {
let cell =
Group {
// render the item if it is a header or a footer and the index is first or last
if (item === list.first && self?.header != nil) || (item === list.last && self?.footer != nil) {
// or if items is empty (and placeholder is being displayed)
if (item === list.first && self?.header != nil) || (item === list.last && self?.footer != nil) || self?.items.isEmpty != false {
item.createView(parentStyle: parentStyle)
} else {
VStack(alignment: .leading, spacing: 0) {
Expand Down
1 change: 0 additions & 1 deletion dydx/PodFile
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ abstract_target 'iOS' do
project '../dydx/dydxAnalytics/dydxAnalytics'
firebase_core_pods
ios_util_pods
abacus_pods
end

target 'dydxPresenters' do
Expand Down
2 changes: 1 addition & 1 deletion dydx/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,6 @@ SPEC CHECKSUMS:
Validator: 80a6f567220c962dfd2d9928ae98a8c1d164f6f4
ZSWTappableLabel: 92f11d677bb395a8294df48482316c4981783ca0

PODFILE CHECKSUM: f1277090c844566f744195caf9d281564bb8957c
PODFILE CHECKSUM: 2a032d64e6c7c3b1839673950b828c8fa7caffa9

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion dydx/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 21fcbe5

Please sign in to comment.