Skip to content

feat(native): one internal Swift tooltip that follows core's useTooltip on pointer, keyboard, touch, and VoiceOver - #8402

Merged
cixzhang merged 1 commit into
mainfrom
native/swift-tooltip-presenter
Oct 25, 2026
Merged

cixzhang merged 1 commit into
mainfrom
native/swift-tooltip-presenter

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

User need

Avatars and thumbnails show a name or a file name as a tooltip. On the web, people read it by resting the pointer, by moving keyboard focus, or by tapping on a touch screen, and screen-reader users hear it once. Each Swift component was rebuilding that behavior on its own, so each one differed. People on a Mac, an iPad, or an iPhone got tooltips that opened on different inputs, read the name twice, or swallowed a row's tap.

Problem and solution fit

  • One internal modifier, astryxTooltip. It follows core's useTooltip and Tooltip, so every Swift component behaves the same on each input.
  • Placement: above the view, as core places it, below only when there is no room under the window's safe top plus core's space.s4 floor, and sliding sideways to stay inside the safe area of the window that holds the view with the same floor. Long words wrap at core's 300-point width.
  • Pointer: shows after 200 ms, stays while the pointer is on the view or the bubble, hides 100 ms after it leaves, and a press hides it.
  • Keyboard: focus the keyboard brings shows it at once where focus reaches it (none, control, or tabStop, as core's focusTrigger and focusin). Whether the keyboard brought focus is decided once, as focus arrives, as core's :focus-visible check is, so a clicked view never shows it later. It hides 100 ms after focus leaves. Escape hides a shown bubble wherever focus is, as core's top-most layer takes the press.
  • Touch: core's auto by default: a tap opens the bubble unless the view is a control; tap and none override it. A trackpad or mouse click opens nothing. The tap is shared, so the view's own action and an enclosing row still run. Another tap on the view closes it; a tap anywhere but the view or the bubble, or a scroll or pinch anywhere but the bubble, closes it and still reaches what it lands on, as core's outside dismissal does.
  • Disabled and blank words: nothing.
  • VoiceOver: the bubble is hidden, the tap is left alone, and given words are the hint, as core's description.
  • No .help: a test fails if any Swift source in the package uses .help(.
  • One structure: a change of words or a disabled toggle never rebuilds the decorated view.

Current specification

  • spec:AST-082 FR3 (a platform honors a core prop as core does: here core's useTooltip, Tooltip, and touchTrigger); spec:AST-093 FR4 (theme values).
  • New: packages/native/specs/swift/library/tooltip.spec.md, the knowledge record architecture:native-swift-library-tooltip (INV1–INV9), as AST-093 FR1 places cross-component Swift rules.

Public delta and caller burden

  • None public: astryxTooltip, TooltipPresenter, TooltipBubble, TooltipFocus, and TooltipTouch are internal to the Astryx module.
  • Avatar and Thumbnail adopt it in their own pull requests and delete their copies.

Design and alternatives

  • SwiftUI's .help does not fit. It is also the VoiceOver hint, so it reads words already in a view's name twice. It also shows with the system's own look and delay, never on keyboard focus or a tap.
  • The bubble is a SwiftUI overlay in core's tooltip colors: color.textPrimary behind color.backgroundSurface body text, padded space.s1 by space.s2, radius.container, space.s1 from the view, the same on every input. It draws in the view's own layer, so a clipping container around the view can cut it off, as the record states; core's top layer is never clipped.
  • Escape is a hidden button bound to Escape that lives while the bubble shows, so the press reaches it wherever focus is. The outside tap on iOS is a window recognizer that never cancels the touch.

Evidence

  • No component uses it in this change, so there is nothing to capture. The bubble is captured in the components' pull requests.
  • Not measured: hover, focus, Escape, and tap need an app-hosted UI test, which the package does not have yet. The rules are tested as logic.

Open-work search

Searched current records and open pull requests by terms (tooltip, help, useTooltip, touchTrigger, focusTrigger), paths (packages/native/apple/Sources/Astryx/, packages/native/specs/swift/library/), and symbols (AvatarTooltipPresenter, ThumbnailTooltip). The only owners were the per-component copies in #8306 and #8323, which this replaces. No public Swift Tooltip exists or is proposed.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

  • R1 narration: none; the record states the behavior.
  • R2 research: none.
  • R3 evidence: bases name AST-082, AST-093, and core's Tooltip; no pull request or commit.
  • R4 rejected alternatives: one paragraph on .help, which AST-093 FR2 asks a record to name.
  • R5 change references: none.
  • R6 open questions: none.
  • Record kind: architecture, from docs/templates/knowledge/architecture.md; check:knowledge passes.

Testing

  • swiftc -typecheck of AstryxNative, Astryx, and the tests passes.
  • TooltipPresenterTests.swift covers the delay, bridge, and immediate focus; placement above with the flip and the sideways slide; wrapping at 300 points; the outside-tap rule; pointer and bubble hover; focus for each focus kind; the touch rule (direct touch, not pointer, not VoiceOver); blank and disabled; the bubble's colors and padding in two themes; and that a decorated view draws unchanged.
  • The Swift tests run in CI on macOS and on the iOS Simulator; the iOS job compiles the popover path.

Every changed file is under packages/native/.

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 25, 2026 4:48pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 25, 2026
@astracat-bot

astracat-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 25, 2026, 5:23 PM UTC

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f4dcc03

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

48 of 502 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
RichTextEditor Markdown parity: side by side probe dark 556,900
RichTextEditor Markdown parity: side by side probe light 538,816
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
AppShell With Mobile Nav probe light 217,010
AppShell With Mobile Nav probe dark 216,960
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
AppShell Playground neutral dark 65,198
AppShell Playground neutral light 63,788
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232

and 28 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 9f9a515

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is on hold until an engineering owner decides the new draft requirements T1–T7 in packages/native/specs/swift/library/tooltip.md, including T6's bubble below the view where core's Tooltip defaults to above. The existing /approve-spec names the first commit, so an engineering owner, the author included, records the decision by commenting /approve-spec <full head SHA>. Independently of that decision, a few changes are needed:

  • Rewrite the record as a knowledge record (an architecture record named *.spec.md, from docs/templates/knowledge/architecture.md), as knowledge-contracts INV27 and AST-093 FR1 require.
  • Cap the bubble's width and let it wrap, since .fixedSize() draws a long file name as one line past the screen edge where core wraps at 300 px.
  • Bring keyboard focus, Escape and the touch popover in line with core's useTooltip, or state the departures in the record: focus waits 200 ms and reacts to any focus, Escape needs focus, and the popover swallows the tap that closes it.

[Automated review]

@@ -0,0 +1,77 @@
# Tooltip (Swift, internal)

- Status: draft

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file states requirements (T1–T7) but has no knowledge-record frontmatter and is not a *.spec.md file, so the spec-owner gate treats the pull request as changing no knowledge records. docs/architecture/knowledge-contracts.md INV27 and AST-093 FR1 ask for an architecture record such as packages/native/specs/swift/tooltip.spec.md (architecture:native-swift-tooltip), built from docs/templates/knowledge/architecture.md; the existing library specs are exempt only because they predate that form.

content
.modifier(TooltipTabStop(focus: focus, isOn: text != nil))
.focused($isFocused)
.onKeyPress(.escape) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onKeyPress fires only while this view has focus, so a bubble the pointer opened ignores Escape, while core hides any visible tip on Escape (useTooltip.tsx:564-609). Also, after Escape on a focused view a passing pointer brings the bubble back and it then stays, because update() still counts isFocused.

hasText: text != nil, isHovering: isHovering, isHoveringBubble: isHoveringBubble, isFocused: isFocused,
focus: focus)
guard wants != isShown else { return }
let wait = wants ? Self.delay : Self.bridge

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focus goes through the same 200 ms delay as hover, and isFocused is true for focus from any source (a tap into a text field, focus set in code). Core shows a tooltip at once on keyboard focus and ignores focus a touch caused (useTooltip.tsx:423-446).

RoundedRectangle(cornerRadius: astryx.tokens.radius.container, style: .continuous)
.fill(astryx.tokens.color.textPrimary)
)
.fixedSize()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.fixedSize() keeps the text on one line at its full width, and the bottom overlay centres it under the view with nothing keeping it on screen, so a long file name runs past the screen edge, more so at large Dynamic Type. Core caps the tooltip at maxWidth: 300 and wraps (useTooltip.tsx:65-72); capping the width and letting the text wrap would match it.


func body(content: Content) -> some View {
#if os(iOS)
content.popover(isPresented: $isPresented, arrowEdge: .bottom) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On iOS this is a UIKit popover, which blocks interaction with other views until it is dismissed (see UIPopoverPresentationController.passthroughViews), so the tap that closes the tooltip never reaches the control it lands on. Core's outside-tap dismissal lets that tap through (useTouchTrigger.ts:268-304), which is the touch behavior AST-082 FR3 holds a touch platform to; a non-modal presentation would keep it, or T3 can state the departure.

@cixzhang
cixzhang force-pushed the native/swift-tooltip-presenter branch 2 times, most recently from 82b5a2e to 274bd4c Compare October 25, 2026 14:10
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 274bd4c

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 6b5bde5

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is on hold until an engineering owner decides the draft invariants INV1–INV9 in packages/native/specs/swift/library/tooltip.spec.md, including INV1's bubble that a scroll view or other clipping container cuts off, the fixed tap/none touch choice where core's touchTrigger defaults to auto, and the review check that rejects SwiftUI's .help. The existing /approve-spec comments name earlier commits, so an engineering owner, the author included, records the decision by commenting /approve-spec <full head SHA>. Independently of that decision, three fixes are needed:

  • Close a tap-opened bubble when a scroll or pinch starts outside it, as core's outside dismissal does, and leave a tap on the bubble itself alone, or state both departures in INV5.
  • Show the bubble on focus only when the keyboard moved it, as core's :focus-visible check does, or state in INV3 that any focus opens it.
  • Read the sideways slide's width from the window that holds the view rather than the first scene's key window, so two iPad windows of different widths each keep the bubble inside.

[Automated review]

recognizer = nil
window = newWindow
guard let newWindow else { return }
let tap = UITapGestureRecognizer(target: self, action: #selector(tapped(_:)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A tap recognizer fails once the finger moves farther than a tap allows, so a scroll or pinch never reaches tapped(_:) and a tap-opened bubble stays up, riding along with the scrolling row. Core's outside dismissal also closes on pointercancel, when a scroll or pinch takes the touch, including one that starts on the trigger (packages/core/src/Layer/useTouchTrigger.ts:271-272, :282-283), and it leaves a tap inside the tooltip alone (:290-293), while closesTapBubble closes on a tap on the bubble. INV5 says "as core's outside tap does", so either close on any touch that starts outside the view and the bubble, or state both departures in INV5.

nonisolated static func wantsBubble(
hasText: Bool, isHovering: Bool, isHoveringBubble: Bool, isFocused: Bool, focus: TooltipFocus
) -> Bool {
hasText && (isHovering || isHoveringBubble || (isFocused && focus != .none))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any focus counts here, so focus moved in code on a control or tabStop view (a form advancing to its next field, say) opens the bubble at once, and nothing filters focus that a touch gave. Core shows a tooltip on focus only for keyboard focus: it returns for a touch interaction and for focus that does not match :focus-visible (packages/core/src/Tooltip/useTooltip.tsx:428-441), which INV3 says this follows. Either show on focus only when the keyboard moved it, or state the departure in INV3.

@MainActor enum TooltipWindow {
static var width: CGFloat? {
#if os(iOS)
UIApplication.shared.connectedScenes.compactMap { ($0 as? UIWindowScene)?.keyWindow }.first?.bounds.width

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connectedScenes is an unordered set and every connected scene has its own key window, so with two windows of the app on screen this can return the other window's width while viewFrame is measured in this one: the bubble then runs past the narrower window's edge, or slides away from its view in the wider one. Reading the width from the window that holds the view keeps INV1's slide right.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 363ad0f

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval is on hold until an engineering owner decides the draft invariants INV1–INV9 in packages/native/specs/swift/library/tooltip.spec.md as rewritten on this head, including INV1's bubble that a scroll view or other clipping container cuts off and the review check that rejects SwiftUI's .help anywhere in the package. The existing /approve-spec comments name earlier commits, so an engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Independently of that decision, three fixes are needed:

  • Decide whether the keyboard brought focus once, when focus arrives, as core's :focus-visible check does: update() re-judges it from the current hover and the time since the last press, so a clicked field shows its bubble once the pointer leaves and focus moved in code shows it at once.
  • Close a tap-opened bubble on a scroll or pinch that starts on the view, as core's outside dismissal does, and exempt the view only for taps.
  • Keep the bubble inside the device's safe area with core's --spacing-4 floor, so it neither opens under the status bar nor slides under the sensor housing.

[Automated review]

private func update() {
pending?.cancel()
let keyboardFocused =
isFocused && Self.isKeyboardFocus(isHovering: isHovering, sincePress: Date().timeIntervalSince(pressedAt))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyboardFocused is re-decided on every update() from the current hover and the time since this view's last tap, so focus a click gave counts as keyboard focus once the pointer leaves more than half a second later, and focus moved in code counts unless the pointer rests on the view. Core decides once in handleFocusIn (packages/core/src/Tooltip/useTooltip.tsx:428-451), which INV3 says this follows; deciding when focus arrives and keeping that answer until it leaves would match it.

/// coordinates, closes a tap-opened bubble: anywhere but the view, whose
/// own tap toggles it, and the bubble.
nonisolated static func closesTapBubble(point: CGPoint, viewFrame: CGRect, bubbleFrame: CGRect) -> Bool {
!viewFrame.contains(point) && !bubbleFrame.contains(point)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pan and pinch recognizers use this exemption too, so a scroll that starts on the avatar leaves a tap-opened bubble up, scrolling with the row. Core closes it: “A scroll that starts there is a scroll outside the layer, and it does close it.” (packages/core/src/Layer/useTouchTrigger.ts:282-289). Exempting the view only for the tap recognizer, and judging a pan by where it started, would match INV5's claim.

/// Whether the bubble goes above the view: core's placement, unless the
/// bubble and its gap would not fit between the window's top and the view.
nonisolated static func placesAbove(viewTop: CGFloat, bubbleHeight: CGFloat, gap: CGFloat) -> Bool {
viewTop >= bubbleHeight + gap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewTop is measured from the window's top, and the slide keeps space.s1 from the bare window edges, so near the status bar, or the sensor housing in landscape, the bubble lands under them. Core's layer keeps max(--spacing-4, env(safe-area-inset-<edge>)) from each edge (AST-059 FR1), which INV1 says this follows.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec c3fe33f

…ip on pointer, keyboard, touch, and VoiceOver
@cixzhang
cixzhang force-pushed the native/swift-tooltip-presenter branch from c3fe33f to 0a3cfb0 Compare October 25, 2026 16:40
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 0a3cfb0

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Swift tooltip modifier is ready for approval: an engineering owner approved INV1–INV9 in packages/native/specs/swift/library/tooltip.spec.md on this exact head, the implementation matches them and the current native specs, and the Swift tests pass on macOS and the iOS Simulator. The earlier focus, scroll-dismissal and safe-area issues are fixed. Two small follow-ups that need not hold this pull request: the INV5 verification row should say that a scroll or pinch starting on the view closes a tap-opened bubble, as INV5 and its test do, and INV1 could say where the bubble goes on a view's first show, before the window's safe area is known.

[Automated review]

| INV1 | `TooltipPresenterTests.swift`: above unless no room; slides inside the window; long words wrap within 300 points | a bubble below with room above, or one line past 300 points |
| INV2 | `TooltipPresenterTests.swift`: delay and bridge; the pointer on the view or the bubble keeps it up | a bubble that hides while hovered or shows at once on a pointer |
| INV3 | `TooltipPresenterTests.swift`: focus shows at once for `control` and `tabStop`, never for `none`; only keyboard focus | a delayed focus bubble, one on a view focus does not reach, or one a pointer's focus opens |
| INV5 | `TooltipPresenterTests.swift`: `auto` resolves as core's; only a direct touch on a tap trigger opens it; a gesture elsewhere closes it, one on the view or the bubble does not | a bubble from a pointer click, under VoiceOver, or on a control under `auto`; one a gesture elsewhere leaves open |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This row says a gesture on the view does not close the bubble, but INV5 closes a tap-opened bubble on a scroll or pinch that starts on the view, and aGestureElsewhereClosesATapOpenedBubbleButNotOnTheBubble asserts exactly that (TooltipPresenterTests.swift:112). Aligning the row with INV5 in a follow-up would keep the record consistent.

@State private var pending: Task<Void, Never>?
@State private var viewFrame: CGRect = .zero
@State private var bubbleFrame: CGRect = .zero
@State private var window = TooltipWindowMetrics()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window is filled only by the probe inside the shown bubble (line 197), so a view's first bubble is laid out with zero safe-area insets and no slide until the probe reports. INV1 does not say where that first placement may go; stating it, or reading the window before the first show, would close the gap.

@cixzhang
cixzhang merged commit ce34b37 into main Oct 25, 2026
71 checks passed
@github-actions
github-actions Bot deleted the native/swift-tooltip-presenter branch October 26, 2026 06:31

This branch was successfully deployed

1 active deployment
Preview — 0a3cfb01 Deployed Oct 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant