Skip to content

Commit

Permalink
ScrollView jumping improvements (#2315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amzd authored Oct 15, 2024
1 parent 6e1d4b2 commit dbe85fc
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 339 deletions.
4 changes: 4 additions & 0 deletions deltachat-ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
30FDB70524D1C1000066C48D /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB6F824D1C1000066C48D /* ChatViewController.swift */; };
30FDB71F24D8170E0066C48D /* TextMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB71E24D8170E0066C48D /* TextMessageCell.swift */; };
30FDB72124D838240066C48D /* BaseMessageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30FDB72024D838240066C48D /* BaseMessageCell.swift */; };
5F785F6E2CB9344F003FFFB9 /* ReusableCellProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F785F6D2CB9344F003FFFB9 /* ReusableCellProtocol.swift */; };
7070FB9B2101ECBB000DC258 /* NewGroupController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7070FB9A2101ECBB000DC258 /* NewGroupController.swift */; };
7092474120B3869500AF8799 /* ContactDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7092474020B3869500AF8799 /* ContactDetailViewController.swift */; };
70B8882E2091B8550074812E /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B8882D2091B8550074812E /* ContactCell.swift */; };
Expand Down Expand Up @@ -432,6 +433,7 @@
30FDB6F824D1C1000066C48D /* ChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = "<group>"; };
30FDB71E24D8170E0066C48D /* TextMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextMessageCell.swift; sourceTree = "<group>"; };
30FDB72024D838240066C48D /* BaseMessageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseMessageCell.swift; sourceTree = "<group>"; };
5F785F6D2CB9344F003FFFB9 /* ReusableCellProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReusableCellProtocol.swift; sourceTree = "<group>"; };
7070FB9A2101ECBB000DC258 /* NewGroupController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGroupController.swift; sourceTree = "<group>"; };
7092474020B3869500AF8799 /* ContactDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactDetailViewController.swift; sourceTree = "<group>"; };
70B8882D2091B8550074812E /* ContactCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -827,6 +829,7 @@
isa = PBXGroup;
children = (
30FDB71E24D8170E0066C48D /* TextMessageCell.swift */,
5F785F6D2CB9344F003FFFB9 /* ReusableCellProtocol.swift */,
30FDB72024D838240066C48D /* BaseMessageCell.swift */,
30E348E024F53772005C93D1 /* ImageTextCell.swift */,
30E348E424F6647D005C93D1 /* FileTextCell.swift */,
Expand Down Expand Up @@ -1633,6 +1636,7 @@
30E83EFD289BF32C0035614C /* ShortcutManager.swift in Sources */,
305501742798CDE1008FD5CA /* WebxdcViewController.swift in Sources */,
3034929F25752FC800A523D0 /* MediaPreview.swift in Sources */,
5F785F6E2CB9344F003FFFB9 /* ReusableCellProtocol.swift in Sources */,
AE76E5EE242BF2EA003CF461 /* WelcomeViewController.swift in Sources */,
3052C60A253F082E007D13EA /* MessageLabelDelegate.swift in Sources */,
AE0AA9562478191900D42A7F /* GridCollectionViewFlowLayout.swift in Sources */,
Expand Down
559 changes: 247 additions & 312 deletions deltachat-ios/Chat/ChatViewController.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ internal extension NSNotification {
}

var timeInterval: TimeInterval? {
guard let value = userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber else { return nil }
return TimeInterval(truncating: value)
userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double
}

