From 548b1c0b457828a22a10c060ab938837837d2a66 Mon Sep 17 00:00:00 2001 From: Developer From Jokela Date: Sat, 9 Jul 2022 00:37:50 +0300 Subject: [PATCH] Added flexible support --- Package.resolved | 24 ++++++++++----------- Package.swift | 6 +++--- Sources/MarkdownUI/Markdown.swift | 4 ++-- Sources/MarkdownUI/Style/Measurements.swift | 7 +++++- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Package.resolved b/Package.resolved index 4417f360..f8c64b31 100644 --- a/Package.resolved +++ b/Package.resolved @@ -2,21 +2,21 @@ "object": { "pins": [ { - "package": "AttributedText", - "repositoryURL": "https://github.com/gonzalezreal/AttributedText", + "package": "combine-schedulers", + "repositoryURL": "https://github.com/pointfreeco/combine-schedulers", "state": { "branch": null, - "revision": "2dc2d7864e0fee4b524a5850d7d7cf9a7eeda0fc", - "version": "1.0.0" + "revision": "0ba3a562716efabb585ccb169450c5389107286b", + "version": "0.6.0" } }, { - "package": "combine-schedulers", - "repositoryURL": "https://github.com/pointfreeco/combine-schedulers", + "package": "AttributedText", + "repositoryURL": "https://github.com/wilmaplus/FlexibleAttributedText", "state": { "branch": null, - "revision": "4cf088c29a20f52be0f2ca54992b492c54e0076b", - "version": "0.5.3" + "revision": "2dc2d7864e0fee4b524a5850d7d7cf9a7eeda0fc", + "version": "1.0.0" } }, { @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/gonzalezreal/NetworkImage", "state": { "branch": null, - "revision": "f8b8ed0be39d2f4aa00a6e8d3b18a62a94eff8d8", - "version": "4.0.0" + "revision": "c97f83e771c95186af80ef6118f158852a9e54be", + "version": "4.0.1" } }, { @@ -51,8 +51,8 @@ "repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay", "state": { "branch": null, - "revision": "50a70a9d3583fe228ce672e8923010c8df2deddd", - "version": "0.2.1" + "revision": "ef8e14e7ce1c0c304c644c6ba365d06c468ded6b", + "version": "0.3.3" } } ] diff --git a/Package.swift b/Package.swift index c6ab206b..4770168e 100644 --- a/Package.swift +++ b/Package.swift @@ -22,8 +22,8 @@ let package = Package( from: "1.0.0" ), .package( - name: "AttributedText", - url: "https://github.com/gonzalezreal/AttributedText", + name: "FlexibleAttributedText", + url: "https://github.com/wilmaplus/FlexibleAttributedText", from: "1.0.0" ), .package( @@ -43,7 +43,7 @@ let package = Package( name: "MarkdownUI", dependencies: [ .product(name: "CommonMark", package: "SwiftCommonMark"), - "AttributedText", + "FlexibleAttributedText", "NetworkImage", .product(name: "CombineSchedulers", package: "combine-schedulers"), ] diff --git a/Sources/MarkdownUI/Markdown.swift b/Sources/MarkdownUI/Markdown.swift index c8494c4a..fc5ac2c7 100644 --- a/Sources/MarkdownUI/Markdown.swift +++ b/Sources/MarkdownUI/Markdown.swift @@ -1,4 +1,4 @@ -import AttributedText +import FlexibleAttributedText import Combine import CombineSchedulers @_exported import CommonMark @@ -227,7 +227,7 @@ public struct Markdown: View { } public var body: some View { - AttributedText(self.viewState.attributedString, onOpenLink: openMarkdownLink?.handler) + FlexibleAttributedText(self.viewState.attributedString, onOpenLink: openMarkdownLink?.handler, flexibleWidth: style.measurements.flexibleWidth) .onReceive(self.viewStatePublisher) { viewState in self.viewState = viewState } diff --git a/Sources/MarkdownUI/Style/Measurements.swift b/Sources/MarkdownUI/Style/Measurements.swift index 5ef12592..9654413c 100644 --- a/Sources/MarkdownUI/Style/Measurements.swift +++ b/Sources/MarkdownUI/Style/Measurements.swift @@ -26,6 +26,8 @@ extension MarkdownStyle { /// The distance between the bottom of a heading and the top of the next block, relative to the base font size. public var headingSpacing: CGFloat + + public var flexibleWidth: Bool /// Creates a `Measurements` instance. /// - Parameters: @@ -39,6 +41,7 @@ extension MarkdownStyle { /// - headingScales: The scale that the `Markdown` view applies to each heading level. /// - headingSpacing: The distance between the bottom of a heading and the top of the next block, /// relative to the base font size. The default is `0.67`. + /// - flexibleWidth: Flexible width does not take full width of available space public init( codeFontScale: CGFloat = 0.94, headIndentStep: CGFloat = 1.97, @@ -46,7 +49,8 @@ extension MarkdownStyle { paragraphSpacing: CGFloat = 1, listMarkerSpacing: CGFloat = 0.47, headingScales: HeadingScales = .default, - headingSpacing: CGFloat = 0.67 + headingSpacing: CGFloat = 0.67, + flexibleWidth: Bool = false ) { self.codeFontScale = codeFontScale self.headIndentStep = headIndentStep @@ -55,6 +59,7 @@ extension MarkdownStyle { self.listMarkerSpacing = listMarkerSpacing self.headingScales = headingScales self.headingSpacing = headingSpacing + self.flexibleWidth = flexibleWidth } } }