Skip to content
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

Deprecate backgroundView for backgroundViewProvider #123

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

scottybobandy
Copy link
Member

@scottybobandy scottybobandy commented Dec 10, 2018

Re-opening this as changes have been pushed to the old branch since stalebot killed the PR.

The backgroundView property on CellStyle is expensive - background views are created on every render pass, even though they are rarely used.

The BackgroundViewProvider allows CellStyle to request an optional background view when its being dequeued; the only time it's actually needed.

Fixes #105

self.layoutMargins = layoutMargins
self.cornerRadius = cornerRadius

struct DefaultBackgroundProvider: BackgroundViewProvider {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DefaultBackgroundProvider in the deprecated init simply wraps and returns the (optionally) provided backgroundView. So we'll still get the functionality in this case.

public init(topSeparator: Separator.Style? = nil,
bottomSeparator: Separator.Style? = nil,
separatorColor: UIColor? = nil,
highlight: Bool? = nil,
accessoryType: UITableViewCell.AccessoryType = .none,
selectionColor: UIColor? = CellStyle.defaultSelectionColor,
backgroundColor: UIColor? = CellStyle.defaultBackgroundColor,
backgroundView: UIView? = nil,
backgroundView: UIView?,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the default value here to avoid Ambiguous use of 'init'. This also means CellStyle initializers without an explicitly set backgroundView will default to the new implementation.

@scottybobandy scottybobandy requested review from dannbeau, raulriera, krbarnes and Caiopia and removed request for dannbeau December 10, 2018 19:12
Copy link
Contributor

@raulriera raulriera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, there is a small typo and I think we can get rid of

else {
 	let backgroundView = UIView()
 	backgroundView.backgroundColor = cell.backgroundColor
 	cell.backgroundView = backgroundView
 }

This seems to be completely new and probably unrelated to the current changes?

Don't forget the regenerate the documentation again? 😉

/// An implementation should maintain some internal state about the contents of the view.
public protocol BackgroundViewProvider {
/// This is where the background view should be instantiated, since this
/// function is only called when a cell is being prepared to be deqeueued.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo in the last word

@raulriera
Copy link
Contributor

The documentation should have been another PR 😬 sorry for not clarifying that

@scottybobandy
Copy link
Member Author

@raulriera No worries - i'll separate them 👍

equality = equality && lhs.tintColor == rhs.tintColor
equality = equality && lhs.layoutMargins == rhs.layoutMargins
equality = equality && lhs.cornerRadius == rhs.cornerRadius
equality = equality && lhs.backgroundViewProvider?.isEqualTo(rhs.backgroundViewProvider) ?? true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if lhs.backgroundViewProvider is nil and rhs.backgroundViewProvider is not?

Suggested change
equality = equality && lhs.backgroundViewProvider?.isEqualTo(rhs.backgroundViewProvider) ?? true
equality = equality && lhs.backgroundViewProvider?.isEqualTo(rhs.backgroundViewProvider) ?? ((lhs.backgroundViewProvider == nil) == (rhs.backgroundViewProvider == nil))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case it is sufficient to write the equality check as:

lhs.backgroundViewProvider?.isEqualTo(rhs.backgroundViewProvider) ?? (rhs.backgroundViewProvider == nil)

@scottybobandy scottybobandy merged commit 344fc1f into master Dec 12, 2018
@scottybobandy scottybobandy deleted the deprecate-background-view branch December 12, 2018 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants