Skip to content

Commit

Permalink
add user to UICollectionViewCompositionalLayout example
Browse files Browse the repository at this point in the history
Summary: Adding user cell

Differential Revision: D52260532

fbshipit-source-id: ec3f4f5a70d02e0c6db713ade51938413cb5ee8a
  • Loading branch information
Maxime Ollivier authored and facebook-github-bot committed Dec 19, 2023
1 parent 7fe78a8 commit 6117cda
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
576D200B2B2CC6DF0012C5B8 /* CompositionLayoutCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576D200A2B2CC6DF0012C5B8 /* CompositionLayoutCell.swift */; };
576D200E2B2CE9EC0012C5B8 /* ExpandableComposableSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576D200D2B2CE9EC0012C5B8 /* ExpandableComposableSectionController.swift */; };
576D20102B2CEC4E0012C5B8 /* GridComposableSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576D200F2B2CEC4E0012C5B8 /* GridComposableSectionController.swift */; };
576D20122B2CF04F0012C5B8 /* UserComposableSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576D20112B2CF04F0012C5B8 /* UserComposableSectionController.swift */; };
576D20142B2CF15C0012C5B8 /* GridItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576D20132B2CF15C0012C5B8 /* GridItem.swift */; };
821BC4B61DB8B3DC00172ED0 /* StoryboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4B51DB8B3DC00172ED0 /* StoryboardViewController.swift */; };
821BC4B81DB8B48300172ED0 /* StoryboardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4B71DB8B48300172ED0 /* StoryboardCell.swift */; };
Expand Down Expand Up @@ -242,6 +243,7 @@
576D200A2B2CC6DF0012C5B8 /* CompositionLayoutCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompositionLayoutCell.swift; sourceTree = "<group>"; };
576D200D2B2CE9EC0012C5B8 /* ExpandableComposableSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandableComposableSectionController.swift; sourceTree = "<group>"; };
576D200F2B2CEC4E0012C5B8 /* GridComposableSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridComposableSectionController.swift; sourceTree = "<group>"; };
576D20112B2CF04F0012C5B8 /* UserComposableSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserComposableSectionController.swift; sourceTree = "<group>"; };
576D20132B2CF15C0012C5B8 /* GridItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridItem.swift; sourceTree = "<group>"; };
821BC4B51DB8B3DC00172ED0 /* StoryboardViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardViewController.swift; sourceTree = "<group>"; };
821BC4B71DB8B48300172ED0 /* StoryboardCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -517,6 +519,7 @@
children = (
576D200D2B2CE9EC0012C5B8 /* ExpandableComposableSectionController.swift */,
576D200F2B2CEC4E0012C5B8 /* GridComposableSectionController.swift */,
576D20112B2CF04F0012C5B8 /* UserComposableSectionController.swift */,
);
path = "With Composable Layout";
sourceTree = "<group>";
Expand Down Expand Up @@ -873,6 +876,7 @@
EB0289A2202A11E0007E17D5 /* PersonModel.m in Sources */,
292658601E74A19F0041B56D /* DayViewModel.swift in Sources */,
2961B3AB1D68B0B5001C9451 /* DemosViewController.swift in Sources */,
576D20122B2CF04F0012C5B8 /* UserComposableSectionController.swift in Sources */,
296DD75D1DD21ADA00206780 /* SelectionModel.swift in Sources */,
29C6297D1DCFD8E5004A5BB1 /* FeedItem.swift in Sources */,
56C05B6C1E49B2E80026DB39 /* UserInfoCell.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import IGListKit
import UIKit

final class UserComposableSectionController: ListSectionController, CompositionLayoutCapable {

private var user: User?

override func sizeForItem(at index: Int) -> CGSize {
// Size handled by cell
return CGSizeZero
}

override func cellForItem(at index: Int) -> UICollectionViewCell {
let cell: DetailLabelCell = collectionContext.dequeueReusableCell(
for: self,
at: index
)
cell.title = user?.name
cell.detail = "@" + (user?.handle ?? "")
return cell
}

override func didUpdate(to object: Any) {
self.user = object as? User
}

// MARK: CompositionLayoutCapable

func collectionViewSectionLayout(layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? {
let config = UICollectionLayoutListConfiguration(appearance: .plain)
return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ final class CompositionLayoutViewController: UIViewController, ListAdapterDataSo
private let data: [Any] = [
"Maecenas faucibus mollis interdum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.",
GridItem(color: UIColor(red: 237 / 255.0, green: 73 / 255.0, blue: 86 / 255.0, alpha: 1), itemCount: 6),
User(pk: 2, name: "Ryan Olson", handle: "ryanolsonk"),
"Praesent commodo cursus magna, vel scelerisque nisl consectetur et.",
User(pk: 4, name: "Oliver Rickard", handle: "ocrickard"),
GridItem(color: UIColor(red: 56 / 255.0, green: 151 / 255.0, blue: 240 / 255.0, alpha: 1), itemCount: 5),
"Nullam quis risus eget urna mollis ornare vel eu leo. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.",
User(pk: 3, name: "Jesse Squires", handle: "jesse_squires"),
GridItem(color: UIColor(red: 112 / 255.0, green: 192 / 255.0, blue: 80 / 255.0, alpha: 1), itemCount: 3),
"Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
GridItem(color: UIColor(red: 163 / 255.0, green: 42 / 255.0, blue: 186 / 255.0, alpha: 1), itemCount: 7),
User(pk: 1, name: "Ryan Nystrom", handle: "_ryannystrom")
]

override func viewDidLoad() {
Expand Down Expand Up @@ -74,6 +78,8 @@ final class CompositionLayoutViewController: UIViewController, ListAdapterDataSo
return ExpandableComposableSectionController()
case is GridItem:
return GridComposableSectionController()
case is User:
return UserComposableSectionController()
default:
return ListSectionController()
}
Expand Down

0 comments on commit 6117cda

Please sign in to comment.