Skip to content

ScrollView contentOffset not adjusted correctly when form is displayed as page sheet and keyboard is displayed #1952

@funkenstrahlen

Description

@funkenstrahlen

I discovered an issue with adjusting the form ScrollView contentInset and contentOffset when the user edits text in a TextAreaRow. This becomes a problem as soon as the form is presented as an page sheet on iOS 13. It looks like the scrolling does not consider the additional top space added by the new page sheet presentation style.

2019-12-12 21-31-01 2019-12-12 21_31_58

This only happens when the view is displayed with the page sheet style (space at the top).

Also the behavior is not consistent as you can see in this clip:

2019-12-12 21-37-07 2019-12-12 21_37_46

The same code on iOS 12 without the page sheet presentation style: Also not consistent but does not scroll badly so the first line is invisible:

2019-12-12 21-40-40 2019-12-12 21_41_07

I guess this is the code that needs some update to fix this:

Eureka/Source/Core/Core.swift

Lines 1009 to 1037 in 2924259

@objc open func keyboardWillShow(_ notification: Notification) {
guard let table = tableView, let cell = table.findFirstResponder()?.formCell() else { return }
let keyBoardInfo = notification.userInfo!
let endFrame = keyBoardInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue
let keyBoardFrame = table.window!.convert(endFrame.cgRectValue, to: table.superview)
let newBottomInset = table.frame.origin.y + table.frame.size.height - keyBoardFrame.origin.y + rowKeyboardSpacing
var tableInsets = table.contentInset
var scrollIndicatorInsets = table.scrollIndicatorInsets
oldBottomInset = oldBottomInset ?? tableInsets.bottom
if newBottomInset > oldBottomInset! {
tableInsets.bottom = newBottomInset
scrollIndicatorInsets.bottom = tableInsets.bottom
UIView.beginAnimations(nil, context: nil)
UIView.setAnimationDuration((keyBoardInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! Double))
UIView.setAnimationCurve(UIView.AnimationCurve(rawValue: (keyBoardInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as! Int))!)
table.contentInset = tableInsets
table.scrollIndicatorInsets = scrollIndicatorInsets
if let selectedRow = table.indexPath(for: cell) {
if ProcessInfo.processInfo.operatingSystemVersion.majorVersion == 11 {
let rect = table.rectForRow(at: selectedRow)
table.scrollRectToVisible(rect, animated: animateScroll)
} else {
table.scrollToRow(at: selectedRow, at: .none, animated: animateScroll)
}
}
UIView.commitAnimations()
}
}

I tried to figure it out myself, but could not find a solution yet.

Environment: Eureka 5.1.0, Xcode 11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions