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 markdown support to tvOS #466

Merged
merged 1 commit into from
Jul 25, 2023
Merged
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
1 change: 1 addition & 0 deletions ConsentViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Pod::Spec.new do |s|
s.ios.exclude_files = 'ConsentViewController/Classes/Views/tvOS'
s.tvos.deployment_target = '10.0'
s.tvos.exclude_files = 'ConsentViewController/Classes/Views/iOS'
s.tvos.dependency 'Down', '~> 0.9.0'
s.resource_bundles = { 'ConsentViewController' => ['ConsentViewController/Assets/**/*', 'Pod/Classes/**/*.{storyboard,xib,xcassets,json,imageset,png,js}'] }
s.resources = "ConsentViewController/**/*.{js,json,png}"
s.info_plist = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import UIKit
import Down

extension UIImageView {
func load(url: URL) {
Expand Down Expand Up @@ -212,15 +213,22 @@ class FocusGuideDebugView: UIView {
return label
}

func parseText(_ rawText: String) -> NSAttributedString? {
guard let markdownText = try? Down(markdownString: rawText).toAttributedString(),
markdownText.length != 0 else {
return rawText.htmlToAttributedString
}
return markdownText
}

@discardableResult
func loadTextView(forComponentId id: String, textView: UITextView, text: String? = nil, bounces: Bool = true) -> UITextView {
if let textViewComponent = components.first(where: { $0.id == id }) as? SPNativeText {
let style = textViewComponent.settings.style
if let text = text {
textView.attributedText = text.htmlToAttributedString
} else {
textView.attributedText = textViewComponent.settings.text.htmlToAttributedString
}
textView.attributedText = parseText(text != nil ?
text! :
textViewComponent.settings.text
)
textView.textColor = UIColor(hexString: style.font.color)
textView.isUserInteractionEnabled = true
textView.isScrollEnabled = true
Expand Down
8 changes: 6 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PODS:
- ConsentViewController (7.2.1)
- ConsentViewController (7.2.1):
- Down (~> 0.9.0)
- Down (0.9.5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andresilveirah is it alright that we have two Down dependencies but with different versions in the Podfile?

Copy link
Member Author

@andresilveirah andresilveirah Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nevazhnovu yes.
The notation ~> X.Y.Z means use the latest version as long as X and Y are the ones specified (so Z can be as high as possible.
If you specify ~> X.Y it'd mean, use the latest version as long as X is the one specified and Y can go as high as possible.

https://guides.cocoapods.org/syntax/podfile.html#pod

- IQKeyboardManagerSwift (6.5.10)
- JSONView (0.0.3)
- Nimble (10.0.0)
Expand All @@ -18,6 +20,7 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- Down
- IQKeyboardManagerSwift
- JSONView
- Nimble
Expand All @@ -30,7 +33,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ConsentViewController: 038d1eb3a9cebc9157809220a319ac1ef7173b8d
ConsentViewController: b4bc3ccbeb4d1659b61609ba956b61c4aa78fa86
Down: 7321a72d0747ed0061dce948bcff518fcb6df2bd
IQKeyboardManagerSwift: 52962c76ab33532f15ad9f3ff4e5715eda5335bb
JSONView: ba9049102fae7ad70de40234d0b7c60986e61e4c
Nimble: 5316ef81a170ce87baf72dd961f22f89a602ff84
Expand Down
218 changes: 218 additions & 0 deletions Example/Pods/Down/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading