Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash related to force unwrapping and unowned self #812

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions GliaWidgets/Sources/View/Chat/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ChatView: EngagementView {
private lazy var quickReplyView = QuickReplyView(
style: style.gliaVirtualAssistant.quickReplyButton
)
private var messageEntryViewBottomConstraint: NSLayoutConstraint!
private var messageEntryViewBottomConstraint: NSLayoutConstraint?
private var callBubble: BubbleView?
private let keyboardObserver = KeyboardObserver()
private let kUnreadMessageIndicatorInset: CGFloat = -3
Expand Down Expand Up @@ -172,7 +172,9 @@ class ChatView: EngagementView {
edges: .bottom,
insets: messageEntryInsets
).first
constraints += messageEntryViewBottomConstraint
if let messageEntryViewBottomConstraint {
constraints += messageEntryViewBottomConstraint
}

constraints += messageEntryView.layoutIn(safeAreaLayoutGuide, edges: .horizontal)
constraints += messageEntryView.topAnchor.constraint(equalTo: quickReplyView.bottomAnchor)
Expand Down Expand Up @@ -584,15 +586,18 @@ extension ChatView {

extension ChatView {
private func observeKeyboard() {
keyboardObserver.keyboardWillShow = { [unowned self] properties in
let bottomInset = safeAreaInsets.bottom
keyboardObserver.keyboardWillShow = { [weak self] properties in
guard let self else { return }

let bottomInset = self.safeAreaInsets.bottom
let newEntryConstraint = -properties.finalFrame.height + bottomInset

UIView.animate(
withDuration: properties.duration,
delay: 0.0,
options: properties.animationOptions,
animations: { [weak self] in
self?.messageEntryViewBottomConstraint.constant = newEntryConstraint
self?.messageEntryViewBottomConstraint?.constant = newEntryConstraint
self?.layoutIfNeeded()
},
completion: { [weak self] _ in
Expand All @@ -601,13 +606,13 @@ extension ChatView {
)
}

keyboardObserver.keyboardWillHide = { [unowned self] properties in
keyboardObserver.keyboardWillHide = { [weak self] properties in
UIView.animate(
withDuration: properties.duration,
delay: 0.0,
options: properties.animationOptions,
animations: { [weak self] in
self?.messageEntryViewBottomConstraint.constant = 0
self?.messageEntryViewBottomConstraint?.constant = 0
self?.layoutIfNeeded()
}
)
Expand Down