diff --git a/Sources/Views/MessageInputBar.swift b/Sources/Views/MessageInputBar.swift index 3a1b9ea9..07cd87d7 100644 --- a/Sources/Views/MessageInputBar.swift +++ b/Sources/Views/MessageInputBar.swift @@ -443,6 +443,8 @@ open class MessageInputBar: UIView { /// - Parameter positions: The UIStackView's to layout public func layoutStackViews(_ positions: [InputStackView.Position] = [.left, .right, .bottom, .top]) { + guard superview != nil else { return } + for position in positions { switch position { case .left: @@ -507,6 +509,7 @@ open class MessageInputBar: UIView { $0.parentStackViewPosition = position leftStackView.addArrangedSubview($0) } + guard superview != nil else { return } leftStackView.layoutIfNeeded() case .right: rightStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } @@ -516,6 +519,7 @@ open class MessageInputBar: UIView { $0.parentStackViewPosition = position rightStackView.addArrangedSubview($0) } + guard superview != nil else { return } rightStackView.layoutIfNeeded() case .bottom: bottomStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } @@ -525,6 +529,7 @@ open class MessageInputBar: UIView { $0.parentStackViewPosition = position bottomStackView.addArrangedSubview($0) } + guard superview != nil else { return } bottomStackView.layoutIfNeeded() case .top: topStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } @@ -534,6 +539,7 @@ open class MessageInputBar: UIView { $0.parentStackViewPosition = position topStackView.addArrangedSubview($0) } + guard superview != nil else { return } topStackView.layoutIfNeeded() } }