Skip to content

Commit

Permalink
Merge branch 'release/3.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Jan 21, 2020
2 parents f81aa4c + fa1cf5b commit 7e7a70e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
17 changes: 17 additions & 0 deletions ExampleiOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let text = """
- <img named="check" att="5"/> Performed!
"""
let base = Style {
$0.font = UIFont.boldSystemFont(ofSize: 14)
$0.color = UIColor(hexString: "#8E8E8E")
}

let xmlStyle = StyleXML(base: base)
xmlStyle.imageProvider = { imageName, attributes in
fatalError()
}

self.textView?.attributedText = text.set(style: xmlStyle)

return

// self.textView?.attributedText = "ciao ciao " + AttributedString(image: UIImage(named: "rocket")!,
// bounds: CGRect(x: 0, y: -20, width: 25, height: 25)) + "ciao ciao"
//
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ This is the result:
Sometimes you may want to provide these images lazily. In order to do it just provide a custom implementation of the `imageProvider` callback in `StyleXML` instance:

```swift
let xmlText = "- <img named=\"check\"/> has done!"
let xmlText = "- <img named=\"check\" background=\"#0000\"/> has done!"

let xmlStyle = StyleXML(base: {
/// some attributes for base style
Expand All @@ -548,7 +548,7 @@ let xmlStyle = StyleXML(base: {
// This method is called when a new `img` tag is found. It's your chance to
// return a custom image. If you return `nil` (or you don't implement this method)
// image is searched inside any bundled `xcasset` file.
xmlStyle.imageProvider = { imageName in
xmlStyle.imageProvider = { (imageName, attributes) in
switch imageName {
case "check":
// create & return your own image
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftRichString/Style/StyleGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class StyleXML: StyleProtocol {

/// Image provider is called to provide custom image when `StyleXML` encounter a `img` tag image.
/// If not implemented the image is automatically searched inside any bundled `xcassets`.
public var imageProvider: ((String) -> Image?)? = nil
public var imageProvider: ((_ name: String, _ attributes: [String: String]?) -> Image?)? = nil

/// Dynamic attributes resolver.
/// By default the `StandardXMLAttributesResolver` instance is used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public protocol XMLDynamicAttributesResolver {
/// - Parameters:
/// - name: name of the image to get.
/// - fromStyle: caller instance of `StyleXML.
func imageWithName(_ name: String, fromStyle style: StyleXML) -> Image?
func image(name: String, attributes: [String: String]?, fromStyle style: StyleXML) -> Image?

/// You are receiving this event when SwiftRichString correctly render an existing tag but the tag
/// contains extra attributes you may want to handle.
Expand Down Expand Up @@ -75,8 +75,8 @@ public protocol XMLDynamicAttributesResolver {

extension XMLDynamicAttributesResolver {

public func imageWithName(_ name: String, fromStyle style: StyleXML) -> Image? {
guard let mappedImage = style.imageProvider?(name) else {
public func image(name: String, attributes: [String: String]?, fromStyle style: StyleXML) -> Image? {
guard let mappedImage = style.imageProvider?(name, attributes) else {
return Image(named: name) // xcassets fallback
}

Expand Down Expand Up @@ -124,7 +124,7 @@ open class StandardXMLAttributesResolver: XMLDynamicAttributesResolver {
#if os(iOS) || os(OSX)
// Local Image support
if let imageName = attributes?["named"] {
if let image = imageWithName(imageName, fromStyle: fromStyle),
if let image = image(name: imageName, attributes: attributes, fromStyle: fromStyle),
let imageString = AttributedString(image: image, bounds: attributes?["rect"]) {
attributedString.append(imageString)
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftRichString.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SwiftRichString"
s.version = "3.6.0"
s.version = "3.6.1"
s.summary = "Elegant Strings & Attributed Strings Toolkit for Swift"
s.description = <<-DESC
SwiftRichString is the best toolkit to work easily with Strings and Attributed Strings.
Expand Down
16 changes: 8 additions & 8 deletions SwiftRichString.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.6.0;
MARKETING_VERSION = 3.6.1;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-iOS";
PRODUCT_NAME = SwiftRichString;
Expand All @@ -1666,7 +1666,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.6.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-iOS";
PRODUCT_NAME = SwiftRichString;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1718,7 +1718,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.5.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-watchOS";
PRODUCT_NAME = SwiftRichString;
SDKROOT = watchos;
Expand All @@ -1745,7 +1745,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.5.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-watchOS";
PRODUCT_NAME = SwiftRichString;
SDKROOT = watchos;
Expand All @@ -1772,7 +1772,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.5.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-tvOS";
PRODUCT_NAME = SwiftRichString;
SDKROOT = appletvos;
Expand All @@ -1799,7 +1799,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.5.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-tvOS";
PRODUCT_NAME = SwiftRichString;
SDKROOT = appletvos;
Expand Down Expand Up @@ -1828,7 +1828,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.5.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-macOS";
PRODUCT_NAME = SwiftRichString;
SDKROOT = macosx;
Expand All @@ -1855,7 +1855,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 3.5.0;
MARKETING_VERSION = 3.6.1;
PRODUCT_BUNDLE_IDENTIFIER = "com.SwiftRichString.SwiftRichString-macOS";
PRODUCT_NAME = SwiftRichString;
SDKROOT = macosx;
Expand Down

0 comments on commit 7e7a70e

Please sign in to comment.