refactor(ui): 将页签改为扁平胶囊并保留导航语义
This commit is contained in:
@@ -13,7 +13,7 @@ private struct TabHost: View {
|
||||
NeutralTabPicker(title: "panel.page", selection: $state.selected,
|
||||
options: [(0, "panel.overview"), (1, "panel.processes")])
|
||||
.environment(\.locale, state.locale)
|
||||
.frame(width: 164, height: 28)
|
||||
.frame(width: 164, height: 32)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,21 +31,46 @@ private struct TabHost: View {
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
await until { find(host) != nil }
|
||||
let control = find(host)!
|
||||
await until { control.label(forSegment: 0) == "Overview" }
|
||||
precondition(control.selectedSegment == 0)
|
||||
await until { control.buttons.first?.title == "Overview" }
|
||||
precondition(control.selectedIndex == 0)
|
||||
precondition(control.accessibilityRole() == .tabGroup)
|
||||
precondition(control.accessibilityTabs()?.count == 2)
|
||||
let first = control.buttons[0], second = control.buttons[1]
|
||||
for button in [first, second] {
|
||||
precondition(button.accessibilityRole() == .radioButton)
|
||||
precondition(button.accessibilitySubrole() == .tabButtonSubrole)
|
||||
precondition(button.isAccessibilityElement() && button.accessibilityChildren()?.isEmpty == true,
|
||||
"Each tab must expose a single accessibility element")
|
||||
}
|
||||
precondition(first.isAccessibilitySelected() && !second.isAccessibilitySelected())
|
||||
precondition(first.canBecomeKeyView && !second.canBecomeKeyView)
|
||||
state.selected = 1
|
||||
await until { control.selectedSegment == 1 }
|
||||
control.selectedSegment = 0
|
||||
_ = control.sendAction(control.action, to: control.target)
|
||||
await until { control.selectedIndex == 1 }
|
||||
precondition(second.isAccessibilitySelected() && !first.isAccessibilitySelected())
|
||||
precondition((second.accessibilityValue() as? NSNumber)?.boolValue == true)
|
||||
precondition(control.accessibilitySelectedChildren()?.first as? NSButton === second)
|
||||
first.performClick(nil)
|
||||
await until { state.selected == 0 }
|
||||
precondition(second.accessibilityPerformPress())
|
||||
await until { state.selected == 1 }
|
||||
precondition(window.makeFirstResponder(second))
|
||||
for (code, selected) in [(UInt16(123), 0), (124, 1), (124, 1), (115, 0), (119, 1)] {
|
||||
let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [], timestamp: 0,
|
||||
windowNumber: window.windowNumber, context: nil, characters: "",
|
||||
charactersIgnoringModifiers: "", isARepeat: false, keyCode: code)!
|
||||
window.sendEvent(event)
|
||||
await until { state.selected == selected }
|
||||
precondition(window.firstResponder === control.buttons[selected], "Arrow navigation must retain focus on the selected tab")
|
||||
}
|
||||
for (locale, title) in [("zh-Hans", "概览"), ("zh-Hant", "概覽"), ("en", "Overview")] {
|
||||
state.locale = Locale(identifier: locale)
|
||||
await until { control.label(forSegment: 0) == title }
|
||||
await until { control.buttons[0].title == title }
|
||||
precondition(find(host) === control, "Locale updates must retain the mounted native control")
|
||||
precondition(control.selectedSegment == 0)
|
||||
precondition(control.buttons[0] === first && control.buttons[1] === second)
|
||||
precondition(control.selectedIndex == 1)
|
||||
}
|
||||
window.orderOut(nil); window.close()
|
||||
print("PASS: native tab binding in both directions, localized labels in place and retained selection")
|
||||
print("PASS: flat tab binding, native/AX press, tab roles and selection, arrow/Home/End focus navigation and in-place three-language updates")
|
||||
fflush(stdout); NSApp.terminate(nil)
|
||||
}
|
||||
NSApp.run()
|
||||
@@ -57,8 +82,8 @@ private struct TabHost: View {
|
||||
precondition(condition(), "Timed out waiting for native tab update")
|
||||
}
|
||||
|
||||
@MainActor private static func find(_ view: NSView) -> NSSegmentedControl? {
|
||||
if let control = view as? NSSegmentedControl { return control }
|
||||
@MainActor private static func find(_ view: NSView) -> FlatTabControl? {
|
||||
if let control = view as? FlatTabControl { return control }
|
||||
return view.subviews.lazy.compactMap { find($0) }.first
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user