@onekeyfe/react-native-native-list 6.8.0-3 → 6.8.0-31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +3 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +18 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +12 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +166 -36
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +8 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +6 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +21 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +24 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListRowUpdates.kt +34 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +11 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +71 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +126 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +84 -9
- package/android/src/main/res/values/native_scroll_coordinator_ids.xml +1 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentitySubtitleBindingTest.kt +177 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +2 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +130 -0
- package/docs/ROW_TEMPLATES.md +8 -1
- package/docs/SPEC.md +312 -5
- package/docs/STYLE_SPEC.md +7 -1
- package/ios/NativeListAccessoryStack.swift +22 -0
- package/ios/NativeListActivityDetailsView.swift +45 -1
- package/ios/NativeListDataRowRenderer.swift +12 -5
- package/ios/NativeListIdentityRenderer.swift +145 -66
- package/ios/NativeListLeadingVisual.swift +8 -0
- package/ios/NativeListMarketRenderer.swift +6 -2
- package/ios/NativeListModels.swift +7 -0
- package/ios/NativeListResolvedText.swift +9 -7
- package/ios/NativeListSectionHeaderRenderer.swift +9 -43
- package/ios/NativeListTextStyles.swift +72 -12
- package/ios/NativeListTitleSegmentLayout.swift +72 -0
- package/ios/NativeListTitleSegmentsLabel.swift +92 -0
- package/ios/RNCNativeListView.swift +203 -45
- package/ios/tests/NativeListActivityPresentationTests.swift +137 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +155 -0
- package/ios/tests/NativeListLifecycleTests.swift +298 -24
- package/ios/tests/NativeListMediaVisibilityTests.swift +2 -1
- package/lib/module/models.js +2 -0
- package/lib/module/validation.js +96 -13
- package/lib/module/web/NativeListWebEngine.js +427 -100
- package/lib/module/web/templates/ActivityRowRenderer.js +1 -1
- package/lib/module/web/templates/IdentityRowRenderer.js +134 -3
- package/lib/module/web/templates/MarketRowRenderer.js +2 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +1 -0
- package/lib/module/web/templates/RowElements.js +2 -2
- package/lib/module/web/templates/RowText.js +2 -0
- package/lib/typescript/src/models.d.ts +35 -1
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +17 -2
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +6 -2
- package/lib/typescript/src/web/templates/RowVisual.d.ts +1 -1
- package/package.json +1 -1
- package/src/models.ts +38 -0
- package/src/validation.ts +196 -6
- package/src/web/NativeListWebEngine.ts +671 -112
- package/src/web/templates/ActivityRowRenderer.ts +1 -1
- package/src/web/templates/IdentityRowRenderer.ts +208 -3
- package/src/web/templates/MarketRowRenderer.ts +2 -0
- package/src/web/templates/MediaTileRowRenderer.ts +1 -0
- package/src/web/templates/RowElements.ts +3 -2
- package/src/web/templates/RowText.ts +6 -0
- package/src/web/templates/RowVisual.ts +2 -1
|
@@ -784,50 +784,16 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
|
|
|
784
784
|
)
|
|
785
785
|
}
|
|
786
786
|
}
|
|
787
|
-
private func selectorTabularFont(_ font: UIFont) -> UIFont {
|
|
788
|
-
var settings =
|
|
789
|
-
font.fontDescriptor.fontAttributes[.featureSettings] as? [[UIFontDescriptor.FeatureKey: Int]]
|
|
790
|
-
?? []
|
|
791
|
-
settings.removeAll { $0[.type] == kNumberSpacingType }
|
|
792
|
-
settings.append([.type: kNumberSpacingType, .selector: kMonospacedNumbersSelector])
|
|
793
|
-
return UIFont(
|
|
794
|
-
descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]),
|
|
795
|
-
size: font.pointSize)
|
|
796
|
-
}
|
|
797
|
-
private func selectorTabularText(_ original: NSAttributedString) -> NSAttributedString {
|
|
798
|
-
let result = NSMutableAttributedString(attributedString: original)
|
|
799
|
-
// OneKey patch: body typography explicitly supplies letterSpacing=0 in Tamagui.
|
|
800
|
-
result.addAttribute(.kern, value: 0, range: NSRange(location: 0, length: result.length))
|
|
801
|
-
original.enumerateAttribute(.font, in: NSRange(location: 0, length: original.length)) {
|
|
802
|
-
value, range, _ in
|
|
803
|
-
if let font = value as? UIFont {
|
|
804
|
-
result.addAttribute(.font, value: self.selectorTabularFont(font), range: range)
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
return result
|
|
808
|
-
}
|
|
809
787
|
private func applySelectorTypography(_ item: NativeListItem) {
|
|
810
|
-
guard
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
820
|
-
} else if let label = view as? UILabel, let font = label.font {
|
|
821
|
-
let original = label.attributedText
|
|
822
|
-
selectorTypographyRestorers.append {
|
|
823
|
-
label.font = font
|
|
824
|
-
label.attributedText = original
|
|
825
|
-
}
|
|
826
|
-
label.font = selectorTabularFont(font)
|
|
827
|
-
if let original { label.attributedText = selectorTabularText(original) }
|
|
828
|
-
}
|
|
829
|
-
for child in view.subviews { visit(child) }
|
|
788
|
+
guard ["accountSelector", "networkSelector", "walletSidebar"].contains(
|
|
789
|
+
item.data.string("presentation")
|
|
790
|
+
) else { return }
|
|
791
|
+
let style = item.data.dictionary("style") ?? [:]
|
|
792
|
+
selectorTypographyRestorers = NativeListTextStyles.applySelectorDefaults(in: contentView) { view in
|
|
793
|
+
if view === titleLabel { return style.dictionary("title") }
|
|
794
|
+
if view === subtitleLabel { return style.dictionary("subtitle") }
|
|
795
|
+
if view === accessoryButtons[0] { return style.dictionary("value") }
|
|
796
|
+
return nil
|
|
830
797
|
}
|
|
831
|
-
visit(contentView)
|
|
832
798
|
}
|
|
833
799
|
}
|
|
@@ -56,7 +56,12 @@ enum NativeListTextStyles {
|
|
|
56
56
|
}
|
|
57
57
|
var attributes: [NSAttributedString.Key: Any] = [:]
|
|
58
58
|
applyStyledFont(attributed, style, fallback: baseFont, fonts: fonts)
|
|
59
|
+
if let tabular = style["tabularNumbers"] as? Bool {
|
|
60
|
+
applyDigitSpacing(attributed, tabular: tabular, fallback: font)
|
|
61
|
+
}
|
|
59
62
|
if style["color"] != nil { attributes[.foregroundColor] = color }
|
|
63
|
+
// An explicit 0 still sets kern, which disables pair kerning like React Native.
|
|
64
|
+
if style["letterSpacing"] != nil { attributes[.kern] = CGFloat(style.double("letterSpacing")) }
|
|
60
65
|
if style["alignment"] != nil || style["lines"] != nil || style["truncate"] != nil
|
|
61
66
|
|| style["lineHeight"] != nil
|
|
62
67
|
{
|
|
@@ -121,7 +126,11 @@ enum NativeListTextStyles {
|
|
|
121
126
|
}
|
|
122
127
|
var attributes: [NSAttributedString.Key: Any] = [:]
|
|
123
128
|
applyStyledFont(attributed, style, fallback: baseFont, fonts: fonts)
|
|
129
|
+
if let tabular = style["tabularNumbers"] as? Bool {
|
|
130
|
+
applyDigitSpacing(attributed, tabular: tabular, fallback: font)
|
|
131
|
+
}
|
|
124
132
|
if style["color"] != nil { attributes[.foregroundColor] = color }
|
|
133
|
+
if style["letterSpacing"] != nil { attributes[.kern] = CGFloat(style.double("letterSpacing")) }
|
|
125
134
|
if style["alignment"] != nil || style["lineHeight"] != nil || style["lines"] != nil
|
|
126
135
|
|| style["truncate"] != nil
|
|
127
136
|
{
|
|
@@ -202,33 +211,84 @@ enum NativeListTextStyles {
|
|
|
202
211
|
}
|
|
203
212
|
}
|
|
204
213
|
|
|
205
|
-
/// Legacy selector/warning
|
|
214
|
+
/// Legacy selector/warning defaults: monospaced digits and zero tracking.
|
|
206
215
|
static func applyTabularDigits(_ label: UILabel) {
|
|
207
216
|
guard let font = label.font else { return }
|
|
208
|
-
label.font =
|
|
209
|
-
|
|
217
|
+
label.font = digitSpacingFont(font, tabular: true)
|
|
218
|
+
if let original = label.attributedText {
|
|
219
|
+
label.attributedText = selectorText(original, explicit: nil, fallback: font)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static func selectorText(
|
|
224
|
+
_ original: NSAttributedString, explicit: [String: Any]?, fallback: UIFont
|
|
225
|
+
) -> NSAttributedString {
|
|
210
226
|
let result = NSMutableAttributedString(attributedString: original)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
227
|
+
if explicit?["letterSpacing"] == nil {
|
|
228
|
+
result.addAttribute(.kern, value: 0, range: NSRange(location: 0, length: result.length))
|
|
229
|
+
}
|
|
230
|
+
if explicit?["tabularNumbers"] == nil {
|
|
231
|
+
applyDigitSpacing(result, tabular: true, fallback: fallback)
|
|
232
|
+
}
|
|
233
|
+
return result
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/// Apply the feature to each run without changing its weight or size.
|
|
237
|
+
static func applyDigitSpacing(
|
|
238
|
+
_ text: NSMutableAttributedString, tabular: Bool, fallback: UIFont
|
|
239
|
+
) {
|
|
240
|
+
let range = NSRange(location: 0, length: text.length)
|
|
241
|
+
var runs: [(NSRange, UIFont)] = []
|
|
242
|
+
text.enumerateAttribute(.font, in: range) { value, run, _ in
|
|
243
|
+
runs.append((run, (value as? UIFont) ?? fallback))
|
|
244
|
+
}
|
|
245
|
+
for (run, font) in runs {
|
|
246
|
+
text.addAttribute(.font, value: digitSpacingFont(font, tabular: tabular), range: run)
|
|
217
247
|
}
|
|
218
|
-
label.attributedText = result
|
|
219
248
|
}
|
|
220
249
|
|
|
221
|
-
static func
|
|
250
|
+
static func digitSpacingFont(_ font: UIFont, tabular: Bool) -> UIFont {
|
|
222
251
|
var settings =
|
|
223
252
|
font.fontDescriptor.fontAttributes[.featureSettings] as? [[UIFontDescriptor.FeatureKey: Int]]
|
|
224
253
|
?? []
|
|
225
254
|
settings.removeAll { $0[.type] == kNumberSpacingType }
|
|
226
|
-
settings.append([
|
|
255
|
+
settings.append([
|
|
256
|
+
.type: kNumberSpacingType,
|
|
257
|
+
.selector: tabular ? kMonospacedNumbersSelector : kProportionalNumbersSelector,
|
|
258
|
+
])
|
|
227
259
|
return UIFont(
|
|
228
260
|
descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]),
|
|
229
261
|
size: font.pointSize)
|
|
230
262
|
}
|
|
231
263
|
|
|
264
|
+
static func applySelectorDefaults(
|
|
265
|
+
in root: UIView, explicitStyle: (UIView) -> [String: Any]?
|
|
266
|
+
) -> [() -> Void] {
|
|
267
|
+
var restorers: [() -> Void] = []
|
|
268
|
+
func visit(_ view: UIView, inherited: [String: Any]? = nil) {
|
|
269
|
+
let style = explicitStyle(view) ?? inherited
|
|
270
|
+
if let button = view as? UIButton,
|
|
271
|
+
let original = button.attributedTitle(for: .normal),
|
|
272
|
+
let font = button.titleLabel?.font {
|
|
273
|
+
restorers.append { button.setAttributedTitle(original, for: .normal) }
|
|
274
|
+
button.setAttributedTitle(selectorText(original, explicit: style, fallback: font), for: .normal)
|
|
275
|
+
} else if let label = view as? UILabel, let font = label.font {
|
|
276
|
+
let original = label.attributedText
|
|
277
|
+
restorers.append {
|
|
278
|
+
label.font = font
|
|
279
|
+
label.attributedText = original
|
|
280
|
+
}
|
|
281
|
+
if style?["tabularNumbers"] == nil { label.font = digitSpacingFont(font, tabular: true) }
|
|
282
|
+
if let original {
|
|
283
|
+
label.attributedText = selectorText(original, explicit: style, fallback: font)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
for child in view.subviews { visit(child, inherited: style) }
|
|
287
|
+
}
|
|
288
|
+
visit(root)
|
|
289
|
+
return restorers
|
|
290
|
+
}
|
|
291
|
+
|
|
232
292
|
static func marketTextAlignment(_ value: String, direction: UIUserInterfaceLayoutDirection)
|
|
233
293
|
-> NSTextAlignment
|
|
234
294
|
{
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Widths for identity title runs (docs/SPEC.md, "Identity title segments
|
|
4
|
+
/// and leading title icon"). A run's base width is its natural width under
|
|
5
|
+
/// its cap; the one shrinking run takes what the others leave; runs that do
|
|
6
|
+
/// not shrink and still overflow are cut from the end of the line.
|
|
7
|
+
func nativeListTitleSegmentWidths(
|
|
8
|
+
natural: [CGFloat],
|
|
9
|
+
shrink: [Bool],
|
|
10
|
+
maxWidthRatio: [CGFloat?],
|
|
11
|
+
available: CGFloat
|
|
12
|
+
) -> [CGFloat] {
|
|
13
|
+
let line = max(0, available)
|
|
14
|
+
var widths = natural.indices.map { index -> CGFloat in
|
|
15
|
+
let width = max(0, natural[index])
|
|
16
|
+
guard index < maxWidthRatio.count, let ratio = maxWidthRatio[index] else { return width }
|
|
17
|
+
return min(width, ratio * line)
|
|
18
|
+
}
|
|
19
|
+
if let shrinking = shrink.firstIndex(of: true), shrinking < widths.count {
|
|
20
|
+
let others = widths.indices.reduce(CGFloat(0)) { $1 == shrinking ? $0 : $0 + widths[$1] }
|
|
21
|
+
widths[shrinking] = max(0, min(widths[shrinking], line - others))
|
|
22
|
+
}
|
|
23
|
+
var overflow = widths.reduce(0, +) - line
|
|
24
|
+
var index = widths.count - 1
|
|
25
|
+
while overflow > 0, index >= 0 {
|
|
26
|
+
let cut = min(widths[index], overflow)
|
|
27
|
+
widths[index] -= cut
|
|
28
|
+
overflow -= cut
|
|
29
|
+
index -= 1
|
|
30
|
+
}
|
|
31
|
+
return widths
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// Wallet sidebar rows keep the plain title: no runs and no leading glyph
|
|
35
|
+
/// (docs/SPEC.md).
|
|
36
|
+
func nativeListAllowsTitleDecorations(presentation: String) -> Bool {
|
|
37
|
+
presentation != "walletSidebar"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Whether the runs replace `title`: not where `title` itself is highlighted
|
|
41
|
+
/// (`titleMatch` indexes it), and never on a wallet sidebar row. Measurement
|
|
42
|
+
/// and binding share this, so a row is sized for the title it draws.
|
|
43
|
+
func nativeListShowsTitleRuns(presentation: String, runCount: Int, matchCount: Int) -> Bool {
|
|
44
|
+
runCount > 0 && matchCount == 0 && nativeListAllowsTitleDecorations(presentation: presentation)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// The run that has to end with an ellipsis because the line was cut exactly
|
|
48
|
+
/// after it: a run that does not shrink lost its whole width, and this one is
|
|
49
|
+
/// drawn in full, so nothing else would show that the title goes on. Nil when
|
|
50
|
+
/// the line is not cut, when it is cut inside a run, which then truncates by
|
|
51
|
+
/// itself, and when only the shrinking run gave up its width, which it may.
|
|
52
|
+
func nativeListTitleSegmentOverflowIndex(
|
|
53
|
+
natural: [CGFloat], shrink: [Bool], widths: [CGFloat]
|
|
54
|
+
) -> Int? {
|
|
55
|
+
guard let last = widths.lastIndex(where: { $0 > 0 }), last < natural.count else { return nil }
|
|
56
|
+
let cutsAFixedRun = natural.indices.contains {
|
|
57
|
+
$0 > last && natural[$0] > 0 && !($0 < shrink.count && shrink[$0])
|
|
58
|
+
}
|
|
59
|
+
return cutsAFixedRun && widths[last] >= natural[last] ? last : nil
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// Width the leading title glyph takes from the title text: its 16 points and
|
|
63
|
+
/// the 6-point gap. Zero where the row keeps a plain title (docs/SPEC.md).
|
|
64
|
+
func nativeListTitleLeadingIconWidth(presentation: String, hasIcon: Bool) -> CGFloat {
|
|
65
|
+
hasIcon && nativeListAllowsTitleDecorations(presentation: presentation) ? 22 : 0
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// A run is one line: a hard break folds into one space, as in a one-line
|
|
69
|
+
/// title.
|
|
70
|
+
func nativeListTitleRunText(_ text: String) -> String {
|
|
71
|
+
text.replacingOccurrences(of: "\r\n|[\r\n]", with: " ", options: .regularExpression)
|
|
72
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// Draws identity title runs on one line, each at the width that
|
|
4
|
+
/// `nativeListTitleSegmentWidths` allocates for the current bounds. Its
|
|
5
|
+
/// intrinsic width is the runs' natural width, so the title row stack can
|
|
6
|
+
/// give it less, and accessibility reads the row's `title` instead of runs.
|
|
7
|
+
final class NativeListTitleSegmentsLabel: UIView {
|
|
8
|
+
struct Run {
|
|
9
|
+
let text: String
|
|
10
|
+
let font: UIFont
|
|
11
|
+
let color: UIColor
|
|
12
|
+
let shrink: Bool
|
|
13
|
+
let maxWidthRatio: CGFloat?
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private var runs: [Run] = []
|
|
17
|
+
private var naturalWidths: [CGFloat] = []
|
|
18
|
+
var lineHeight: CGFloat = 24 {
|
|
19
|
+
didSet {
|
|
20
|
+
invalidateIntrinsicContentSize()
|
|
21
|
+
setNeedsDisplay()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/// `style.title.offsetY`: moves the drawn runs, not the line they sit on.
|
|
25
|
+
var offsetY: CGFloat = 0 { didSet { setNeedsDisplay() } }
|
|
26
|
+
|
|
27
|
+
override init(frame: CGRect) {
|
|
28
|
+
super.init(frame: frame)
|
|
29
|
+
isOpaque = false
|
|
30
|
+
backgroundColor = .clear
|
|
31
|
+
contentMode = .redraw
|
|
32
|
+
isAccessibilityElement = true
|
|
33
|
+
accessibilityTraits = .staticText
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
|
|
37
|
+
|
|
38
|
+
func configure(_ runs: [Run], spokenText: String) {
|
|
39
|
+
self.runs = runs
|
|
40
|
+
naturalWidths = runs.map {
|
|
41
|
+
ceil(($0.text as NSString).size(withAttributes: [.font: $0.font]).width)
|
|
42
|
+
}
|
|
43
|
+
accessibilityLabel = spokenText.isEmpty ? nil : spokenText
|
|
44
|
+
invalidateIntrinsicContentSize()
|
|
45
|
+
setNeedsDisplay()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func reset() {
|
|
49
|
+
offsetY = 0
|
|
50
|
+
configure([], spokenText: "")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override var intrinsicContentSize: CGSize {
|
|
54
|
+
CGSize(width: naturalWidths.reduce(0, +), height: lineHeight)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override func layoutSubviews() {
|
|
58
|
+
super.layoutSubviews()
|
|
59
|
+
setNeedsDisplay()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override func draw(_ rect: CGRect) {
|
|
63
|
+
guard !runs.isEmpty else { return }
|
|
64
|
+
let widths = nativeListTitleSegmentWidths(
|
|
65
|
+
natural: naturalWidths, shrink: runs.map(\.shrink),
|
|
66
|
+
maxWidthRatio: runs.map(\.maxWidthRatio), available: bounds.width)
|
|
67
|
+
let overflowing = nativeListTitleSegmentOverflowIndex(
|
|
68
|
+
natural: naturalWidths, shrink: runs.map(\.shrink), widths: widths)
|
|
69
|
+
let isRightToLeft = effectiveUserInterfaceLayoutDirection == .rightToLeft
|
|
70
|
+
var x: CGFloat = isRightToLeft ? bounds.width : 0
|
|
71
|
+
for (index, (run, width)) in zip(runs, widths).enumerated() where width > 0 {
|
|
72
|
+
let paragraph = NSMutableParagraphStyle()
|
|
73
|
+
paragraph.lineBreakMode = .byTruncatingTail
|
|
74
|
+
// Text after this run is hidden: one character more than fits makes the
|
|
75
|
+
// tail truncation show it. A run too narrow for the ellipsis itself is
|
|
76
|
+
// drawn whole instead.
|
|
77
|
+
let ellipsis = "\u{2026}"
|
|
78
|
+
let showsOverflow = index == overflowing
|
|
79
|
+
&& width >= ceil((ellipsis as NSString).size(withAttributes: [.font: run.font]).width)
|
|
80
|
+
let text = NSAttributedString(
|
|
81
|
+
string: showsOverflow ? run.text + ellipsis : run.text,
|
|
82
|
+
attributes: [.font: run.font, .foregroundColor: run.color, .paragraphStyle: paragraph])
|
|
83
|
+
let height = ceil(run.font.lineHeight)
|
|
84
|
+
let originX = isRightToLeft ? x - width : x
|
|
85
|
+
text.draw(
|
|
86
|
+
with: CGRect(
|
|
87
|
+
x: originX, y: (bounds.height - height) / 2 + offsetY, width: width, height: height),
|
|
88
|
+
options: [.usesLineFragmentOrigin, .truncatesLastVisibleLine], context: nil)
|
|
89
|
+
x += isRightToLeft ? -width : width
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|