Skip to content

Commit

Permalink
Removed height constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankmara authored May 3, 2024
1 parent 673be3f commit a994a97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public final class StaticInAppContentBlockView: UIView, WKNavigationDelegate {
)
return
}
self.replacePlaceholder(inputView: self, loadedInAppContentBlocksView: self.webview, height: height.height ) {
self.heightCompletion?(Int(height.height))
let usableHeight = height.height - calculator.defaultPadding
self.replacePlaceholder(inputView: self, loadedInAppContentBlocksView: self.webview, height: usableHeight) {
self.heightCompletion?(Int(usableHeight))
self.prepareContentReadyState(true)
guard let message = self.assignedMessage else {
return
Expand Down Expand Up @@ -152,16 +153,16 @@ public final class StaticInAppContentBlockView: UIView, WKNavigationDelegate {
}
loadedInAppContentBlocksView.removeFromSuperview()
inputView.addSubview(loadedInAppContentBlocksView)
loadedInAppContentBlocksView.topAnchor.constraint(equalTo: inputView.topAnchor, constant: 5).isActive = true
loadedInAppContentBlocksView.leadingAnchor.constraint(equalTo: inputView.leadingAnchor, constant: 5).isActive = true
loadedInAppContentBlocksView.trailingAnchor.constraint(equalTo: inputView.trailingAnchor, constant: -5).isActive = true
loadedInAppContentBlocksView.topAnchor.constraint(equalTo: inputView.topAnchor).isActive = true
loadedInAppContentBlocksView.leadingAnchor.constraint(equalTo: inputView.leadingAnchor).isActive = true
loadedInAppContentBlocksView.trailingAnchor.constraint(equalTo: inputView.trailingAnchor).isActive = true
if self.height != nil {
self.height?.constant = height
} else {
self.height = loadedInAppContentBlocksView.heightAnchor.constraint(equalToConstant: height)
self.height?.isActive = true
}
loadedInAppContentBlocksView.bottomAnchor.constraint(equalTo: inputView.bottomAnchor, constant: -5).isActive = true
loadedInAppContentBlocksView.bottomAnchor.constraint(equalTo: inputView.bottomAnchor).isActive = true
loadedInAppContentBlocksView.sizeToFit()
loadedInAppContentBlocksView.layoutIfNeeded()
UIView.animate(withDuration: duration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import UIKit
public final class WKWebViewHeightCalculator: WKWebView, WKNavigationDelegate {

// MARK: - Properties
var defaultPadding: CGFloat = 20
var heightUpdate: TypeBlock<CalculatorData>?
var height: CGFloat?
var id: String = ""
Expand All @@ -32,7 +33,7 @@ public final class WKWebViewHeightCalculator: WKWebView, WKNavigationDelegate {
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void
) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.heightUpdate?(.init(height: webView.scrollView.contentSize.height + 25, placeholderId: self.id))
self.heightUpdate?(.init(height: webView.scrollView.contentSize.height + self.defaultPadding, placeholderId: self.id))
}
decisionHandler(.allow)
}
Expand Down

0 comments on commit a994a97

Please sign in to comment.