IGListKit/Examples/Examples-iOS/IGListKitExamples/Models/PostModel.swift
Abhyas Mall 305a7bce0a Feed View Controller Demo and Improve UI Testing Infrastructure (#1629)
Summary:
## Changes in this pull request

This PR adds a new feed view controller demo to the IGListKit example app, showcasing how to implement a social media feed with IGListKit. The demo features infinite scrolling with pagination, post deletion, and interactive elements. Also, I've improved the UI testing infrastructure by adding helper methods for more reliable tests across different device types. The new helpers make the tests more resilient when dealing with iPad split views and ensure elements are properly visible before interacting with them.

### Checklist

- [X] All tests pass. Demo project builds and runs.
- [X] I added tests, an experiment, or detailed why my change isn't tested.
- [X] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/main/.github/CONTRIBUTING.md)

Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1629

Reviewed By: fabiomassimo

Differential Revision: D77482204

Pulled By: TimOliver

fbshipit-source-id: 44ac86ed253e8452388aad50a1ed05bc6f3a31ab
2025-12-10 17:18:43 +09:00

60 lines
2 KiB
Swift

/*
* 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 Post {
let id: String
let username: String
let userAvatarURL: URL?
let imageURL: URL?
let title: String
let description: String
let likes: Int
let timeStamp: Date
init(id: String, username: String, userAvatarURL: URL?, imageURL: URL?, title: String, description: String, likes: Int, timeStamp: Date) {
self.id = id
self.username = username
self.userAvatarURL = userAvatarURL
self.imageURL = imageURL
self.title = title
self.description = description
self.likes = likes
self.timeStamp = timeStamp
}
}
// MARK: - ListDiffable Implementation
// ListDiffable is the core protocol in IGListKit for data diffing
// It's similar to Equatable but with more specific requirements for efficient diffing
extension Post: ListDiffable {
// This method returns a unique identifier for the object
// IGListKit uses this to track objects across updates
// It should be unique and stable across updates (like a database ID)
func diffIdentifier() -> NSObjectProtocol {
return self.id as NSObjectProtocol
}
// This method compares all properties that might cause visual changes
// If this returns false for objects with the same diffIdentifier,
// IGListKit will reload that section instead of leaving it alone
func isEqual(toDiffableObject object: (any ListDiffable)?) -> Bool {
guard let object = object as? Post else { return false }
return self.id == object.id &&
self.username == object.username &&
self.userAvatarURL == object.userAvatarURL &&
self.imageURL == object.imageURL &&
self.title == object.title &&
self.description == object.description &&
self.likes == object.likes
}
}