mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* iOS: launch screen in the app's first-frame black
The launch screen's LaunchBackground was a dark teal (sRGB 7,17,20, shown
as about 2,17,19) for the ~1.5 s before the app's first frame, which is
HexTheme.bgDeep (0x0A0B0D). It now uses bgDeep's exact components, so
launch hands over to the app without a colour jump.
Verified: built for Simulator; fresh-install launch recorded.
* iOS: onboarding follows the desktop's pages, with the polish fixes
Dax found the iPhone onboarding annoying; Ryan and Dax asked for the
desktop's flow. The three pages (Welcome, Set up Hex, Try the keyboard)
become the desktop's six, in its order and copy style:
1. Setting up Hex: the speech model starts downloading as onboarding
opens (whichever engine transcriberFactory picks). Before, only home's
"Set up" started a Parakeet download, so onboarding said "You're all
set" while home said "Finish setup · 1 step". A launch that found
Parakeet ended mid-load stays failed (ParakeetLoadGuard) until Try
again. Moves on after a beat; a failed start holds it with Try again.
2. With Hex: a short demo, a reply dictated with the Hex key. Skip.
3. Let Hex hear you: Microphone and Hex keyboard rows with a one-line
detail that stays (steady heights) and one-line copy ("With Full
Access", no mid-phrase wrap). A done row shows only its check (the
Keyboard row used to keep its Open Settings pill). The pill and the
page's button say Continue before iOS's prompt (App Review 5.1.1(iv)),
Continue never needs the microphone, and the page moves on once both
rows are done. No Skip.
4. Almost ready: only while the model downloads, with its progress;
Continue without a model only after a failure or 30 s without progress.
5. Your turn: the practice. The field keeps the keyboard up (the old
page unfocused it ~150 ms after the first letter) and counts once a
dictation arrives (lastInsertedResultID changes) or three words are
typed with Full Access. An empty dictation says "Hex didn't hear any
words. Try again a little louder." on this page only; the keyboard
notes it in the App Group (keyboard.lastEmptyDictationAt) and still
shows nothing itself. Skip.
6. Hex is ready: only once every step (model included) is done, else
"Almost ready" with what's left. Start using Hex never waits.
The download's pill (language and percent) sits in the top bar until the
model is ready; Skip shows on the demo and the practice only. The page
counter and Back are gone, as on the desktop. Saved pages from earlier
builds resume on their new equivalents. Snapshot scenes are renamed
onboarding-setup/-demo/-permissions(-done)/-waiting/-failed/-try(-done,
-empty,-off)/-ready, plus onboarding-tour. zh-Hans strings added.
Verified: xcodebuild test on an iOS 27.2 simulator (385 tests, 0
failures, 1 skipped), including new KeyboardBridgeTests for the empty
dictation note, the practice rule, and saved-page migration; English and
Chinese snapshots of every page; a fresh-install recording.
* iOS onboarding: the practice field takes focus when Hex comes back
Coming back from Settings with both permission rows done moves straight
on to Your turn, but the page opened before Hex was active again, so its
field never took focus and the keyboard stayed down. The page now
focuses the field again when the scene becomes active (unless it already
has focus).
Verified: fresh-install recording on an iOS 27.2 simulator: back from
Settings, Your turn opens with the keyboard up.
* iOS: Ready waits for the model the Hex key itself dictates with
On iOS 26 the keyboard transcribes inside itself with Apple Speech,
whatever Hex uses. When Hex dictates with Parakeet (an English iPhone
without SpeechTranscriber, or a cached Parakeet model), onboarding and
home said Ready while the keyboard's Apple Speech model wasn't there,
and the first Hex key tap said "Open Hex to download English."
KeyboardSpeechPreparation (owned by ContentView, started at launch)
prepares the keyboard's engine:
- Hex dictates with Apple Speech: Hex's model is the same one, so it
follows Hex's.
- Otherwise it resolves the keyboard's language (AppleSpeechLanguages,
as the keyboard does) and installs it with AppleSpeechAssets.install,
the keyboard's own call, which also clears keyboardNeedsHex.
- Apple has no model for it on this iPhone, or Speech lists nothing: it
marks keyboardNeedsHex, so the Hex key opens Hex (which dictates with
its own model) from the first tap instead of after a failed one.
Re-marked at each launch, as the mark lasts a day.
- A failed download (connection) shows on onboarding with Try again.
Why not have the keyboard use Hex's Parakeet: it can't load within a
keyboard extension's memory limit, and handing every dictation to Hex
leaves the app being typed in each time. In-keyboard Apple Speech stays
the path, with the handoff only where Apple has no model.
Onboarding's model stage combines both (OnboardingModel.combine): ready
only when both are, a failure first, fractions averaged only when the
keyboard actually downloads. Home's status line and the setup sheet's
Speech model row count it the same way.
Verified: xcodebuild test, iOS 27.2 simulator: 386 tests, 0 failures,
1 skipped (new: the combine rules). In the simulator (no Apple Speech
assets: "not subscribed to assistant.en_US") it marks the handoff and
onboarding goes on to Parakeet's Ready; a real iPhone must confirm the
Apple Speech download path.
* iOS onboarding: the desktop's motion, the pill flying between places
The desktop onboarding's motion (onboarding_kit/landing.rs, pill.rs):
- Each page's parts roll in 8 pt with a fade on a 0.34 s zero-bounce
spring, 0.05 s apart (onboardingStagger), and the leaving page lifts
away 8 pt on 0.26 s. Replaces the old 28 pt sideways page slide.
- The download pill flies from under Setting up Hex to the top bar and
stays there across pages (matchedGeometryEffect), on the desktop's
0.42 s flight spring.
- Reduce Motion: parts fade without moving or staggering, the pill
cross-fades, pages fade.
Stills (--snap-state) show every part at once.
"Watch another one" stays off: on the desktop it fills a long download
on Almost ready; on iPhone the demo is ~6 s and moves on by itself, so a
replay control would only add a label.
Verified: xcodebuild test (386, 0 failures, 1 skipped); fresh-install
recording on an iOS 27.2 simulator, frames checked at each page change.
* iOS onboarding: steady progress and an untruncated pill in flight
Two things the recording showed:
- In the simulator the keyboard's Apple Speech download starts, then
can't be had and hands off to Hex; that short attempt still counted as
half of onboarding's progress, so the percent jumped from 0% to 50%.
A handoff no longer counts as a download.
- The pill flew with its frame, so the small pill's language truncated
("Engli… 2%") for about half a second after landing. It now flies by
position only; each pill keeps its own size.
Verified: fresh-install recording on an iOS 27.2 simulator, frames at
15 fps around the Setting up Hex to demo change, and the percent climbing
from 0% in steps.
358 lines
12 KiB
Swift
358 lines
12 KiB
Swift
import SwiftUI
|
||
import UIKit
|
||
|
||
// The pieces onboarding's pages share, in the app's flat style.
|
||
|
||
/// The desktop onboarding's motion (src/rune_ui/onboarding_kit/landing.rs and pill.rs): parts
|
||
/// roll in 8 pt on a 0.34 s zero-bounce spring, 0.05 s apart, and lift away on 0.26 s; the
|
||
/// download pill flies between its places on 0.42 s.
|
||
enum OnboardingMotion {
|
||
static let travel: CGFloat = 8
|
||
static let stagger: Double = 0.05
|
||
static let enter = Animation.spring(duration: 0.34, bounce: 0)
|
||
static let exit = Animation.spring(duration: 0.26, bounce: 0)
|
||
static let fly = Animation.spring(duration: 0.42, bounce: 0)
|
||
}
|
||
|
||
extension EnvironmentValues {
|
||
/// Where the download pill flies between pages; nil under Reduce Motion, where it fades.
|
||
@Entry var onboardingPillSpace: Namespace.ID? = nil
|
||
}
|
||
|
||
extension View {
|
||
/// Rolls in on arrival after "rank" stagger steps; a plain fade under Reduce Motion.
|
||
func onboardingStagger(_ rank: Int) -> some View {
|
||
modifier(OnboardingStagger(rank: rank))
|
||
}
|
||
}
|
||
|
||
private struct OnboardingStagger: ViewModifier {
|
||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||
let rank: Int
|
||
/// Stills show every part at once.
|
||
@State private var shown = OnboardingFixture.isSnapshot && OnboardingFixture.current != .tour
|
||
|
||
func body(content: Content) -> some View {
|
||
content
|
||
.opacity(shown ? 1 : 0)
|
||
.offset(y: shown || reduceMotion ? 0 : OnboardingMotion.travel)
|
||
.onAppear {
|
||
guard !shown else { return }
|
||
let animation = reduceMotion
|
||
? HexMotion.reducedFade
|
||
: OnboardingMotion.enter.delay(Double(rank) * OnboardingMotion.stagger)
|
||
withAnimation(animation) { shown = true }
|
||
}
|
||
}
|
||
}
|
||
|
||
private struct OnboardingPillFlight: ViewModifier {
|
||
@Environment(\.onboardingPillSpace) private var space
|
||
|
||
func body(content: Content) -> some View {
|
||
if let space {
|
||
// Position only: the two pills keep their own sizes, so the language never truncates
|
||
// mid-flight.
|
||
content.matchedGeometryEffect(id: "download-pill", in: space, properties: .position)
|
||
} else {
|
||
content
|
||
}
|
||
}
|
||
}
|
||
|
||
@MainActor
|
||
func openSettings(_ openURL: OpenURLAction) {
|
||
// Hex's own page in Settings (Apps › Hex), which lists Keyboards and Microphone.
|
||
if let url = URL(string: UIApplication.openSettingsURLString) {
|
||
openURL(url)
|
||
}
|
||
}
|
||
|
||
struct OnboardingTitle: View {
|
||
let title: LocalizedStringKey
|
||
|
||
init(_ title: LocalizedStringKey) {
|
||
self.title = title
|
||
}
|
||
|
||
var body: some View {
|
||
Text(title)
|
||
.font(.system(size: 28, weight: .semibold))
|
||
.tracking(-0.4)
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.multilineTextAlignment(.center)
|
||
}
|
||
}
|
||
|
||
/// The top row: the model's download pill in the middle while it downloads, and a quiet Skip
|
||
/// on the optional pages, as on the desktop.
|
||
struct OnboardingTopBar: View {
|
||
let model: OnboardingModel
|
||
let onSkip: (() -> Void)?
|
||
|
||
var body: some View {
|
||
ZStack {
|
||
if !model.isReady && !model.isFailed {
|
||
OnboardingProgressPill(model: model, large: false)
|
||
.transition(.opacity)
|
||
}
|
||
HStack {
|
||
Spacer()
|
||
if let onSkip {
|
||
Button("Skip", action: onSkip)
|
||
.font(.system(size: 15, weight: .medium))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.frame(minWidth: 44, minHeight: 44, alignment: .trailing)
|
||
.contentShape(Rectangle())
|
||
.buttonStyle(.plain)
|
||
.onboardingStagger(0)
|
||
}
|
||
}
|
||
}
|
||
.frame(height: 44)
|
||
.animation(HexMotion.reducedFade, value: model.isReady)
|
||
}
|
||
}
|
||
|
||
/// A hexagon outline that fills as the model downloads, beside its percentage. The large one
|
||
/// is Setting up Hex's; the small one sits in the top bar with the language.
|
||
struct OnboardingProgressPill: View {
|
||
let model: OnboardingModel
|
||
let large: Bool
|
||
|
||
var body: some View {
|
||
HStack(spacing: large ? 10 : 8) {
|
||
ZStack {
|
||
OnboardingHexagon()
|
||
.stroke(Color.white.opacity(0.18), lineWidth: 1.6)
|
||
OnboardingHexagon()
|
||
.trim(from: 0, to: model.isReady ? 1 : max(0.02, model.fraction))
|
||
.stroke(model.isReady ? HexTheme.success : HexTheme.textBase, style: StrokeStyle(lineWidth: 1.6, lineCap: .round))
|
||
}
|
||
.frame(width: large ? 18 : 14, height: large ? 18 : 14)
|
||
.animation(HexMotion.reducedFade, value: model.fraction)
|
||
|
||
if !large {
|
||
Text(model.language)
|
||
.foregroundStyle(HexTheme.textBase)
|
||
}
|
||
Group {
|
||
if model.isReady {
|
||
Text("Ready")
|
||
} else {
|
||
Text(model.fraction, format: .percent.precision(.fractionLength(0)))
|
||
.monospacedDigit()
|
||
}
|
||
}
|
||
.foregroundStyle(large ? HexTheme.textBase : HexTheme.textMuted)
|
||
}
|
||
.font(.system(size: large ? 15 : 13, weight: .medium))
|
||
.padding(.horizontal, large ? 14 : 11)
|
||
.frame(height: large ? 36 : 30)
|
||
.background(HexTheme.bgBase, in: Capsule())
|
||
.modifier(OnboardingPillFlight())
|
||
.accessibilityElement(children: .combine)
|
||
}
|
||
}
|
||
|
||
struct OnboardingHexagon: Shape {
|
||
func path(in rect: CGRect) -> Path {
|
||
let r = min(rect.width, rect.height) / 2
|
||
let c = CGPoint(x: rect.midX, y: rect.midY)
|
||
var path = Path()
|
||
for i in 0...6 {
|
||
let angle = Double(i) * .pi / 3 - .pi / 2
|
||
let point = CGPoint(x: c.x + r * cos(angle), y: c.y + r * sin(angle))
|
||
if i == 0 { path.move(to: point) } else { path.addLine(to: point) }
|
||
}
|
||
return path
|
||
}
|
||
}
|
||
|
||
struct OnboardingLanguageCapsule: View {
|
||
let language: String
|
||
|
||
var body: some View {
|
||
Text(language)
|
||
.font(.system(size: 14, weight: .medium))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.padding(.horizontal, 10)
|
||
.frame(height: 26)
|
||
.background(HexTheme.bgBase, in: Capsule())
|
||
.overlay(Capsule().stroke(Color.white.opacity(0.1), lineWidth: 0.5))
|
||
}
|
||
}
|
||
|
||
struct OnboardingFailure: View {
|
||
let message: String
|
||
let onRetry: () -> Void
|
||
|
||
var body: some View {
|
||
VStack(spacing: 12) {
|
||
Text(message)
|
||
.font(.system(size: 15))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.multilineTextAlignment(.center)
|
||
.fixedSize(horizontal: false, vertical: true)
|
||
OnboardingSecondaryButton(title: "Try again", icon: "arrow.clockwise", action: onRetry)
|
||
.frame(maxWidth: 200)
|
||
}
|
||
}
|
||
}
|
||
|
||
/// The lock line under Setting up Hex and the permissions.
|
||
struct OnboardingPrivacyLine: View {
|
||
var body: some View {
|
||
Label("Hex hears you on this iPhone. Your voice never leaves it.", systemImage: "lock")
|
||
.font(.system(size: 13))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.multilineTextAlignment(.center)
|
||
.labelStyle(OnboardingInlineLabelStyle())
|
||
}
|
||
}
|
||
|
||
private struct OnboardingInlineLabelStyle: LabelStyle {
|
||
func makeBody(configuration: Configuration) -> some View {
|
||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||
configuration.icon.font(.system(size: 11, weight: .medium))
|
||
configuration.title
|
||
}
|
||
}
|
||
}
|
||
|
||
/// A permission row: icon, title, a one-line detail that stays (so both rows keep one height),
|
||
/// and on the right either its action pill or, once done, only a check.
|
||
struct OnboardingPermissionRow: View {
|
||
let icon: String
|
||
let title: LocalizedStringKey
|
||
let detail: LocalizedStringKey
|
||
let done: Bool
|
||
let actionTitle: LocalizedStringKey
|
||
let action: () -> Void
|
||
|
||
var body: some View {
|
||
if done {
|
||
content
|
||
.accessibilityElement(children: .ignore)
|
||
.accessibilityLabel(Text(title))
|
||
.accessibilityValue(Text("Done"))
|
||
} else {
|
||
Button(action: action) { content }
|
||
.buttonStyle(OnboardingPressStyle())
|
||
.accessibilityLabel(Text(title))
|
||
.accessibilityHint(Text(actionTitle))
|
||
}
|
||
}
|
||
|
||
private var content: some View {
|
||
HStack(alignment: .center, spacing: 12) {
|
||
Image(systemName: icon)
|
||
.font(.system(size: 17, weight: .regular))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.frame(width: 24)
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text(title)
|
||
.font(.system(size: 16, weight: .medium))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
Text(detail)
|
||
.font(.system(size: 13))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
.lineLimit(1)
|
||
.minimumScaleFactor(0.85)
|
||
Spacer(minLength: 8)
|
||
ZStack(alignment: .trailing) {
|
||
OnboardingPill(title: actionTitle)
|
||
.opacity(done ? 0 : 1)
|
||
Image(systemName: "checkmark.circle.fill")
|
||
.font(.system(size: 20, weight: .medium))
|
||
.foregroundStyle(HexTheme.success)
|
||
.opacity(done ? 1 : 0)
|
||
.scaleEffect(done ? 1 : 0.8)
|
||
}
|
||
.animation(HexMotion.settle, value: done)
|
||
}
|
||
.frame(minHeight: 64)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
|
||
/// The one filled action on a page.
|
||
struct OnboardingPrimaryButton: View {
|
||
let title: LocalizedStringKey
|
||
var enabled = true
|
||
let action: () -> Void
|
||
|
||
var body: some View {
|
||
Button(action: action) {
|
||
Text(title)
|
||
.font(.system(size: 17, weight: .semibold))
|
||
.foregroundStyle(enabled ? HexTheme.textContrast : HexTheme.textFaint)
|
||
.frame(maxWidth: .infinity, minHeight: 50)
|
||
.background(enabled ? HexTheme.bgContrast : Color.white.opacity(0.07), in: Capsule())
|
||
.contentShape(Capsule())
|
||
}
|
||
.buttonStyle(OnboardingPressStyle())
|
||
.disabled(!enabled)
|
||
.animation(HexMotion.reducedFade, value: enabled)
|
||
}
|
||
}
|
||
|
||
/// A quiet text button: Skip's weight, for the second choice on a page.
|
||
struct OnboardingQuietButton: View {
|
||
let title: LocalizedStringKey
|
||
let action: () -> Void
|
||
|
||
var body: some View {
|
||
Button(title, action: action)
|
||
.font(.system(size: 15, weight: .medium))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.frame(minHeight: 44)
|
||
.contentShape(Rectangle())
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
|
||
struct OnboardingSecondaryButton: View {
|
||
let title: LocalizedStringKey
|
||
let icon: String
|
||
let action: () -> Void
|
||
|
||
var body: some View {
|
||
Button(action: action) {
|
||
HStack(spacing: 7) {
|
||
Image(systemName: icon)
|
||
.font(.system(size: 13, weight: .medium))
|
||
Text(title)
|
||
.font(.system(size: 15, weight: .medium))
|
||
}
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.frame(maxWidth: .infinity, minHeight: 44)
|
||
.background(Color.white.opacity(0.09), in: Capsule())
|
||
.contentShape(Capsule())
|
||
}
|
||
.buttonStyle(OnboardingPressStyle())
|
||
}
|
||
}
|
||
|
||
/// The small action pill on the right of a row; the row itself is the button.
|
||
struct OnboardingPill: View {
|
||
let title: LocalizedStringKey
|
||
|
||
var body: some View {
|
||
Text(title)
|
||
.font(.system(size: 13, weight: .medium))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
.padding(.horizontal, 12)
|
||
.frame(height: 28)
|
||
.background(Color.white.opacity(0.09), in: Capsule())
|
||
.fixedSize()
|
||
}
|
||
}
|
||
|
||
struct OnboardingPressStyle: ButtonStyle {
|
||
func makeBody(configuration: Configuration) -> some View {
|
||
configuration.label
|
||
.opacity(configuration.isPressed ? 0.7 : 1)
|
||
}
|
||
}
|