Skip to content

Commit

Permalink
Added get indexPath from datasource. Added editable flag to text fiel…
Browse files Browse the repository at this point in the history
…d cells.
  • Loading branch information
ivanvorobei committed Feb 28, 2022
1 parent bc61515 commit ffce3af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SPDiffable.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'SPDiffable'
s.version = '4.0.8'
s.version = '4.0.9'
s.summary = 'Extension of Diffable API which allow not duplicate code and use less models. Included example for SideBar.'
s.homepage = 'https://github.com/ivanvorobei/SPDiffable'
s.source = { :git => 'https://github.com/ivanvorobei/SPDiffable.git', :tag => s.version }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ open class SPDiffableTextFieldTitleTableViewCell: UITableViewCell {
}

private func commonInit() {
if #available(iOS 13.0, *) {
textLabel?.textColor = .secondaryLabel
}
textField.backgroundColor = .clear
contentView.addSubview(textField)
}
Expand All @@ -65,6 +68,7 @@ open class SPDiffableTextFieldTitleTableViewCell: UITableViewCell {
textField.delegate = item.delegate
textField.clearButtonMode = item.clearButtonMode
textField.textAlignment = .right
textField.isEnabled = item.editable
accessoryView = .none
selectionStyle = .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ open class SPDiffableTableDataSource: NSObject, SPDiffableDataSourceInterface {
return snapshot.sectionIdentifiers[index]
}

public func getIndexPath(id: String) -> IndexPath? {
guard let item = getItem(id: id) else { return nil }
guard let indexPath = appleDiffableDataSource?.indexPath(for: item) else { return nil }
return indexPath
}

public func getIndexPath(item: SPDiffableItem) -> IndexPath? {
guard let indexPath = appleDiffableDataSource?.indexPath(for: item) else { return nil }
return indexPath
}

// MARK: - Private

private func convertToSnapshot(_ sections: [SPDiffableSection]) -> AppleTableDiffableDataSource.Snapshot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ open class SPDiffableTableRowTextField: SPDiffableItem {
open var autocapitalizationType: UITextAutocapitalizationType
open var clearButtonMode: UITextField.ViewMode
open weak var delegate: UITextFieldDelegate?
open var editable: Bool

public init(
id: String,
Expand All @@ -41,7 +42,8 @@ open class SPDiffableTableRowTextField: SPDiffableItem {
keyboardType: UIKeyboardType,
autocapitalizationType: UITextAutocapitalizationType,
clearButtonMode: UITextField.ViewMode,
delegate: UITextFieldDelegate?
delegate: UITextFieldDelegate?,
editable: Bool = true
) {
self.icon = icon
self.text = text
Expand All @@ -51,6 +53,7 @@ open class SPDiffableTableRowTextField: SPDiffableItem {
self.keyboardType = keyboardType
self.autocapitalizationType = autocapitalizationType
self.clearButtonMode = clearButtonMode
self.editable = editable
super.init(id: id)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ open class SPDiffableTableRowTextFieldTitle: SPDiffableTableRowTextField {
keyboardType: UIKeyboardType,
autocapitalizationType: UITextAutocapitalizationType,
clearButtonMode: UITextField.ViewMode,
delegate: UITextFieldDelegate?
delegate: UITextFieldDelegate?,
editable: Bool = true
) {
self.title = title
super.init(id: id, icon: icon, text: text, placeholder: placeholder, autocorrectionType: autocorrectionType, keyboardType: keyboardType, autocapitalizationType: autocapitalizationType, clearButtonMode: clearButtonMode, delegate: delegate)
super.init(id: id, icon: icon, text: text, placeholder: placeholder, autocorrectionType: autocorrectionType, keyboardType: keyboardType, autocapitalizationType: autocapitalizationType, clearButtonMode: clearButtonMode, delegate: delegate, editable: editable)
}
}

0 comments on commit ffce3af

Please sign in to comment.