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

Add ios16 compatibility and improve scrolling handling #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions Sources/MarkdownView/MarkdownUI.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import SwiftUI

public final class MarkdownUI: UIViewRepresentable {
public struct MarkdownUI: UIViewRepresentable {
private let markdownView: MarkdownView

@Binding public var body: String

public init(body: String? = nil, css: String? = nil, plugins: [String]? = nil, stylesheets: [URL]? = nil, styled: Bool = true) {
self._body = .constant(body ?? "")
self.markdownView = MarkdownView(css: css, plugins: plugins, stylesheets: stylesheets, styled: styled)
self.markdownView.isScrollEnabled = false
self.markdownView.isScrollEnabled = true
}

public func onTouchLink(perform action: @escaping ((URLRequest) -> Bool)) -> MarkdownUI {
Expand All @@ -29,9 +29,7 @@ extension MarkdownUI {
}

public func updateUIView(_ uiView: MarkdownView, context: Context) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.markdownView.show(markdown: self.body)
}
self.markdownView.markDown = self.body
}

public func makeCoordinator() -> () {
Expand Down
6 changes: 6 additions & 0 deletions Sources/MarkdownView/MarkdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ open class MarkdownView: UIView {
public convenience init() {
self.init(frame: .zero)
}

public var markDown: String = ""

/// Reserve a web view before displaying markdown.
/// You can use this for performance optimization.
Expand Down Expand Up @@ -118,6 +120,10 @@ extension MarkdownView: WKNavigationDelegate {
}

}

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
show(markdown: markDown)
}
}

// MARK: -
Expand Down