var animationCurve: UIView.AnimationCurve? {
Expand All @@ -60,19 +59,8 @@ internal extension NSNotification {
}

var animationOptions: UIView.AnimationOptions {
guard let curve = animationCurve else { return [] }
switch curve {
case .easeIn:
return .curveEaseIn
case .easeOut:
return .curveEaseOut
case .easeInOut:
return .curveEaseInOut
case .linear:
return .curveLinear
@unknown default:
return .curveLinear
}
guard let animationCurve = userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as? UInt else { return .curveLinear }
return UIView.AnimationOptions(rawValue: animationCurve << 16)
}

var startFrame: CGRect? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ open class InputBarAccessoryView: UIView {
/// - view: New view
/// - animated: If the layout should be animated
open func setMiddleContentView(_ view: UIView?, animated: Bool) {
guard view !== middleContentView else { return }
middleContentView?.removeFromSuperview()
middleContentView = view
guard let view = view else { return }
Expand Down Expand Up @@ -832,7 +833,8 @@ open class InputBarAccessoryView: UIView {
/// - newValue: New widthAnchor constant
/// - animated: If the layout should be animated
open func setLeftStackViewWidthConstant(to newValue: CGFloat, animated: Bool) {
performLayout(animated) {
guard leftStackViewWidthConstant != newValue else { return }
performLayout(animated) {
self.leftStackViewWidthConstant = newValue
self.layoutStackViews([.left])
self.layoutContainerViewIfNeeded()
Expand All @@ -845,7 +847,8 @@ open class InputBarAccessoryView: UIView {
/// - newValue: New widthAnchor constant
/// - animated: If the layout should be animated
open func setRightStackViewWidthConstant(to newValue: CGFloat, animated: Bool) {
performLayout(animated) {
guard rightStackViewWidthConstant != newValue else { return }
performLayout(animated) {
self.rightStackViewWidthConstant = newValue
self.layoutStackViews([.right])
self.layoutContainerViewIfNeeded()
Expand All @@ -858,6 +861,7 @@ open class InputBarAccessoryView: UIView {
/// - newValue: New boolean value
/// - animated: If the layout should be animated
open func setShouldForceMaxTextViewHeight(to newValue: Bool, animated: Bool) {
guard shouldForceTextViewMaxHeight != newValue else { return }
performLayout(animated) {
self.shouldForceTextViewMaxHeight = newValue
self.textViewHeightAnchor?.isActive = newValue
Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/AudioMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public protocol AudioMessageCellDelegate: AnyObject {

}

public class AudioMessageCell: BaseMessageCell {
public class AudioMessageCell: BaseMessageCell, ReusableCell {

static let reuseIdentifier = "AudioMessageCell"

Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/ContactCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UIKit
import DcCore
import SDWebImage

public class ContactCardCell: BaseMessageCell {
public class ContactCardCell: BaseMessageCell, ReusableCell {

static let reuseIdentifier = "ContactCardCell"

Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/FileTextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UIKit
import DcCore
import SDWebImage

public class FileTextCell: BaseMessageCell {
public class FileTextCell: BaseMessageCell, ReusableCell {

class var reuseIdentifier: String { "FileTextCell" }

Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/ImageTextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UIKit
import DcCore
import SDWebImage

class ImageTextCell: BaseMessageCell {
class ImageTextCell: BaseMessageCell, ReusableCell {

static let reuseIdentifier = "ImageTextCell"

Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/InfoMessageCell.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import DcCore

class InfoMessageCell: UITableViewCell {
class InfoMessageCell: UITableViewCell, ReusableCell {

static let reuseIdentifier = "InfoMessageCell"

Expand Down
5 changes: 5 additions & 0 deletions deltachat-ios/Chat/Views/Cells/ReusableCellProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import UIKit

protocol ReusableCell: UITableViewCell {
static var reuseIdentifier: String { get }
}
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/TextMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import DcCore
import UIKit

class TextMessageCell: BaseMessageCell {
class TextMessageCell: BaseMessageCell, ReusableCell {

static let reuseIdentifier = "TextMessageCell"

Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/Cells/VideoInviteCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import UIKit
import DcCore

public class VideoInviteCell: UITableViewCell {
public class VideoInviteCell: UITableViewCell, ReusableCell {

static let reuseIdentifier = "VideoInviteCell"

Expand Down
13 changes: 10 additions & 3 deletions deltachat-ios/View/EmptyStateLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ class EmptyStateLabel: PaddingTextView {
translatesAutoresizingMaskIntoConstraints = false
}

func addCenteredTo(parentView: UIView) {
func addCenteredTo(parentView: UIView, evadeKeyboard: Bool = false) {
parentView.addSubview(self)
leadingAnchor.constraint(equalTo: parentView.leadingAnchor, constant: 40).isActive = true
trailingAnchor.constraint(equalTo: parentView.trailingAnchor, constant: -40).isActive = true
centerYAnchor.constraint(equalTo: parentView.safeAreaLayoutGuide.centerYAnchor).isActive = true
centerXAnchor.constraint(equalTo: parentView.safeAreaLayoutGuide.centerXAnchor).isActive = true
let safeArea = parentView.safeAreaLayoutGuide
centerXAnchor.constraint(equalTo: safeArea.centerXAnchor).isActive = true
let centerYConstraint = centerYAnchor.constraint(equalTo: safeArea.centerYAnchor)
centerYConstraint.isActive = true
if #available(iOS 15.0, *), evadeKeyboard {
centerYConstraint.priority = .defaultHigh
bottomAnchor.constraint(lessThanOrEqualTo: parentView.keyboardLayoutGuide.topAnchor, constant: -40).isActive = true
}

}

required init?(coder: NSCoder) {
Expand Down

0 comments on commit dbe85fc

Please sign in to comment.