Skip to content

Commit

Permalink
End editing to dismiss the keyboard the case where a cell having focu…
Browse files Browse the repository at this point in the history
…s gets recycled. (#331)
  • Loading branch information
rajdeep authored Jul 30, 2024
1 parent ffb2be2 commit d7947b3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
9 changes: 7 additions & 2 deletions ExampleApp/ExampleApp/Commands/TableViewCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ public class TableViewCommand: EditorCommand {
self.delegate = delegate

text.append(NSAttributedString(string: "Text before Grid"))
let str = """
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
"""

timeEvent(label: "Create")
for i in 1..<2 {
for i in 1..<4 {
text.append(NSAttributedString(string: str))
text.append(makeGridViewAttachment(id: i, numRows: 10, numColumns: 10).string)
// text.append(makePanelAttachment(id: i).string)
text.append(NSAttributedString(string: "\ntest middle\n"))
text.append(NSAttributedString(string: str))
}

text.append(NSAttributedString(string: "Text After Grid"))
Expand Down
18 changes: 18 additions & 0 deletions Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,24 @@ open class EditorView: UIView {
richTextView.text
}

// Boolean flag to control first responder state
private var canBecomeFirstResponderFlag = true

// Override canBecomeFirstResponder property
open override var canBecomeFirstResponder: Bool {
return canBecomeFirstResponderFlag
}

// Method to disable becoming first responder
func disableFirstResponder() {
canBecomeFirstResponderFlag = false
}

// Method to enable becoming first responder
func enableFirstResponder() {
canBecomeFirstResponderFlag = true
}

public var selectedRange: NSRange {
get { richTextView.ensuringValidSelectedRange() }
set { richTextView.selectedRange = newValue }
Expand Down
2 changes: 2 additions & 0 deletions Proton/Sources/Swift/Table/TableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,11 @@ public class TableCell {
}

func addContentView(_ contentView: TableCellContentView) {
contentView.editor.disableFirstResponder()
prepareForReuse(contentView)
self.contentView = contentView
delegate?.cell(self, didAddContentView: contentView)
contentView.editor.enableFirstResponder()
}

func prepareForReuse(_ contentView: TableCellContentView) {
Expand Down
13 changes: 4 additions & 9 deletions Proton/Sources/Swift/Table/TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,11 @@ public class TableView: UIView {
// In absence of this check, if the editor having focus gets reclaimed,
// the focus moves to root editor which may cause the content to be scrolled
// out to end of the root editor.
var needsFocusChange = false
let needsFocusChange = toReclaim.contains(where: { $0.editor?.isFirstResponder() == true })
if needsFocusChange {
containerAttachment?.containerEditorView?.rootEditor.endEditing(true)
}
toReclaim.forEach { [weak self] cell in
if needsFocusChange == false {
needsFocusChange = cell.editor?.isFirstResponder() == true
if needsFocusChange {
self?.cellsInViewport
.first(where: { c in c.editor != nil && c.columnSpan.min() == cell.columnSpan.min() } )?
.editor?.becomeFirstResponder()
}
}
self?.repository.enqueue(cell: cell)
}

Expand Down

0 comments on commit d7947b3

Please sign in to comment.