mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-25 01:30:06 +08:00
iOS keyboard: the recording transition moves to FullKeyboardView+Recording.swift (#2464)
What: setRecording and its helpers (hexKeyTucked, beginReveal, endReveal, placeReveal, recordingPanelFrame and fade), 173 lines added in #2457, move unchanged from FullKeyboardView.swift into a new extension file beside it, View/FullKeyboardView+Recording.swift. setRecording and recordingPanelFrame lose private (FullKeyboardView calls them), and wordsMask, recordingPanel, appliedLift, refreshRecordingPanel and makeRecordingPanel become internal for the moved code; showsRecording's setter does too (private(set) to internal). The moved lines are otherwise identical (checked line by line against the removed block; one blank line dropped). No behaviour changes. Why: #2457 took FullKeyboardView.swift to 1,537 lines, over the 1,500 hard cap, so scripts/code-shape.py --check fails on dev (1,522 after #2461). It is now 1,348; View/ has 8 files against the folder limit of 60. Verified: scripts/code-shape.py --check passes; the full suite on the Studio simulator (see the pull request).
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
import UIKit
|
||||
|
||||
/// Recording in and out: the Hex key hands its spot to the recording panel, and the words and
|
||||
/// the dots trade places behind one soft edge. Moved out of FullKeyboardView.swift unchanged.
|
||||
@MainActor
|
||||
extension FullKeyboardView {
|
||||
/// Recording in and out with no shape between: the Hex key hands its spot to ✓ (the key
|
||||
/// leaving as ✓ arrives, on the same frame), ✕ slides out from under ✓, and the dots come
|
||||
/// out of the key behind a soft edge that runs across the bar, wiping the words as it goes.
|
||||
/// Going back, the edge runs home into the key, the words return behind it, ✕ tucks under
|
||||
/// ✓ and the key takes its spot back. Reduce Motion crossfades instead.
|
||||
func setRecording(_ recording: Bool) {
|
||||
showsRecording = recording
|
||||
dismissStyleMenu()
|
||||
if recording { closeEmojiPanel(); hideModelNotice() }
|
||||
let animated = window != nil
|
||||
let travels = animated && !StripMotion.reduced && engine.layout.key(.hex).map { $0.row < 0 } == true
|
||||
stripView.holdsStill = recording || recordingPanel != nil
|
||||
if recording {
|
||||
plane.cancelAllTouches()
|
||||
hideUndo()
|
||||
let panel = recordingPanel ?? makeRecordingPanel()
|
||||
panel.palette = palette
|
||||
panel.frame = recordingPanelFrame
|
||||
refreshRecordingPanel()
|
||||
panel.isHidden = false
|
||||
panel.layoutIfNeeded()
|
||||
guard travels else {
|
||||
endReveal(panel)
|
||||
panel.setControls(shown: true)
|
||||
fade(in: [panel], out: [stripView, hexKey], duration: animated ? StripMotion.reducedFade : 0)
|
||||
return
|
||||
}
|
||||
panel.alpha = 1
|
||||
let fresh = beginReveal(panel)
|
||||
if fresh {
|
||||
UIView.performWithoutAnimation { panel.setControls(shown: false) }
|
||||
}
|
||||
StripMotion.animate(StripMotion.grow, fresh: fresh, {
|
||||
self.placeReveal(open: true, panel: panel)
|
||||
}, completion: { [weak self] _ in
|
||||
// Masked away, the words would still take touches.
|
||||
guard let self, self.showsRecording else { return }
|
||||
self.stripView.isHidden = true
|
||||
})
|
||||
StripMotion.animate(StripMotion.settle, fresh: fresh) { panel.setControls(shown: true) }
|
||||
StripMotion.animate(StripMotion.settleExit, {
|
||||
self.hexKey.alpha = 0
|
||||
self.hexKey.transform = self.hexKeyTucked
|
||||
}, completion: { [weak self] _ in
|
||||
// A Hex key still held for push to talk stays in the window (at alpha 0), so its
|
||||
// touch keeps arriving and lifting the finger finishes the dictation.
|
||||
guard let self, self.showsRecording, !self.hexKey.isTracking else { return }
|
||||
self.hexKey.isHidden = true
|
||||
})
|
||||
} else if let panel = recordingPanel {
|
||||
let finish = { [weak self, weak panel] in
|
||||
guard let self, !self.showsRecording, let panel, panel === self.recordingPanel else { return }
|
||||
self.stripView.holdsStill = false
|
||||
self.endReveal(panel)
|
||||
panel.tearDown()
|
||||
panel.removeFromSuperview()
|
||||
self.recordingPanel = nil
|
||||
}
|
||||
guard travels else {
|
||||
endReveal(panel)
|
||||
fade(in: [stripView, hexKey], out: [panel], duration: animated ? StripMotion.reducedFade : 0, after: finish)
|
||||
return
|
||||
}
|
||||
stripView.isHidden = false
|
||||
stripView.alpha = 1
|
||||
let fresh = beginReveal(panel)
|
||||
if fresh {
|
||||
UIView.performWithoutAnimation { placeReveal(open: true, panel: panel) }
|
||||
}
|
||||
if hexKey.isHidden || hexKey.alpha == 0 {
|
||||
hexKey.isHidden = false
|
||||
hexKey.transform = hexKeyTucked
|
||||
}
|
||||
StripMotion.animate(StripMotion.shrink, fresh: fresh, {
|
||||
self.placeReveal(open: false, panel: panel)
|
||||
}, completion: { _ in finish() })
|
||||
StripMotion.animate(StripMotion.settleExit) { panel.setControls(shown: false) }
|
||||
StripMotion.animate(StripMotion.settle) {
|
||||
self.hexKey.alpha = 1
|
||||
self.hexKey.transform = .identity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Hex key a little smaller about its keycap's centre, as it leaves and returns.
|
||||
private var hexKeyTucked: CGAffineTransform {
|
||||
let s = StripMotion.controlScale
|
||||
let cap = hexKey.keycapFrame
|
||||
let dx = cap.midX - hexKey.bounds.midX
|
||||
let dy = cap.midY - hexKey.bounds.midY
|
||||
return CGAffineTransform(translationX: dx, y: dy).scaledBy(x: s, y: s).translatedBy(x: -dx, y: -dy)
|
||||
}
|
||||
|
||||
/// Masks the words and the dots on the two sides of one soft edge. True when they were
|
||||
/// unmasked, so the edge starts at home in the Hex key; false mid-flight, where it carries on.
|
||||
private func beginReveal(_ panel: HexKeyRecordingPanel) -> Bool {
|
||||
let dotsAfter = !engine.layout.hexOnLeading
|
||||
if let wordsMask, wordsMask.opaqueAfter == !dotsAfter, panel.dotsMask?.opaqueAfter == dotsAfter {
|
||||
return false
|
||||
}
|
||||
let words = StripRevealMask(opaqueAfter: !dotsAfter)
|
||||
let dots = StripRevealMask(opaqueAfter: dotsAfter)
|
||||
stripView.mask = words
|
||||
wordsMask = words
|
||||
panel.dotsMask = dots
|
||||
UIView.performWithoutAnimation { placeReveal(open: false, panel: panel) }
|
||||
return true
|
||||
}
|
||||
|
||||
private func endReveal(_ panel: HexKeyRecordingPanel) {
|
||||
stripView.mask = nil
|
||||
wordsMask = nil
|
||||
panel.dotsMask = nil
|
||||
}
|
||||
|
||||
/// Where the edge's band starts (it is `StripRevealMask.feather` wide): home, at the Hex key's
|
||||
/// side of the bar with every dot gathered in and every word shown, or across the bar.
|
||||
private func placeReveal(open: Bool, panel: HexKeyRecordingPanel) {
|
||||
let well = panel.convert(panel.wellFrame, to: self)
|
||||
let words = stripView.frame
|
||||
let feather = StripRevealMask.feather
|
||||
let band: CGFloat = if engine.layout.hexOnLeading {
|
||||
open ? max(well.maxX, words.maxX) : min(well.minX, words.minX) - feather
|
||||
} else {
|
||||
open ? min(well.minX, words.minX) - feather : max(well.maxX, words.maxX)
|
||||
}
|
||||
wordsMask?.place(bandStart: band - words.minX)
|
||||
panel.dotsMask?.place(bandStart: band - well.minX)
|
||||
}
|
||||
|
||||
/// Where the recording panel sits: the suggestion strip, full width and its height, so
|
||||
/// neither the keyboard nor the keys move.
|
||||
var recordingPanelFrame: CGRect {
|
||||
let m = engine.layout.metrics
|
||||
return CGRect(x: 0, y: m.stripTop + appliedLift, width: bounds.width, height: m.stripHeight)
|
||||
}
|
||||
|
||||
private func fade(
|
||||
in shown: [UIView],
|
||||
out hidden: [UIView],
|
||||
duration requested: TimeInterval = 0.2,
|
||||
delay: TimeInterval = 0,
|
||||
after: (() -> Void)? = nil
|
||||
) {
|
||||
shown.forEach { $0.isHidden = false }
|
||||
let globeHidden = engine.layout.key(.globe) == nil
|
||||
let accentHidden = engine.activeAccentMenu == nil
|
||||
let duration = window == nil ? 0 : requested
|
||||
if duration == 0 {
|
||||
shown.forEach { $0.alpha = 1 }
|
||||
hidden.forEach {
|
||||
$0.alpha = 0
|
||||
$0.isHidden = true
|
||||
}
|
||||
if globeHidden { globeButton.isHidden = true }
|
||||
if accentHidden { accentCallout.isHidden = true }
|
||||
after?()
|
||||
return
|
||||
}
|
||||
UIView.animate(springDuration: duration, bounce: 0, initialSpringVelocity: 0, delay: delay * MotionDebug.slow, options: [.beginFromCurrentState, .allowUserInteraction]) {
|
||||
shown.forEach { $0.alpha = 1 }
|
||||
hidden.forEach { $0.alpha = 0 }
|
||||
} completion: { _ in
|
||||
// A Hex key still held for push to talk stays in the window (at alpha 0), so its
|
||||
// touch keeps arriving and lifting the finger finishes the dictation.
|
||||
for view in hidden where view.alpha == 0 && (view as? UIControl)?.isTracking != true {
|
||||
view.isHidden = true
|
||||
}
|
||||
if globeHidden { self.globeButton.isHidden = true }
|
||||
if accentHidden { self.accentCallout.isHidden = true }
|
||||
after?()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,15 +49,15 @@ final class FullKeyboardView: UIView {
|
||||
let globeButton = UIButton(type: .custom)
|
||||
/// The words' side of the soft edge the recording bar's dots come out of the Hex key behind
|
||||
/// (`StripRevealMask`); only while the bar is coming, shown, or going.
|
||||
private var wordsMask: StripRevealMask?
|
||||
private var recordingPanel: HexKeyRecordingPanel?
|
||||
var wordsMask: StripRevealMask?
|
||||
var recordingPanel: HexKeyRecordingPanel?
|
||||
/// The words so far over the keys while recording (Show words as you speak).
|
||||
let livePreview = LiveDictationPreviewHost()
|
||||
private var styleMenu: HexStyleMenuView?
|
||||
private(set) var palette = FullKeyboardPalette(isDark: false)
|
||||
private var didApplyPalette = false
|
||||
private var subscriptions: Set<AnyCancellable> = []
|
||||
private(set) var showsRecording = false
|
||||
var showsRecording = false
|
||||
/// The Hex key's last tap or hold started a dictation here (not by opening Hex).
|
||||
private var dictatingFromHexKey = false
|
||||
/// A finger on the bar where no word is: holding it dictates as holding the Hex key does.
|
||||
@@ -366,7 +366,7 @@ final class FullKeyboardView: UIView {
|
||||
var onPreferredHeightChange: (() -> Void)?
|
||||
|
||||
/// How much of the lift the view actually has yet, so nothing jumps before the host grows it.
|
||||
private var appliedLift: CGFloat {
|
||||
var appliedLift: CGFloat {
|
||||
max(0, min(lift, bounds.height - keysHeight))
|
||||
}
|
||||
|
||||
@@ -954,7 +954,7 @@ final class FullKeyboardView: UIView {
|
||||
return KeyboardStripNotice(title: TranslationFailure.note, detail: note.fix, button: String(localized: "Open Hex"))
|
||||
}
|
||||
|
||||
private func refreshRecordingPanel() {
|
||||
func refreshRecordingPanel() {
|
||||
guard let panel = recordingPanel, showsRecording else { return }
|
||||
panel.update(
|
||||
phase: model.stagePhase == .transcribing ? .processing : .recording,
|
||||
@@ -962,180 +962,6 @@ final class FullKeyboardView: UIView {
|
||||
)
|
||||
}
|
||||
|
||||
/// Recording in and out with no shape between: the Hex key hands its spot to ✓ (the key
|
||||
/// leaving as ✓ arrives, on the same frame), ✕ slides out from under ✓, and the dots come
|
||||
/// out of the key behind a soft edge that runs across the bar, wiping the words as it goes.
|
||||
/// Going back, the edge runs home into the key, the words return behind it, ✕ tucks under
|
||||
/// ✓ and the key takes its spot back. Reduce Motion crossfades instead.
|
||||
private func setRecording(_ recording: Bool) {
|
||||
showsRecording = recording
|
||||
dismissStyleMenu()
|
||||
if recording { closeEmojiPanel(); hideModelNotice() }
|
||||
let animated = window != nil
|
||||
let travels = animated && !StripMotion.reduced && engine.layout.key(.hex).map { $0.row < 0 } == true
|
||||
stripView.holdsStill = recording || recordingPanel != nil
|
||||
if recording {
|
||||
plane.cancelAllTouches()
|
||||
hideUndo()
|
||||
let panel = recordingPanel ?? makeRecordingPanel()
|
||||
panel.palette = palette
|
||||
panel.frame = recordingPanelFrame
|
||||
refreshRecordingPanel()
|
||||
panel.isHidden = false
|
||||
panel.layoutIfNeeded()
|
||||
guard travels else {
|
||||
endReveal(panel)
|
||||
panel.setControls(shown: true)
|
||||
fade(in: [panel], out: [stripView, hexKey], duration: animated ? StripMotion.reducedFade : 0)
|
||||
return
|
||||
}
|
||||
panel.alpha = 1
|
||||
let fresh = beginReveal(panel)
|
||||
if fresh {
|
||||
UIView.performWithoutAnimation { panel.setControls(shown: false) }
|
||||
}
|
||||
StripMotion.animate(StripMotion.grow, fresh: fresh, {
|
||||
self.placeReveal(open: true, panel: panel)
|
||||
}, completion: { [weak self] _ in
|
||||
// Masked away, the words would still take touches.
|
||||
guard let self, self.showsRecording else { return }
|
||||
self.stripView.isHidden = true
|
||||
})
|
||||
StripMotion.animate(StripMotion.settle, fresh: fresh) { panel.setControls(shown: true) }
|
||||
StripMotion.animate(StripMotion.settleExit, {
|
||||
self.hexKey.alpha = 0
|
||||
self.hexKey.transform = self.hexKeyTucked
|
||||
}, completion: { [weak self] _ in
|
||||
// A Hex key still held for push to talk stays in the window (at alpha 0), so its
|
||||
// touch keeps arriving and lifting the finger finishes the dictation.
|
||||
guard let self, self.showsRecording, !self.hexKey.isTracking else { return }
|
||||
self.hexKey.isHidden = true
|
||||
})
|
||||
} else if let panel = recordingPanel {
|
||||
let finish = { [weak self, weak panel] in
|
||||
guard let self, !self.showsRecording, let panel, panel === self.recordingPanel else { return }
|
||||
self.stripView.holdsStill = false
|
||||
self.endReveal(panel)
|
||||
panel.tearDown()
|
||||
panel.removeFromSuperview()
|
||||
self.recordingPanel = nil
|
||||
}
|
||||
guard travels else {
|
||||
endReveal(panel)
|
||||
fade(in: [stripView, hexKey], out: [panel], duration: animated ? StripMotion.reducedFade : 0, after: finish)
|
||||
return
|
||||
}
|
||||
stripView.isHidden = false
|
||||
stripView.alpha = 1
|
||||
let fresh = beginReveal(panel)
|
||||
if fresh {
|
||||
UIView.performWithoutAnimation { placeReveal(open: true, panel: panel) }
|
||||
}
|
||||
if hexKey.isHidden || hexKey.alpha == 0 {
|
||||
hexKey.isHidden = false
|
||||
hexKey.transform = hexKeyTucked
|
||||
}
|
||||
StripMotion.animate(StripMotion.shrink, fresh: fresh, {
|
||||
self.placeReveal(open: false, panel: panel)
|
||||
}, completion: { _ in finish() })
|
||||
StripMotion.animate(StripMotion.settleExit) { panel.setControls(shown: false) }
|
||||
StripMotion.animate(StripMotion.settle) {
|
||||
self.hexKey.alpha = 1
|
||||
self.hexKey.transform = .identity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Hex key a little smaller about its keycap's centre, as it leaves and returns.
|
||||
private var hexKeyTucked: CGAffineTransform {
|
||||
let s = StripMotion.controlScale
|
||||
let cap = hexKey.keycapFrame
|
||||
let dx = cap.midX - hexKey.bounds.midX
|
||||
let dy = cap.midY - hexKey.bounds.midY
|
||||
return CGAffineTransform(translationX: dx, y: dy).scaledBy(x: s, y: s).translatedBy(x: -dx, y: -dy)
|
||||
}
|
||||
|
||||
/// Masks the words and the dots on the two sides of one soft edge. True when they were
|
||||
/// unmasked, so the edge starts at home in the Hex key; false mid-flight, where it carries on.
|
||||
private func beginReveal(_ panel: HexKeyRecordingPanel) -> Bool {
|
||||
let dotsAfter = !engine.layout.hexOnLeading
|
||||
if let wordsMask, wordsMask.opaqueAfter == !dotsAfter, panel.dotsMask?.opaqueAfter == dotsAfter {
|
||||
return false
|
||||
}
|
||||
let words = StripRevealMask(opaqueAfter: !dotsAfter)
|
||||
let dots = StripRevealMask(opaqueAfter: dotsAfter)
|
||||
stripView.mask = words
|
||||
wordsMask = words
|
||||
panel.dotsMask = dots
|
||||
UIView.performWithoutAnimation { placeReveal(open: false, panel: panel) }
|
||||
return true
|
||||
}
|
||||
|
||||
private func endReveal(_ panel: HexKeyRecordingPanel) {
|
||||
stripView.mask = nil
|
||||
wordsMask = nil
|
||||
panel.dotsMask = nil
|
||||
}
|
||||
|
||||
/// Where the edge's band starts (it is `StripRevealMask.feather` wide): home, at the Hex key's
|
||||
/// side of the bar with every dot gathered in and every word shown, or across the bar.
|
||||
private func placeReveal(open: Bool, panel: HexKeyRecordingPanel) {
|
||||
let well = panel.convert(panel.wellFrame, to: self)
|
||||
let words = stripView.frame
|
||||
let feather = StripRevealMask.feather
|
||||
let band: CGFloat = if engine.layout.hexOnLeading {
|
||||
open ? max(well.maxX, words.maxX) : min(well.minX, words.minX) - feather
|
||||
} else {
|
||||
open ? min(well.minX, words.minX) - feather : max(well.maxX, words.maxX)
|
||||
}
|
||||
wordsMask?.place(bandStart: band - words.minX)
|
||||
panel.dotsMask?.place(bandStart: band - well.minX)
|
||||
}
|
||||
|
||||
/// Where the recording panel sits: the suggestion strip, full width and its height, so
|
||||
/// neither the keyboard nor the keys move.
|
||||
private var recordingPanelFrame: CGRect {
|
||||
let m = engine.layout.metrics
|
||||
return CGRect(x: 0, y: m.stripTop + appliedLift, width: bounds.width, height: m.stripHeight)
|
||||
}
|
||||
|
||||
private func fade(
|
||||
in shown: [UIView],
|
||||
out hidden: [UIView],
|
||||
duration requested: TimeInterval = 0.2,
|
||||
delay: TimeInterval = 0,
|
||||
after: (() -> Void)? = nil
|
||||
) {
|
||||
shown.forEach { $0.isHidden = false }
|
||||
let globeHidden = engine.layout.key(.globe) == nil
|
||||
let accentHidden = engine.activeAccentMenu == nil
|
||||
let duration = window == nil ? 0 : requested
|
||||
if duration == 0 {
|
||||
shown.forEach { $0.alpha = 1 }
|
||||
hidden.forEach {
|
||||
$0.alpha = 0
|
||||
$0.isHidden = true
|
||||
}
|
||||
if globeHidden { globeButton.isHidden = true }
|
||||
if accentHidden { accentCallout.isHidden = true }
|
||||
after?()
|
||||
return
|
||||
}
|
||||
UIView.animate(springDuration: duration, bounce: 0, initialSpringVelocity: 0, delay: delay * MotionDebug.slow, options: [.beginFromCurrentState, .allowUserInteraction]) {
|
||||
shown.forEach { $0.alpha = 1 }
|
||||
hidden.forEach { $0.alpha = 0 }
|
||||
} completion: { _ in
|
||||
// A Hex key still held for push to talk stays in the window (at alpha 0), so its
|
||||
// touch keeps arriving and lifting the finger finishes the dictation.
|
||||
for view in hidden where view.alpha == 0 && (view as? UIControl)?.isTracking != true {
|
||||
view.isHidden = true
|
||||
}
|
||||
if globeHidden { self.globeButton.isHidden = true }
|
||||
if accentHidden { self.accentCallout.isHidden = true }
|
||||
after?()
|
||||
}
|
||||
}
|
||||
|
||||
/// The snapshot stage's motion scenes press the Hex key the way a finger would before recording.
|
||||
func debugPressHexKey(_ down: Bool) { hexKey.isHighlighted = down }
|
||||
|
||||
@@ -1162,7 +988,7 @@ final class FullKeyboardView: UIView {
|
||||
return s
|
||||
}
|
||||
|
||||
private func makeRecordingPanel() -> HexKeyRecordingPanel {
|
||||
func makeRecordingPanel() -> HexKeyRecordingPanel {
|
||||
let panel = HexKeyRecordingPanel(loudness: { [weak model] in model?.liveLoudnessDB ?? -62 })
|
||||
panel.alpha = 0
|
||||
panel.onDone = { [weak self] in
|
||||
|
||||
Reference in New Issue
Block a user