@astryxdesign/native 0.7.5-canary.cdd75ae → 0.7.5-canary.d26cdf3
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.
|
@@ -181,6 +181,14 @@ struct TooltipPresenter: ViewModifier {
|
|
|
181
181
|
isFocused: holdsByFocus(isFocused: isFocused, focusIsKeyboard: focusIsKeyboard), focus: focus)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/// Whether keyboard focus still holds the bubble after the pointer enters
|
|
185
|
+
/// or leaves the view or the bubble: a pointer leaving lets the bubble hide
|
|
186
|
+
/// even though focus opened it, as core's `mouseleave` schedules the hide
|
|
187
|
+
/// whatever brought it up, until focus leaves and returns.
|
|
188
|
+
nonisolated static func keyboardFocusHolds(afterHover inside: Bool, holds: Bool) -> Bool {
|
|
189
|
+
inside && holds
|
|
190
|
+
}
|
|
191
|
+
|
|
184
192
|
/// Whether focus came from the keyboard, as core's `:focus-visible`: not
|
|
185
193
|
/// while a pointer rests on the view, and not within a press of it.
|
|
186
194
|
nonisolated static func isKeyboardFocus(isHovering: Bool, sincePress: TimeInterval) -> Bool {
|
|
@@ -195,6 +203,7 @@ struct TooltipPresenter: ViewModifier {
|
|
|
195
203
|
.simultaneousGesture(TapGesture().onEnded { pressed() })
|
|
196
204
|
.onHover { inside in
|
|
197
205
|
isHovering = inside
|
|
206
|
+
focusIsKeyboard = Self.keyboardFocusHolds(afterHover: inside, holds: focusIsKeyboard)
|
|
198
207
|
update()
|
|
199
208
|
}
|
|
200
209
|
.onChange(of: isFocused) {
|
|
@@ -208,23 +217,20 @@ struct TooltipPresenter: ViewModifier {
|
|
|
208
217
|
}
|
|
209
218
|
.overlay(alignment: above ? .top : .bottom) {
|
|
210
219
|
if isShown || isTapShown, let text {
|
|
211
|
-
let gap = astryx.tokens.space.s1
|
|
212
|
-
let isAbove = above
|
|
213
220
|
TooltipBubble(text: text)
|
|
214
221
|
.onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { bubbleFrame = $0 }
|
|
215
222
|
.background(TooltipWindowReader { window = $0 })
|
|
216
223
|
.onHover { inside in
|
|
217
224
|
isHoveringBubble = inside
|
|
225
|
+
focusIsKeyboard = Self.keyboardFocusHolds(afterHover: inside, holds: focusIsKeyboard)
|
|
218
226
|
update()
|
|
219
227
|
}
|
|
220
|
-
.offset(x: sideways)
|
|
221
228
|
.background(TooltipEscape(hide: hideAll))
|
|
222
229
|
.background(
|
|
223
230
|
TooltipOutsideTap(isActive: isTapShown, viewFrame: viewFrame, bubbleFrame: bubbleFrame) {
|
|
224
231
|
isTapShown = false
|
|
225
232
|
})
|
|
226
|
-
|
|
227
|
-
.alignmentGuide(isAbove ? .top : .bottom) { d in isAbove ? d[.bottom] + gap : d[.top] - gap }
|
|
233
|
+
.modifier(TooltipPlacement(isAbove: above, gap: astryx.tokens.space.s1, slide: sideways))
|
|
228
234
|
}
|
|
229
235
|
}
|
|
230
236
|
.zIndex(isShown || isTapShown ? 1 : 0)
|
|
@@ -340,6 +346,22 @@ private struct TooltipWindowProbe: View {
|
|
|
340
346
|
}
|
|
341
347
|
#endif
|
|
342
348
|
|
|
349
|
+
/// Places the bubble `gap` above the view it decorates, or below it, slid
|
|
350
|
+
/// sideways by `slide`. The bubble hangs from a zero-height frame on the
|
|
351
|
+
/// view's top or bottom edge, so it needs no measured height and sits in
|
|
352
|
+
/// place on its first frame. Used inside an overlay aligned to that edge.
|
|
353
|
+
struct TooltipPlacement: ViewModifier {
|
|
354
|
+
let isAbove: Bool
|
|
355
|
+
let gap: CGFloat
|
|
356
|
+
let slide: CGFloat
|
|
357
|
+
|
|
358
|
+
func body(content: Content) -> some View {
|
|
359
|
+
content
|
|
360
|
+
.frame(height: 0, alignment: isAbove ? .bottom : .top)
|
|
361
|
+
.offset(x: slide, y: isAbove ? -gap : gap)
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
343
365
|
/// Escape hides a shown bubble wherever focus is, as core's top-most layer
|
|
344
366
|
/// takes the press: a hidden button bound to Escape lives while the bubble
|
|
345
367
|
/// shows.
|
|
@@ -168,3 +168,53 @@ import Testing
|
|
|
168
168
|
#expect(P.showsBubble(hasText: true, isHovering: false, isHoveringBubble: false, isFocused: true, focusIsKeyboard: true, focus: .tabStop))
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
@Test func aPointerLeavingLetsAKeyboardFocusedBubbleHide() {
|
|
172
|
+
typealias P = TooltipPresenter
|
|
173
|
+
#expect(!P.keyboardFocusHolds(afterHover: false, holds: true))
|
|
174
|
+
#expect(P.keyboardFocusHolds(afterHover: true, holds: true))
|
|
175
|
+
#expect(!P.keyboardFocusHolds(afterHover: true, holds: false))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/// Rows the bubble's dark fill covers, and rows the view shows, in a render
|
|
179
|
+
/// of a 36-point view with a placed bubble.
|
|
180
|
+
@MainActor
|
|
181
|
+
private func placedRows(isAbove: Bool, text: String = "Ada Lovelace") -> (bubble: ClosedRange<Int>?, view: ClosedRange<Int>) {
|
|
182
|
+
let theme = Theme.default.light
|
|
183
|
+
let probe = ZStack(alignment: .topLeading) {
|
|
184
|
+
Color.white
|
|
185
|
+
Color.blue.frame(width: 36, height: 36)
|
|
186
|
+
.overlay(alignment: isAbove ? .top : .bottom) {
|
|
187
|
+
TooltipBubble(text: text).modifier(TooltipPlacement(isAbove: isAbove, gap: 4, slide: 0))
|
|
188
|
+
}
|
|
189
|
+
.offset(x: 150, y: 100)
|
|
190
|
+
}
|
|
191
|
+
.frame(width: 400, height: 240)
|
|
192
|
+
let pixels = Pixels(probe.astryxTheme())
|
|
193
|
+
let ink = rgba(theme.color.textPrimary)
|
|
194
|
+
func rows(_ match: ([Int]) -> Bool) -> [Int] {
|
|
195
|
+
(0..<pixels.height).filter { y in (0..<pixels.width).contains { x in match(pixels.at(x, y)) } }
|
|
196
|
+
}
|
|
197
|
+
let dark = rows { close($0, ink, within: 12) }
|
|
198
|
+
let blue = rows { $0[2] > 200 && $0[0] < 60 && $0[1] < 140 }
|
|
199
|
+
return (dark.isEmpty ? nil : dark.first!...dark.last!, blue.first!...blue.last!)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// INV1: the bubble sits `gap` above the view, or below it, and never on it.
|
|
203
|
+
@MainActor
|
|
204
|
+
@Test func theBubbleSitsAboveOrBelowTheViewNotOnIt() throws {
|
|
205
|
+
let above = placedRows(isAbove: true)
|
|
206
|
+
let bubble = try #require(above.bubble)
|
|
207
|
+
#expect(above.view == 100...135)
|
|
208
|
+
#expect(bubble.upperBound == 95)
|
|
209
|
+
#expect(bubble.count >= 20)
|
|
210
|
+
let below = placedRows(isAbove: false)
|
|
211
|
+
let under = try #require(below.bubble)
|
|
212
|
+
#expect(below.view == 100...135)
|
|
213
|
+
#expect(under.lowerBound == 140)
|
|
214
|
+
// Long words wrap upward from the same edge.
|
|
215
|
+
let long = placedRows(isAbove: true, text: String(repeating: "A long tooltip ", count: 6))
|
|
216
|
+
let wrapped = try #require(long.bubble)
|
|
217
|
+
#expect(wrapped.upperBound == 95)
|
|
218
|
+
#expect(wrapped.count > bubble.count)
|
|
219
|
+
}
|
|
220
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/native",
|
|
3
|
-
"version": "0.7.5-canary.
|
|
3
|
+
"version": "0.7.5-canary.d26cdf3",
|
|
4
4
|
"description": "Experimental native platforms for Astryx (iOS, Android, macOS, Windows) — published to npm only under the @canary dist-tag; never released as a stable (latest) version.",
|
|
5
5
|
"author": "Meta Open Source",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@astryxdesign/core": "0.7.5-canary.
|
|
73
|
+
"@astryxdesign/core": "0.7.5-canary.d26cdf3"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@astryxdesign/core": "0.7.5-canary.
|
|
76
|
+
"@astryxdesign/core": "0.7.5-canary.d26cdf3"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",
|