-
-
Notifications
You must be signed in to change notification settings - Fork 298
Implement Unwrapped Cells for Improved Type Safety #1382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,10 @@ extension StatusSection { | |
| return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in | ||
| switch item { | ||
| case .feed(let feed): | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
| let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.feed(feed) | ||
| let contentConcealModel = StatusView.ContentConcealViewModel(status: feed.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.filterContext) | ||
| configure( | ||
|
|
@@ -53,15 +56,21 @@ extension StatusSection { | |
| ) | ||
| return cell | ||
| case .feedLoader(let feed): | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as! TimelineMiddleLoaderTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as? TimelineMiddleLoaderTableViewCell else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
| configure( | ||
| cell: cell, | ||
| feed: feed, | ||
| configuration: configuration | ||
| ) | ||
| return cell | ||
| case .status(let status): | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
| let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(status) | ||
| let contentConcealModel = StatusView.ContentConcealViewModel(status: status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.filterContext) | ||
| configure( | ||
|
|
@@ -82,11 +91,15 @@ extension StatusSection { | |
| ) | ||
| return cell | ||
| case .topLoader: | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
| cell.activityIndicatorView.startAnimating() | ||
| return cell | ||
| case .bottomLoader: | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
| cell.activityIndicatorView.startAnimating() | ||
| return cell | ||
| } | ||
|
|
@@ -109,7 +122,10 @@ extension StatusSection { | |
| ) -> UITableViewCell { | ||
| switch configuration.thread { | ||
| case .root(let threadContext): | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusThreadRootTableViewCell.self), for: indexPath) as! StatusThreadRootTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusThreadRootTableViewCell.self), for: indexPath) as? StatusThreadRootTableViewCell else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return UITableViewCell() | ||
| } | ||
| let contentConcealModel = StatusView.ContentConcealViewModel(status: threadContext.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: .thread) | ||
| StatusSection.configure( | ||
| tableView: tableView, | ||
|
|
@@ -120,7 +136,10 @@ extension StatusSection { | |
| return cell | ||
| case .reply(let threadContext), | ||
| .leaf(let threadContext): | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell | ||
| guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return UITableViewCell() | ||
| } | ||
| let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(threadContext.status) | ||
| let contentConcealModel = StatusView.ContentConcealViewModel(status: threadContext.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.configuration.filterContext) | ||
| assert(configuration.configuration.filterContext == .thread) | ||
|
|
@@ -147,12 +166,15 @@ extension StatusSection { | |
| return nil | ||
| case .option(let record): | ||
| // Fix cell reuse animation issue | ||
| let cell: PollOptionTableViewCell = { | ||
| guard let cell: PollOptionTableViewCell = { | ||
| let _cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PollOptionTableViewCell.self) + "@\(indexPath.row)#\(indexPath.section)") as? PollOptionTableViewCell | ||
| _cell?.prepareForReuse() | ||
| return _cell ?? PollOptionTableViewCell() | ||
| }() | ||
|
|
||
| }() else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
|
|
||
| cell.pollOptionView.viewModel.authenticationBox = authenticationBox | ||
|
|
||
| cell.pollOptionView.configure(pollOption: record) | ||
|
|
@@ -179,12 +201,15 @@ extension StatusSection { | |
| return nil | ||
| case let .history(option): | ||
| // Fix cell reuse animation issue | ||
| let cell: PollOptionTableViewCell = { | ||
| guard let cell: PollOptionTableViewCell = { | ||
| let _cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PollOptionTableViewCell.self) + "@\(indexPath.row)#\(indexPath.section)") as? PollOptionTableViewCell | ||
| _cell?.prepareForReuse() | ||
| return _cell ?? PollOptionTableViewCell() | ||
|
||
| }() | ||
|
|
||
| }() else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
|
|
||
| cell.pollOptionView.configure(historyPollOption: option) | ||
|
|
||
| return cell | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,10 @@ extension UITableViewDelegate where Self: DataSourceProvider & MediaPreviewableV | |
| indexPath: IndexPath, point: CGPoint | ||
| ) -> UIContextMenuConfiguration? { | ||
|
|
||
| guard let cell = tableView.cellForRow(at: indexPath) as? StatusViewContainerTableViewCell else { return nil } | ||
| guard let cell = tableView.cellForRow(at: indexPath) as? StatusViewContainerTableViewCell else { | ||
| assertionFailure("unexpected cell dequeued") | ||
| return nil | ||
| } | ||
|
|
||
| let mediaViews = cell.statusView.mediaGridContainerView.mediaViews | ||
|
|
||
|
|
@@ -218,6 +221,7 @@ extension UITableViewDelegate where Self: DataSourceProvider & MediaPreviewableV | |
| parameters.visiblePath = UIBezierPath(roundedRect: mediaView.bounds, cornerRadius: MediaView.cornerRadius) | ||
| return UITargetedPreview(view: mediaView, parameters: parameters) | ||
| } else { | ||
| assertionFailure("unexpected cell dequeued") | ||
|
||
| return nil | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block will never return
nil(if_cellisnil, it will create a newPollOptionTableViewCell()), so theelsewill never be reached. Best fix would be to remove the?? PollOptionTableViewCell(), so that the block can returnniland the newelsecan then be reached.