Skip to content

Commit

Permalink
Add callbacks (#94)
Browse files Browse the repository at this point in the history
* Add callbacks

* version++
  • Loading branch information
keitaoouchi authored Feb 13, 2022
1 parent c08feca commit 5e62a27
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
16 changes: 7 additions & 9 deletions Example/Example/SwiftUI/SampleUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import MarkdownView
struct SampleUI: View {
var body: some View {
ScrollView {
Text("Header")
.frame(maxWidth: .infinity, idealHeight: 44)
.background(Color.red)


MarkdownUI(body: markdown)

Text("Footer")
.frame(maxWidth: .infinity, idealHeight: 44)
.background(Color.red)
.onTouchLink { link in
print(link)
return false
}
.onRendered { height in
print(height)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- MarkdownView (1.9.0)
- MarkdownView (1.9.1)

DEPENDENCIES:
- MarkdownView (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
MarkdownView: a3cace707de758a21246d45dba9430fdaf02776a
MarkdownView: 22249778219cc22901f1454e8355298dd0bda7f0

PODFILE CHECKSUM: aca8c849eff30cf020f460dc2fb5cc0b4a16e14a

Expand Down
2 changes: 1 addition & 1 deletion MarkdownView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "MarkdownView"
s.version = "1.9.0"
s.version = "1.9.1"
s.summary = "Markdown View for iOS."
s.homepage = "https://github.com/keitaoouchi/MarkdownView"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
4 changes: 2 additions & 2 deletions MarkdownView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.9.0;
MARKETING_VERSION = 1.9.1;
PRODUCT_BUNDLE_IDENTIFIER = com.keita.oouchi.MarkdownView;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -321,7 +321,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.9.0;
MARKETING_VERSION = 1.9.1;
PRODUCT_BUNDLE_IDENTIFIER = com.keita.oouchi.MarkdownView;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
```swift
import MarkdownView

let markdownView = MarkdownView()
markdownView.load(markdown: "# Hello World!")
let md = MarkdownView()
md.load(markdown: "# Hello World!")
```

#### SwiftUI

```
```swift
import SwiftUI
import MarkdownView

struct SampleUI: View {
var body: some View {
ScrollView {
Text("Header")
.frame(maxWidth: .infinity, idealHeight: 44)
.background(Color.red)
ScrollView {
MarkdownUI(body: markdown)
Text("Footer")
.frame(maxWidth: .infinity, idealHeight: 44)
.background(Color.red)
.onTouchLink { link in
print(link)
return false
}
.onRendered { height in
print(height)
}
}
}

Expand Down
15 changes: 10 additions & 5 deletions Sources/MarkdownView/MarkdownUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ public final class MarkdownUI: UIViewRepresentable {
self._body = .constant(body ?? "")
self.markdownView = MarkdownView(css: css, plugins: plugins, stylesheets: stylesheets, styled: styled)
self.markdownView.isScrollEnabled = false

self.markdownView.onRendered = { height in
print(height)

}
}

public func onTouchLink(perform action: @escaping ((URLRequest) -> Bool)) -> MarkdownUI {
self.markdownView.onTouchLink = action
return self
}

public func onRendered(perform action: @escaping ((CGFloat) -> Void)) -> MarkdownUI {
self.markdownView.onRendered = action
return self
}
}

Expand Down

0 comments on commit 5e62a27

Please sign in to comment.