Skip to content

Commit eb9591a

Browse files
committed
Fix SwiftUI hang
1 parent e70fb07 commit eb9591a

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

SwiftMessages/KeyboardTrackingView.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,15 @@ open class KeyboardTrackingView: UIView {
128128
}
129129

130130
private func animateKeyboardChange(change: Change, height: CGFloat, userInfo: [AnyHashable: Any]) {
131-
self.heightConstraint.constant = height
132-
if let durationNumber = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber,
133-
let curveNumber = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber {
134-
CATransaction.begin()
135-
CATransaction.setCompletionBlock {
136-
self.didChange(change: change, userInfo: userInfo)
137-
self.delegate?.keyboardTrackingViewDidChange(change: change, userInfo: userInfo)
138-
}
139-
let curve = UIView.AnimationCurve(rawValue: curveNumber.intValue) ?? .easeInOut
140-
let animation = UIViewPropertyAnimator(duration: durationNumber.doubleValue, curve: curve) {
131+
if let durationNumber = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber {
132+
UIView.animate(withDuration: durationNumber.doubleValue, delay: 0, options: .curveEaseInOut, animations: {
133+
self.heightConstraint.constant = height
141134
self.updateConstraintsIfNeeded()
142135
self.superview?.layoutIfNeeded()
136+
}) { completed in
137+
self.didChange(change: change, userInfo: userInfo)
138+
self.delegate?.keyboardTrackingViewDidChange(change: change, userInfo: userInfo)
143139
}
144-
animation.startAnimation()
145140
}
146141
}
147142

SwiftMessages/MessageHostingView.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010

1111
/// A rudimentary hosting view for SwiftUI messages.
1212
@available(iOS 14.0, *)
13-
public class MessageHostingView<Content>: BaseView, Identifiable where Content: View {
13+
public class MessageHostingView<Content>: UIView, Identifiable where Content: View {
1414

1515
// MARK: - API
1616

@@ -50,4 +50,17 @@ public class MessageHostingView<Content>: BaseView, Identifiable where Content:
5050
if view == self || view?.superview == self { return nil }
5151
return view
5252
}
53+
54+
// MARK: - Configuration
55+
56+
private func installContentView(_ contentView: UIView) {
57+
contentView.translatesAutoresizingMaskIntoConstraints = false
58+
addSubview(contentView)
59+
NSLayoutConstraint.activate([
60+
contentView.topAnchor.constraint(equalTo: topAnchor),
61+
contentView.bottomAnchor.constraint(equalTo: bottomAnchor),
62+
contentView.leftAnchor.constraint(equalTo: leftAnchor),
63+
contentView.rightAnchor.constraint(equalTo: rightAnchor),
64+
])
65+
}
5366
}

0 commit comments

Comments
 (0)