Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit f161876

Browse files
authored
nil scrollview in message VC (#1434)
1 parent 842260d commit f161876

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Local Pods/MessageViewController/MessageViewController/MessageViewController.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
8080
case hiding
8181
}
8282
internal var keyboardState: KeyboardState = .resigned
83-
internal var scrollView: UIScrollView!
83+
internal var scrollView: UIScrollView?
8484
internal var keyboardHeight: CGFloat = 0
8585
internal var isMessageViewHidden = false
8686

@@ -104,6 +104,8 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
104104
}
105105

106106
internal func layout() {
107+
guard let scrollView = self.scrollView else { return }
108+
107109
let bounds = view.bounds
108110

109111
let safeAreaAdditionalHeight = self.safeAreaAdditionalHeight
@@ -155,21 +157,22 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
155157
let animationDuration = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval
156158
else { return }
157159

158-
scrollView.stopScrolling()
160+
scrollView?.stopScrolling()
159161
keyboardState = .showing
160162

161163
let previousKeyboardHeight = keyboardHeight
162164
keyboardHeight = keyboardFrame.height
163165

164166
UIView.animate(withDuration: animationDuration) {
167+
guard let scrollView = self.scrollView else { return }
165168
// capture before changing the frame which might have weird side effects
166-
let contentOffset = self.scrollView.contentOffset
169+
let contentOffset = scrollView.contentOffset
167170

168171
self.layout()
169172

170-
let scrollViewHeight = self.scrollView.bounds.height
171-
let contentHeight = self.scrollView.contentSize.height
172-
let topInset = self.scrollView.util_adjustedContentInset.top
173+
let scrollViewHeight = scrollView.bounds.height
174+
let contentHeight = scrollView.contentSize.height
175+
let topInset = scrollView.util_adjustedContentInset.top
173176
let bottomSafeInset = self.view.util_safeAreaInsets.bottom
174177

175178
let newOffset = max(
@@ -179,7 +182,7 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
179182
),
180183
-topInset
181184
)
182-
self.scrollView.contentOffset = CGPoint(x: contentOffset.x, y: newOffset)
185+
scrollView.contentOffset = CGPoint(x: contentOffset.x, y: newOffset)
183186
}
184187
}
185188

0 commit comments

Comments
 (0)