Chore/variable accessibility, close #618

Summary:
Issue fixed: #618

- [ ] All tests pass. Demo project builds and runs.
- [ ] I added tests, an experiment, or detailed why my change isn't tested.
- [ ] 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/master/.github/CONTRIBUTING.md)
Closes https://github.com/Instagram/IGListKit/pull/637

Differential Revision: D4869624

Pulled By: jessesquires

fbshipit-source-id: a9d5623dbb7a032691f3af5a2abf61adc3a42cd0
This commit is contained in:
heshamsalman
2017-04-11 13:20:56 -07:00
committed by Facebook Github Bot
parent c49511fb4f
commit 6758355f0c
30 changed files with 186 additions and 54 deletions

View File

@@ -49,7 +49,7 @@ extension DemoItem: IGListDiffable {
final class DemoSectionController: IGListSectionController, IGListSectionType {
var object: DemoItem?
private var object: DemoItem?
func numberOfItems() -> Int {
return 1
@@ -61,7 +61,7 @@ final class DemoSectionController: IGListSectionController, IGListSectionType {
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
cell.label.text = object?.name
cell.text = object?.name
return cell
}

View File

@@ -34,7 +34,7 @@ final class DisplaySectionController: IGListSectionController, IGListSectionType
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
let section = collectionContext!.section(for: self)
cell.label.text = "Section \(section), cell \(index)"
cell.text = "Section \(section), cell \(index)"
return cell
}

View File

@@ -17,7 +17,7 @@ import IGListKit
final class EmbeddedSectionController: IGListSectionController, IGListSectionType {
var number: Int?
private var number: Int?
override init() {
super.init()
@@ -36,7 +36,7 @@ final class EmbeddedSectionController: IGListSectionController, IGListSectionTyp
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: CenterLabelCell.self, for: self, at: index) as! CenterLabelCell
let value = number ?? 0
cell.label.text = "\(value + 1)"
cell.text = "\(value + 1)"
cell.backgroundColor = UIColor(red: 237/255.0, green: 73/255.0, blue: 86/255.0, alpha: 1)
return cell
}

View File

@@ -17,8 +17,8 @@ import IGListKit
final class ExpandableSectionController: IGListSectionController, IGListSectionType {
var expanded = false
var object: String?
private var expanded = false
private var object: String?
func numberOfItems() -> Int {
return 1
@@ -32,7 +32,7 @@ final class ExpandableSectionController: IGListSectionController, IGListSectionT
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
cell.label.text = object
cell.text = object
return cell
}

View File

@@ -16,7 +16,7 @@ import IGListKit
final class FeedItemSectionController: IGListSectionController, IGListSectionType, IGListSupplementaryViewSource {
var feedItem: FeedItem!
private var feedItem: FeedItem!
override init() {
super.init()
@@ -35,7 +35,7 @@ final class FeedItemSectionController: IGListSectionController, IGListSectionTyp
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext?.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
cell.label.text = feedItem.comments[index]
cell.text = feedItem.comments[index]
return cell
}
@@ -57,8 +57,8 @@ final class FeedItemSectionController: IGListSectionController, IGListSectionTyp
nibName: "UserHeaderView",
bundle: nil,
at: index) as! UserHeaderView
view.handleLabel.text = "@" + feedItem.user.handle
view.nameLabel.text = feedItem.user.name
view.handle = "@" + feedItem.user.handle
view.name = feedItem.user.name
return view
}

View File

@@ -41,7 +41,7 @@ extension GridItem: IGListDiffable {
final class GridSectionController: IGListSectionController, IGListSectionType {
var object: GridItem?
private var object: GridItem?
override init() {
super.init()
@@ -61,7 +61,7 @@ final class GridSectionController: IGListSectionController, IGListSectionType {
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: CenterLabelCell.self, for: self, at: index) as! CenterLabelCell
cell.label.text = "\(index + 1)"
cell.text = "\(index + 1)"
cell.backgroundColor = object?.color
return cell
}

View File

@@ -17,7 +17,7 @@ import IGListKit
final class HorizontalSectionController: IGListSectionController, IGListSectionType, IGListAdapterDataSource {
var number: Int?
private var number: Int?
lazy var adapter: IGListAdapter = {
let adapter = IGListAdapter(updater: IGListAdapterUpdater(),

View File

@@ -17,7 +17,7 @@ import IGListKit
final class LabelSectionController: IGListSectionController, IGListSectionType {
var object: String?
private var object: String?
func numberOfItems() -> Int {
return 1
@@ -29,7 +29,7 @@ final class LabelSectionController: IGListSectionController, IGListSectionType {
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
cell.label.text = object
cell.text = object
return cell
}

View File

@@ -16,7 +16,7 @@ import IGListKit
final class ListeningSectionController: IGListSectionController, IGListSectionType, IncrementListener {
var value: Int = 0
private var value: Int = 0
init(announcer: IncrementAnnouncer) {
super.init()
@@ -25,7 +25,7 @@ final class ListeningSectionController: IGListSectionController, IGListSectionTy
func configureCell(cell: LabelCell) {
let section = collectionContext!.section(for: self)
cell.label.text = "Section: \(section), value: \(value)"
cell.text = "Section: \(section), value: \(value)"
}
// MARK: IGListSectionType

View File

@@ -17,7 +17,7 @@ import IGListKit
final class MonthSectionController: IGListBindingSectionController<IGListDiffable>, IGListBindingSectionControllerDataSource, IGListBindingSectionControllerSelectionDelegate {
var selectedDay: Int = -1
private var selectedDay: Int = -1
override init() {
super.init()

View File

@@ -21,7 +21,7 @@ protocol RemoveSectionControllerDelegate: class {
final class RemoveSectionController: IGListSectionController, IGListSectionType, RemoveCellDelegate {
weak var delegate: RemoveSectionControllerDelegate?
var number: Int?
private var number: Int?
override init() {
super.init()
@@ -38,7 +38,7 @@ final class RemoveSectionController: IGListSectionController, IGListSectionType,
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext?.dequeueReusableCell(of: RemoveCell.self, for: self, at: index) as! RemoveCell
cell.label.text = "Cell: \((number ?? 0) + 1)"
cell.text = "Cell: \((number ?? 0) + 1)"
cell.delegate = self
return cell
}

View File

@@ -17,7 +17,7 @@ import IGListKit
final class SelfSizingSectionController: IGListSectionController, IGListSectionType {
var model: SelectionModel!
private var model: SelectionModel!
override init() {
super.init()
@@ -40,11 +40,11 @@ final class SelfSizingSectionController: IGListSectionController, IGListSectionT
switch model.type {
case .none:
let manualCell = collectionContext!.dequeueReusableCell(of: ManuallySelfSizingCell.self, for: self, at: index) as! ManuallySelfSizingCell
manualCell.label.text = text
manualCell.text = text
cell = manualCell
case .fullWidth:
let manualCell = collectionContext!.dequeueReusableCell(of: FullWidthSelfSizingCell.self, for: self, at: index) as! FullWidthSelfSizingCell
manualCell.label.text = text
manualCell.text = text
cell = manualCell
case .nib:
let nibCell = collectionContext!.dequeueReusableCell(withNibName: "NibSelfSizingCell", bundle: nil, for: self, at: index) as! NibSelfSizingCell

View File

@@ -21,7 +21,7 @@ protocol StoryboardLabelSectionControllerDelegate: class {
final class StoryboardLabelSectionController: IGListSectionController, IGListSectionType {
var object: Person?
private var object: Person?
weak var delegate: StoryboardLabelSectionControllerDelegate?
func numberOfItems() -> Int {
@@ -34,7 +34,7 @@ final class StoryboardLabelSectionController: IGListSectionController, IGListSec
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCellFromStoryboard(withIdentifier: "cell", for: self, at: index) as! StoryboardCell
cell.textLabel.text = object?.name
cell.text = object?.name
return cell
}

View File

@@ -17,7 +17,7 @@ import IGListKit
final class UserSectionController: IGListSectionController, IGListSectionType {
var user: User?
private var user: User?
func numberOfItems() -> Int {
return 1
@@ -29,8 +29,8 @@ final class UserSectionController: IGListSectionController, IGListSectionType {
func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: DetailLabelCell.self, for: self, at: index) as! DetailLabelCell
cell.titleLabel.text = user?.name
cell.detailLabel.text = "@" + (user?.handle ?? "")
cell.title = user?.name
cell.detail = "@" + (user?.handle ?? "")
return cell
}

View File

@@ -17,11 +17,11 @@ import IGListKit
final class WorkingRangeSectionController: IGListSectionController, IGListSectionType, IGListWorkingRangeDelegate {
var height: Int?
var downloadedImage: UIImage?
var task: URLSessionDataTask?
private var height: Int?
private var downloadedImage: UIImage?
private var task: URLSessionDataTask?
var urlString: String? {
private var urlString: String? {
guard let height = height,
let width = collectionContext?.containerSize.width
else { return nil }
@@ -51,7 +51,7 @@ final class WorkingRangeSectionController: IGListSectionController, IGListSectio
let cellClass: AnyClass = index == 0 ? LabelCell.self : ImageCell.self
let cell = collectionContext!.dequeueReusableCell(of: cellClass, for: self, at: index)
if let cell = cell as? LabelCell {
cell.label.text = urlString
cell.text = urlString
} else if let cell = cell as? ImageCell {
cell.setImage(image: downloadedImage)
}

View File

@@ -42,7 +42,7 @@ final class SingleSectionStoryboardViewController: UIViewController, IGListAdapt
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
let configureBlock = { (item: Any, cell: UICollectionViewCell) in
guard let cell = cell as? StoryboardCell, let number = item as? Int else { return }
cell.textLabel.text = "Cell: \(number + 1)"
cell.text = "Cell: \(number + 1)"
}
let sizeBlock = { (item: Any, context: IGListCollectionContext?) -> CGSize in
guard let context = context else { return .zero }

View File

@@ -49,7 +49,7 @@ final class SingleSectionViewController: UIViewController, IGListAdapterDataSour
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
let configureBlock = { (item: Any, cell: UICollectionViewCell) in
guard let cell = cell as? NibCell, let number = item as? Int else { return }
cell.textLabel.text = "Cell: \(number + 1)"
cell.text = "Cell: \(number + 1)"
}
let sizeBlock = { (item: Any, context: IGListCollectionContext?) -> CGSize in

View File

@@ -50,7 +50,7 @@ final class StackedViewController: UIViewController, IGListAdapterDataSource {
WorkingRangeSectionController(),
DisplaySectionController(),
HorizontalSectionController(),
])!
])
sectionController.inset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
return sectionController
}

View File

@@ -17,7 +17,7 @@ import IGListKit
final class CalendarDayCell: UICollectionViewCell {
lazy var label: UILabel = {
lazy fileprivate var label: UILabel = {
let view = UILabel()
view.backgroundColor = .clear
view.textAlignment = .center
@@ -29,7 +29,7 @@ final class CalendarDayCell: UICollectionViewCell {
return view
}()
lazy var dotsLabel: UILabel = {
lazy fileprivate var dotsLabel: UILabel = {
let view = UILabel()
view.backgroundColor = .clear
view.textAlignment = .center
@@ -38,7 +38,25 @@ final class CalendarDayCell: UICollectionViewCell {
self.contentView.addSubview(view)
return view
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
var dots: String? {
get {
return dotsLabel.text
}
set {
dotsLabel.text = newValue
}
}
override func layoutSubviews() {
super.layoutSubviews()
let bounds = contentView.bounds
@@ -47,7 +65,7 @@ final class CalendarDayCell: UICollectionViewCell {
label.layer.cornerRadius = half
dotsLabel.frame = CGRect(x: 0, y: half - 10, width: bounds.width, height: half)
}
}
extension CalendarDayCell: IGListBindable {

View File

@@ -16,7 +16,7 @@ import UIKit
final class CenterLabelCell: UICollectionViewCell {
lazy var label: UILabel = {
lazy private var label: UILabel = {
let view = UILabel()
view.backgroundColor = .clear
view.textAlignment = .center
@@ -26,6 +26,15 @@ final class CenterLabelCell: UICollectionViewCell {
return view
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
override func layoutSubviews() {
super.layoutSubviews()
label.frame = contentView.bounds

View File

@@ -18,7 +18,7 @@ final class DetailLabelCell: UICollectionViewCell {
fileprivate let padding: CGFloat = 15.0
lazy var titleLabel: UILabel = {
lazy private var titleLabel: UILabel = {
let view = UILabel()
view.backgroundColor = .clear
view.textAlignment = .left
@@ -28,7 +28,7 @@ final class DetailLabelCell: UICollectionViewCell {
return view
}()
lazy var detailLabel: UILabel = {
lazy private var detailLabel: UILabel = {
let view = UILabel()
view.backgroundColor = .clear
view.textAlignment = .right
@@ -38,6 +38,25 @@ final class DetailLabelCell: UICollectionViewCell {
return view
}()
var title: String? {
get {
return titleLabel.text
}
set {
titleLabel.text = newValue
}
}
var detail: String? {
get {
return detailLabel.text
}
set {
detailLabel.text = newValue
}
}
override func layoutSubviews() {
super.layoutSubviews()
let frame = contentView.bounds.insetBy(dx: padding, dy: 0)

View File

@@ -16,7 +16,7 @@ import UIKit
final class FullWidthSelfSizingCell: UICollectionViewCell {
let label: UILabel = {
private let label: UILabel = {
let label = UILabel()
label.backgroundColor = UIColor.red.withAlphaComponent(0.1)
label.numberOfLines = 0
@@ -24,6 +24,15 @@ final class FullWidthSelfSizingCell: UICollectionViewCell {
return label
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
override init(frame: CGRect) {
super.init(frame: frame)

View File

@@ -32,7 +32,7 @@ final class LabelCell: UICollectionViewCell {
return ceil(bounds.height) + insets.top + insets.bottom
}
let label: UILabel = {
fileprivate let label: UILabel = {
let label = UILabel()
label.backgroundColor = .clear
label.numberOfLines = 0
@@ -46,6 +46,15 @@ final class LabelCell: UICollectionViewCell {
return layer
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(label)

View File

@@ -16,7 +16,7 @@ import UIKit
final class ManuallySelfSizingCell: UICollectionViewCell {
let label: UILabel = {
private let label: UILabel = {
let label = UILabel()
label.backgroundColor = UIColor.green.withAlphaComponent(0.1)
label.numberOfLines = 1
@@ -24,6 +24,15 @@ final class ManuallySelfSizingCell: UICollectionViewCell {
return label
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
override init(frame: CGRect) {
super.init(frame: frame)

View File

@@ -17,7 +17,7 @@ import IGListKit
final class MonthTitleCell: UICollectionViewCell {
lazy var label: UILabel = {
fileprivate lazy var label: UILabel = {
let view = UILabel()
view.backgroundColor = .clear
view.textAlignment = .center
@@ -26,6 +26,15 @@ final class MonthTitleCell: UICollectionViewCell {
self.contentView.addSubview(view)
return view
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
override func layoutSubviews() {
super.layoutSubviews()

View File

@@ -16,7 +16,12 @@ import UIKit
final class NibCell: UICollectionViewCell {
static let nibName = "NibCell"
@IBOutlet var textLabel: UILabel!
@IBOutlet private var textLabel: UILabel!
var text: String? {
didSet {
textLabel.text = text
}
}
}

View File

@@ -18,4 +18,13 @@ final class NibSelfSizingCell: UICollectionViewCell {
@IBOutlet weak var contentLabel: UILabel!
private var content: String? {
get {
return contentLabel.text
}
set {
contentLabel.text = newValue
}
}
}

View File

@@ -22,7 +22,7 @@ final class RemoveCell: UICollectionViewCell {
weak var delegate: RemoveCellDelegate?
lazy var label: UILabel = {
private lazy var label: UILabel = {
let label = UILabel()
label.backgroundColor = .clear
self.contentView.addSubview(label)
@@ -39,6 +39,15 @@ final class RemoveCell: UICollectionViewCell {
return button
}()
var text: String? {
get {
return label.text
}
set {
label.text = newValue
}
}
override func layoutSubviews() {
super.layoutSubviews()
contentView.backgroundColor = .white

View File

@@ -15,5 +15,14 @@
import UIKit
final class StoryboardCell: UICollectionViewCell {
@IBOutlet weak var textLabel: UILabel!
@IBOutlet private weak var textLabel: UILabel!
var text: String? {
get {
return textLabel.text
}
set {
textLabel.text = newValue
}
}
}

View File

@@ -16,7 +16,25 @@ import UIKit
final class UserHeaderView: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var handleLabel: UILabel!
@IBOutlet private weak var nameLabel: UILabel!
@IBOutlet private weak var handleLabel: UILabel!
var name: String? {
get {
return nameLabel.text
}
set {
nameLabel.text = newValue
}
}
var handle: String? {
get {
return handleLabel.text
}
set {
handleLabel.text = newValue
}
}
}