Skip to content

Commit

Permalink
Merge pull request #27 from NuPlay/feat/transition_option
Browse files Browse the repository at this point in the history
✨ feat: Add placeholder transition option
  • Loading branch information
NuPlay authored Feb 7, 2023
2 parents 4dae52e + 2f7b095 commit 26bd7fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Sources/RichText/Extensions/RichText+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ extension RichText {
result.placeholder = AnyView(content())
return result
}

public func transition(_ transition: Animation?) -> RichText {
var result = self
result.configuration.transition = transition
return result
}
}

// MARK: - Deprected Functions
Expand Down
6 changes: 5 additions & 1 deletion Sources/RichText/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public struct Configuration {

public var isColorsImportant: ColorPreference

public var transition: Animation?

public init(
customCSS: String = "",
fontType: FontType = .system,
Expand All @@ -33,7 +35,8 @@ public struct Configuration {
imageRadius: CGFloat = 0,
linkOpenType: LinkOpenType = .SFSafariView(),
linkColor: ColorSet = .init(light: "007AFF", dark: "0A84FF", isImportant: true),
isColorsImportant: ColorPreference = .onlyLinks
isColorsImportant: ColorPreference = .onlyLinks,
transition: Animation? = .none
) {
self.customCSS = customCSS
self.fontType = fontType
Expand All @@ -44,6 +47,7 @@ public struct Configuration {
self.linkOpenType = linkOpenType
self.linkColor = linkColor
self.isColorsImportant = isColorsImportant
self.transition = transition
}

func css(isLight: Bool, alignment: TextAlignment) -> String {
Expand Down
4 changes: 3 additions & 1 deletion Sources/RichText/Views/Webview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ extension WebView {
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.documentElement.scrollHeight", completionHandler: { (height, _) in
DispatchQueue.main.async {
self.parent.dynamicHeight = height as! CGFloat
withAnimation(self.parent.conf.transition) {
self.parent.dynamicHeight = height as! CGFloat
}
}
})
}
Expand Down

0 comments on commit 26bd7fa

Please sign in to comment.