@nativue/core 0.15.4 → 0.17.0
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/AGENTS.md +18 -4
- package/android/nativue.settings.gradle.kts +29 -9
- package/android/src/main/java/dev/nativue/BackgroundGradients.kt +111 -0
- package/android/src/main/java/dev/nativue/BoxDrawable.kt +49 -9
- package/android/src/main/java/dev/nativue/Bridge.kt +6 -16
- package/android/src/main/java/dev/nativue/NativeNode.kt +4 -0
- package/android/src/main/java/dev/nativue/Navigation.kt +31 -37
- package/android/src/main/java/dev/nativue/NavigationIcons.kt +24 -0
- package/android/src/main/java/dev/nativue/Plugins.kt +13 -1
- package/android/src/main/java/dev/nativue/Style.kt +81 -3
- package/android/src/main/java/dev/nativue/Views.kt +70 -33
- package/android/src/main/res/drawable/nativue_arrow_back.xml +14 -0
- package/android/src/main/res/drawable/nativue_close.xml +14 -0
- package/cli/ios-project.mjs +1 -1
- package/cli/link.mjs +25 -6
- package/cli/nativue.mjs +0 -1
- package/ios/BackgroundGradients.swift +191 -0
- package/ios/Bridge.swift +14 -20
- package/ios/ImageView.swift +32 -10
- package/ios/NativeNode.swift +19 -2
- package/ios/NavigationIcons.swift +49 -0
- package/ios/Plugins.swift +13 -1
- package/ios/PressableView.swift +3 -1
- package/ios/ScreenController.swift +6 -3
- package/ios/Style.swift +76 -14
- package/ios/VueScrollView.swift +1 -0
- package/package.json +2 -2
- package/src/colors.ts +10 -6
- package/src/gradients.ts +304 -0
- package/src/native-components.ts +0 -14
- package/src/renderer.ts +203 -12
- package/src/router.ts +20 -7
- package/src/types.ts +18 -0
- package/android/src/main/java/dev/nativue/SvgView.kt +0 -443
- package/ios/SvgView.swift +0 -464
package/ios/ImageView.swift
CHANGED
|
@@ -32,7 +32,7 @@ final class ImageView: UIImageView {
|
|
|
32
32
|
/// The image changed, and with it the size the view measures.
|
|
33
33
|
var onImageChange: (() -> Void)?
|
|
34
34
|
|
|
35
|
-
/// "disk", "memory" or "none". Read
|
|
35
|
+
/// "disk", "memory" or "none". Read once loading starts, so it applies even when set after `source`.
|
|
36
36
|
var cachePolicy = "disk"
|
|
37
37
|
|
|
38
38
|
private var loadingTask: Task<Void, Never>?
|
|
@@ -57,28 +57,45 @@ final class ImageView: UIImageView {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
show(nil)
|
|
60
|
-
let readsDisk = cachePolicy == "disk"
|
|
61
60
|
loadingTask = Task { [weak self] in
|
|
62
|
-
let cachedData = readsDisk ? await Task.detached { ImageDiskCache.data(for: source) }.value : nil
|
|
63
|
-
let downloadedData = cachedData == nil ? await Self.download(source, from: url) : nil
|
|
64
61
|
guard
|
|
65
|
-
let
|
|
66
|
-
let image = await
|
|
62
|
+
let cachePolicy = self?.cachePolicy,
|
|
63
|
+
let image = await Self.image(for: source, from: url, cachePolicy: cachePolicy),
|
|
67
64
|
!Task.isCancelled,
|
|
68
65
|
let self
|
|
69
66
|
else { return }
|
|
70
67
|
|
|
71
|
-
store(image, downloadedData: downloadedData, for: source)
|
|
72
68
|
show(image)
|
|
73
69
|
}
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
|
|
72
|
+
/// An image as <Image> loads it: from memory, the disk cache or its url, then kept as `cachePolicy` says.
|
|
73
|
+
static func image(for source: String, cachePolicy: String = "disk") async -> UIImage? {
|
|
74
|
+
if cachePolicy != "none", let cachedImage = decodedImages.object(forKey: source as NSString) { return cachedImage }
|
|
75
|
+
guard let url = URL(string: source) else { return nil }
|
|
76
|
+
|
|
77
|
+
return await image(for: source, from: url, cachePolicy: cachePolicy)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private static func image(for source: String, from url: URL, cachePolicy: String) async -> UIImage? {
|
|
81
|
+
let cachedData = cachePolicy == "disk" ? await Task.detached { ImageDiskCache.data(for: source) }.value : nil
|
|
82
|
+
let downloadedData = cachedData == nil ? await download(source, from: url) : nil
|
|
83
|
+
guard
|
|
84
|
+
let data = cachedData ?? downloadedData,
|
|
85
|
+
let image = await UIImage(data: data)?.byPreparingForDisplay() // decoded off the main thread
|
|
86
|
+
else { return nil }
|
|
87
|
+
|
|
88
|
+
store(image, downloadedData: downloadedData, for: source, cachePolicy: cachePolicy)
|
|
89
|
+
|
|
90
|
+
return image
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private static func store(_ image: UIImage, downloadedData: Data?, for source: String, cachePolicy: String) {
|
|
77
94
|
guard cachePolicy != "none" else { return }
|
|
78
95
|
|
|
79
|
-
|
|
96
|
+
decodedImages.setObject(image, forKey: source as NSString, cost: byteCount(of: image))
|
|
80
97
|
|
|
81
|
-
guard cachePolicy == "disk", let downloadedData, !
|
|
98
|
+
guard cachePolicy == "disk", let downloadedData, !isInMemory(source) else { return }
|
|
82
99
|
Task.detached(priority: .utility) { ImageDiskCache.store(downloadedData, for: source) }
|
|
83
100
|
}
|
|
84
101
|
|
|
@@ -130,6 +147,11 @@ final class ImageView: UIImageView {
|
|
|
130
147
|
}
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
/// An image loaded and cached as <Image> does it: for a package's views.
|
|
151
|
+
public func loadImage(_ source: String) async -> UIImage? {
|
|
152
|
+
await ImageView.image(for: source)
|
|
153
|
+
}
|
|
154
|
+
|
|
133
155
|
/// Downloaded images by url, in the system's caches folder, which iOS may empty when storage runs low. Past
|
|
134
156
|
/// its limit, the images used least recently go first.
|
|
135
157
|
private enum ImageDiskCache {
|
package/ios/NativeNode.swift
CHANGED
|
@@ -24,8 +24,17 @@ final class NativeNode {
|
|
|
24
24
|
var defaultFontSize: CGFloat = UIFont.labelFontSize
|
|
25
25
|
var fontSize: CGFloat = UIFont.labelFontSize
|
|
26
26
|
var fontWeight: UIFont.Weight = .regular
|
|
27
|
+
var isItalic = false
|
|
28
|
+
/// The text's attributes a label keeps in its attributed text (updateTextAttributes).
|
|
27
29
|
/// textDecorationLine: 'none', 'underline', 'line-through' or both.
|
|
28
30
|
var textDecorationLine = "none"
|
|
31
|
+
/// letterSpacing and lineHeight: points, or ems of the font size ('1.5em'); nil for the font's own.
|
|
32
|
+
var letterSpacing: Any?
|
|
33
|
+
var lineHeight: Any?
|
|
34
|
+
|
|
35
|
+
var hasTextAttributes: Bool {
|
|
36
|
+
textDecorationLine != "none" || letterSpacing != nil || lineHeight != nil
|
|
37
|
+
}
|
|
29
38
|
|
|
30
39
|
/// Leaf nodes (Text, Button) measure their own content; containers are sized by their children.
|
|
31
40
|
init(view: UIView, measuresContent: Bool) {
|
|
@@ -142,6 +151,7 @@ final class NativeNode {
|
|
|
142
151
|
place(childView, at: frame)
|
|
143
152
|
}
|
|
144
153
|
childView.applyCornerRadius()
|
|
154
|
+
childView.applyBackgroundGradients()
|
|
145
155
|
|
|
146
156
|
applyFrames(of: child)
|
|
147
157
|
|
|
@@ -221,10 +231,17 @@ private func measureView(
|
|
|
221
231
|
@MainActor private func singleLineSize(of label: UILabel, maxWidth: CGFloat) -> CGSize? {
|
|
222
232
|
guard let text = label.text, !text.contains(where: \.isNewline) else { return nil }
|
|
223
233
|
|
|
224
|
-
|
|
234
|
+
// Its attributes too: letter spacing widens the line, a line height sets its height.
|
|
235
|
+
let attributedText = label.attributedText ?? NSAttributedString(string: text, attributes: [.font: label.font!])
|
|
225
236
|
let line = CTLineCreateWithAttributedString(attributedText)
|
|
226
237
|
let width = ceil(CTLineGetTypographicBounds(line, nil, nil, nil))
|
|
227
238
|
guard width <= maxWidth else { return nil }
|
|
228
239
|
|
|
229
|
-
|
|
240
|
+
let paragraphStyle = attributedText.length > 0
|
|
241
|
+
? attributedText.attribute(.paragraphStyle, at: 0, effectiveRange: nil) as? NSParagraphStyle
|
|
242
|
+
: nil
|
|
243
|
+
|
|
244
|
+
let lineHeight = paragraphStyle.map(\.minimumLineHeight).flatMap { $0 > 0 ? $0 : nil } ?? label.font.lineHeight
|
|
245
|
+
|
|
246
|
+
return CGSize(width: width, height: ceil(lineHeight))
|
|
230
247
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// The icons of tab bars and headers: an SF Symbol (`systemImage`), an image (`image`, a url), or one a
|
|
4
|
+
/// package draws (`drawnIcon`, registered with PluginRegistry.addIconDrawer). Tinted by what shows them.
|
|
5
|
+
enum NavigationIcons {
|
|
6
|
+
static var drawersByName: [String: PluginRegistry.DrawIcon] = [:]
|
|
7
|
+
/// The url each item (a tab, a header button) shows last: a slower load of an earlier one is dropped.
|
|
8
|
+
private static let sourcesByOwner = NSMapTable<AnyObject, NSString>.weakToStrongObjects()
|
|
9
|
+
|
|
10
|
+
/// The icon now, or nil with `update` called (on the main thread) once an image loads, if `owner` still
|
|
11
|
+
/// shows that image then.
|
|
12
|
+
static func image(
|
|
13
|
+
_ item: [String: Any], size: CGFloat, for owner: AnyObject, update: @escaping (UIImage) -> Void
|
|
14
|
+
) -> UIImage? {
|
|
15
|
+
sourcesByOwner.setObject((item["image"] as? String) as NSString?, forKey: owner)
|
|
16
|
+
if let name = item["systemImage"] as? String { return UIImage(systemName: name) }
|
|
17
|
+
if let source = item["image"] as? String {
|
|
18
|
+
Task { @MainActor [weak owner] in
|
|
19
|
+
guard
|
|
20
|
+
let image = await loadImage(source),
|
|
21
|
+
let owner,
|
|
22
|
+
sourcesByOwner.object(forKey: owner) as String? == source
|
|
23
|
+
else { return }
|
|
24
|
+
|
|
25
|
+
update(fitted(image, size: size))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return nil
|
|
29
|
+
}
|
|
30
|
+
guard
|
|
31
|
+
let icon = item["drawnIcon"] as? [String: Any],
|
|
32
|
+
let drawer = icon["drawer"] as? String,
|
|
33
|
+
let draw = drawersByName[drawer]
|
|
34
|
+
else { return nil }
|
|
35
|
+
|
|
36
|
+
return draw(icon, size)?.withRenderingMode(.alwaysTemplate)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// Scaled to fit a square of `size` points, as the bar expects.
|
|
40
|
+
private static func fitted(_ image: UIImage, size: CGFloat) -> UIImage {
|
|
41
|
+
let scale = min(size / max(image.size.width, 1), size / max(image.size.height, 1))
|
|
42
|
+
let fittedSize = CGSize(width: image.size.width * scale, height: image.size.height * scale)
|
|
43
|
+
let fittedImage = UIGraphicsImageRenderer(size: fittedSize).image { _ in
|
|
44
|
+
image.draw(in: CGRect(origin: .zero, size: fittedSize))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return fittedImage.withRenderingMode(.alwaysTemplate)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/ios/Plugins.swift
CHANGED
|
@@ -14,6 +14,8 @@ public final class PluginRegistry {
|
|
|
14
14
|
/// sendEvent("change", payload) reaches the element's @change; event names are lowercase.
|
|
15
15
|
public typealias SendEvent = (_ eventName: String, _ payload: Any?) -> Void
|
|
16
16
|
public typealias MakeView = (_ sendEvent: @escaping SendEvent) -> UIView
|
|
17
|
+
/// An icon JS describes ({ drawer, ... }) drawn at `size` points, for a tab bar or a header.
|
|
18
|
+
public typealias DrawIcon = (_ icon: [String: Any], _ size: CGFloat) -> UIImage?
|
|
17
19
|
|
|
18
20
|
/// Set by the Bridge: calls JavaScript's listeners.
|
|
19
21
|
var sendToJavaScript: (_ eventName: String, _ payload: Any?) -> Void = { _, _ in }
|
|
@@ -47,8 +49,18 @@ public final class PluginRegistry {
|
|
|
47
49
|
public func addView(_ type: String, _ makeView: @escaping MakeView) {
|
|
48
50
|
viewMakers[type] = makeView
|
|
49
51
|
}
|
|
52
|
+
|
|
53
|
+
/// Draws the tab bar and header icons whose `drawnIcon.drawer` is `drawer` (see router.ts's DrawnIcon).
|
|
54
|
+
/// The image is tinted, like an SF Symbol: only its shape counts.
|
|
55
|
+
public func addIconDrawer(_ drawer: String, _ draw: @escaping DrawIcon) {
|
|
56
|
+
NavigationIcons.drawersByName[drawer] = draw
|
|
57
|
+
}
|
|
50
58
|
}
|
|
51
59
|
|
|
60
|
+
/// A plugin view that takes its own touches where `point(inside:with:)` says, which a <Pressable> around it
|
|
61
|
+
/// leaves to it.
|
|
62
|
+
public protocol InteractiveView: UIView {}
|
|
63
|
+
|
|
52
64
|
/// Thrown by an async function: JavaScript's Promise rejects with an Error whose `code` is this one.
|
|
53
65
|
/// Codes nativue's packages share: ERR_PERMISSION_DENIED, ERR_UNAVAILABLE, ERR_CANCELED,
|
|
54
66
|
/// ERR_INVALID_ARGUMENT.
|
|
@@ -64,7 +76,7 @@ public struct PluginError: LocalizedError {
|
|
|
64
76
|
public var errorDescription: String? { message }
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
/// A plugin view gets its props here, all but `style`, which nativue applies
|
|
79
|
+
/// A plugin view gets its props here, all but `style`, `accessibility`, `@layout` and the gestures (`@pan`...), which nativue applies.
|
|
68
80
|
public protocol PluginView: UIView {
|
|
69
81
|
func setProp(_ key: String, value: Any?)
|
|
70
82
|
}
|
package/ios/PressableView.swift
CHANGED
|
@@ -51,7 +51,9 @@ final class PressableView: UIControl {
|
|
|
51
51
|
private func isInteractiveChild(_ view: UIView) -> Bool {
|
|
52
52
|
sequence(first: view, next: \.superview)
|
|
53
53
|
.prefix { $0 !== self }
|
|
54
|
-
.contains {
|
|
54
|
+
.contains {
|
|
55
|
+
$0 is UIControl || $0 is UIScrollView || $0 is InteractiveView || !($0.gestureRecognizers ?? []).isEmpty
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/// VoiceOver's double tap: a press, even when something interactive sits under the activation point.
|
|
@@ -111,12 +111,15 @@ final class ScreenController: UIViewController, ContentRoot {
|
|
|
111
111
|
|
|
112
112
|
private func makeBarButtonItem(_ description: [String: Any], side: String, index: Int) -> UIBarButtonItem {
|
|
113
113
|
let title = description["title"] as? String ?? ""
|
|
114
|
-
let
|
|
114
|
+
let barButtonItem = UIBarButtonItem()
|
|
115
|
+
let image = NavigationIcons.image(description, size: 22, for: barButtonItem) { [weak barButtonItem] image in
|
|
116
|
+
barButtonItem?.image = image
|
|
117
|
+
}
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
barButtonItem.primaryAction = UIAction(title: title, image: image) { [unowned self] _ in
|
|
117
120
|
onEvent?("headeritempress", ["side": side, "index": index])
|
|
118
121
|
}
|
|
119
122
|
|
|
120
|
-
return
|
|
123
|
+
return barButtonItem
|
|
121
124
|
}
|
|
122
125
|
}
|
package/ios/Style.swift
CHANGED
|
@@ -33,9 +33,15 @@ extension NativeNode {
|
|
|
33
33
|
case "backgroundColor":
|
|
34
34
|
view.backgroundColor = UIColor(rgba: value)
|
|
35
35
|
|
|
36
|
-
case "
|
|
37
|
-
view.
|
|
36
|
+
case "backgroundImage":
|
|
37
|
+
view.setBackgroundGradients(value as? [[String: Any]] ?? [])
|
|
38
|
+
|
|
39
|
+
case "borderRadius", "borderTopLeftRadius", "borderTopRightRadius", "borderBottomLeftRadius", "borderBottomRightRadius":
|
|
40
|
+
var radii = view.layer.value(forKey: UIView.requestedCornerRadiiKey) as? [String: CGFloat] ?? [:]
|
|
41
|
+
radii[property] = number(value).map { CGFloat($0) }
|
|
42
|
+
view.layer.setValue(radii, forKey: UIView.requestedCornerRadiiKey)
|
|
38
43
|
view.applyCornerRadius()
|
|
44
|
+
view.applyBackgroundGradients()
|
|
39
45
|
|
|
40
46
|
case "borderWidth":
|
|
41
47
|
view.layer.borderWidth = CGFloat(number(value) ?? 0)
|
|
@@ -82,31 +88,69 @@ extension NativeNode {
|
|
|
82
88
|
|
|
83
89
|
case "textDecorationLine":
|
|
84
90
|
textDecorationLine = value as? String ?? "none"
|
|
85
|
-
|
|
91
|
+
updateTextAttributes()
|
|
92
|
+
|
|
93
|
+
case "letterSpacing":
|
|
94
|
+
letterSpacing = value is NSNull ? nil : value
|
|
95
|
+
updateTextAttributes()
|
|
96
|
+
|
|
97
|
+
case "lineHeight":
|
|
98
|
+
lineHeight = value is NSNull ? nil : value
|
|
99
|
+
updateTextAttributes()
|
|
100
|
+
|
|
101
|
+
case "fontStyle":
|
|
102
|
+
isItalic = value as? String == "italic"
|
|
103
|
+
updateFont()
|
|
104
|
+
|
|
105
|
+
case "lineClamp":
|
|
106
|
+
let lines = Int(number(value) ?? 0)
|
|
107
|
+
|
|
108
|
+
(view as? UILabel)?.numberOfLines = lines
|
|
109
|
+
markContentChanged()
|
|
86
110
|
|
|
87
111
|
default:
|
|
88
112
|
break
|
|
89
113
|
}
|
|
90
114
|
}
|
|
91
115
|
|
|
92
|
-
/// UILabel has no underline or
|
|
93
|
-
/// `text` drops, so setText calls this again. Later
|
|
94
|
-
|
|
116
|
+
/// UILabel has no underline, letter spacing or line height of its own: they're attributes of its text,
|
|
117
|
+
/// which setting `text` drops, so setText calls this again. Later color and alignment changes keep them;
|
|
118
|
+
/// a font change calls it, as ems depend on the font's size.
|
|
119
|
+
func updateTextAttributes() {
|
|
95
120
|
guard let label = view as? UILabel, let text = label.text else { return }
|
|
96
121
|
|
|
122
|
+
let font = label.font ?? UIFont.systemFont(ofSize: fontSize)
|
|
97
123
|
let paragraphStyle = NSMutableParagraphStyle()
|
|
98
124
|
paragraphStyle.alignment = label.textAlignment
|
|
99
|
-
paragraphStyle.lineBreakMode = label.lineBreakMode
|
|
100
125
|
|
|
101
126
|
var attributes: [NSAttributedString.Key: Any] = [
|
|
102
|
-
.font:
|
|
127
|
+
.font: font,
|
|
103
128
|
.foregroundColor: label.textColor as Any,
|
|
104
129
|
.paragraphStyle: paragraphStyle,
|
|
105
130
|
]
|
|
106
131
|
if textDecorationLine.contains("underline") { attributes[.underlineStyle] = NSUnderlineStyle.single.rawValue }
|
|
107
132
|
if textDecorationLine.contains("line-through") { attributes[.strikethroughStyle] = NSUnderlineStyle.single.rawValue }
|
|
133
|
+
if let spacing = points(letterSpacing, font: font) { attributes[.kern] = spacing }
|
|
134
|
+
if let height = points(lineHeight, font: font) {
|
|
135
|
+
paragraphStyle.minimumLineHeight = height
|
|
136
|
+
paragraphStyle.maximumLineHeight = height
|
|
137
|
+
// The extra space goes above the text: half of it below instead, as CSS centers a line.
|
|
138
|
+
attributes[.baselineOffset] = (height - font.lineHeight) / 2
|
|
139
|
+
}
|
|
108
140
|
|
|
141
|
+
let lineBreakMode = label.lineBreakMode
|
|
109
142
|
label.attributedText = NSAttributedString(string: text, attributes: attributes)
|
|
143
|
+
label.lineBreakMode = lineBreakMode
|
|
144
|
+
markContentChanged()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// A number of points, or ems of the font's size ("1.5em").
|
|
148
|
+
private func points(_ value: Any?, font: UIFont) -> CGFloat? {
|
|
149
|
+
if let text = value as? String, text.hasSuffix("em") {
|
|
150
|
+
return Double(text.dropLast(2)).map { CGFloat($0) * font.pointSize }
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return number(value as Any).map { CGFloat($0) }
|
|
110
154
|
}
|
|
111
155
|
|
|
112
156
|
/// Font size and weight can change independently, so the node remembers both.
|
|
@@ -127,11 +171,17 @@ extension NativeNode {
|
|
|
127
171
|
func updateFont() {
|
|
128
172
|
guard view is UILabel || view is UITextField || view is UIButton else { return }
|
|
129
173
|
|
|
130
|
-
let
|
|
174
|
+
let systemFont = UIFont.systemFont(ofSize: fontSize, weight: fontWeight)
|
|
175
|
+
let italicTraits = systemFont.fontDescriptor.symbolicTraits.union(.traitItalic)
|
|
176
|
+
let styledFont = isItalic
|
|
177
|
+
? systemFont.fontDescriptor.withSymbolicTraits(italicTraits).map { UIFont(descriptor: $0, size: fontSize) } ?? systemFont
|
|
178
|
+
: systemFont
|
|
179
|
+
let font = UIFontMetrics.default.scaledFont(for: styledFont)
|
|
131
180
|
(view as? UILabel)?.font = font
|
|
132
181
|
(view as? UITextField)?.font = font
|
|
133
182
|
(view as? UIButton)?.titleLabel?.font = font
|
|
134
183
|
|
|
184
|
+
if hasTextAttributes { updateTextAttributes() }
|
|
135
185
|
markContentChanged()
|
|
136
186
|
}
|
|
137
187
|
}
|
|
@@ -357,7 +407,7 @@ private let fontWeights: [String: UIFont.Weight] = [
|
|
|
357
407
|
|
|
358
408
|
extension UIColor {
|
|
359
409
|
/// Colors arrive as 0xRRGGBBAA numbers: the JS side (src/colors.js) parses every CSS format.
|
|
360
|
-
convenience init?(rgba value: Any) {
|
|
410
|
+
public convenience init?(rgba value: Any) {
|
|
361
411
|
guard let rgba = (value as? NSNumber)?.uint32Value else { return nil }
|
|
362
412
|
|
|
363
413
|
self.init(
|
|
@@ -406,13 +456,25 @@ extension NativeNode {
|
|
|
406
456
|
}
|
|
407
457
|
|
|
408
458
|
extension UIView {
|
|
409
|
-
|
|
459
|
+
/// borderRadius and the corners' own, as styles set them.
|
|
460
|
+
static let requestedCornerRadiiKey = "nativueCornerRadii"
|
|
410
461
|
|
|
411
462
|
/// A radius over half the view's side (rounded-full is 9999) makes Core Animation draw nothing:
|
|
412
|
-
/// capped to a circle's, and applied again as the frame changes.
|
|
463
|
+
/// capped to a circle's, and applied again as the frame changes. Core Animation rounds every chosen
|
|
464
|
+
/// corner alike: corners with their own radius share the largest.
|
|
413
465
|
func applyCornerRadius() {
|
|
414
|
-
guard let
|
|
466
|
+
guard let radii = layer.value(forKey: Self.requestedCornerRadiiKey) as? [String: CGFloat] else { return }
|
|
467
|
+
|
|
468
|
+
let radius = radii["borderRadius"] ?? 0
|
|
469
|
+
let corners: [(CACornerMask, CGFloat)] = [
|
|
470
|
+
(.layerMinXMinYCorner, radii["borderTopLeftRadius"] ?? radius),
|
|
471
|
+
(.layerMaxXMinYCorner, radii["borderTopRightRadius"] ?? radius),
|
|
472
|
+
(.layerMinXMaxYCorner, radii["borderBottomLeftRadius"] ?? radius),
|
|
473
|
+
(.layerMaxXMaxYCorner, radii["borderBottomRightRadius"] ?? radius),
|
|
474
|
+
]
|
|
475
|
+
let largest = corners.map(\.1).max() ?? 0
|
|
415
476
|
|
|
416
|
-
layer.cornerRadius = min(
|
|
477
|
+
layer.cornerRadius = min(largest, min(bounds.width, bounds.height) / 2)
|
|
478
|
+
layer.maskedCorners = CACornerMask(corners.filter { $0.1 > 0 }.map(\.0))
|
|
417
479
|
}
|
|
418
480
|
}
|
package/ios/VueScrollView.swift
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativue/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Vue rendering real native views on iOS and Android",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/native-events.test.mjs && node test/hermes.test.mjs && node test/prebuild.test.mjs",
|
|
35
|
+
"test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/gradients.test.mjs && node test/native-events.test.mjs && node test/hermes.test.mjs && node test/prebuild.test.mjs",
|
|
36
36
|
"typecheck": "vue-tsc"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
package/src/colors.ts
CHANGED
|
@@ -186,13 +186,17 @@ function parseRgbFunction(color: string) {
|
|
|
186
186
|
export function processColor(color: unknown): number | null {
|
|
187
187
|
if (color == null) return null
|
|
188
188
|
|
|
189
|
-
const
|
|
190
|
-
NAMED_COLORS[String(color).trim().toLowerCase()] ?? String(color).trim().toLowerCase()
|
|
191
|
-
const rgba = normalized.startsWith('#')
|
|
192
|
-
? parseHex(normalized.slice(1))
|
|
193
|
-
: parseRgbFunction(normalized)
|
|
189
|
+
const rgba = parseColor(color)
|
|
194
190
|
|
|
195
|
-
if (rgba === null) console.warn(`[
|
|
191
|
+
if (rgba === null) console.warn(`[nativue] unsupported color: ${color}`)
|
|
196
192
|
|
|
197
193
|
return rgba
|
|
198
194
|
}
|
|
195
|
+
|
|
196
|
+
/** The color as 0xRRGGBBAA, or null, quietly: for telling a color from something else. */
|
|
197
|
+
export function parseColor(color: unknown): number | null {
|
|
198
|
+
const normalized =
|
|
199
|
+
NAMED_COLORS[String(color).trim().toLowerCase()] ?? String(color).trim().toLowerCase()
|
|
200
|
+
|
|
201
|
+
return normalized.startsWith('#') ? parseHex(normalized.slice(1)) : parseRgbFunction(normalized)
|
|
202
|
+
}
|