mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
A tester on build 117 (iPhone 14 Pro, iOS 27.2.1, Spotlight) marked the top of Hex's keyboard: a greyer rounded panel sitting inside iOS's panel, with a seam under the band iOS adds above a third-party keyboard. Ryan: the space is fine as long as it is the same colour. Cause: since #2256 a thin material sat under the whole keyboard, always. It compresses whatever is behind it: on an iPhone 17 Pro (iOS 27.2, dark mode) Hex's area read 36 where the glass is 31 (Notes), 45 where it is 54 (a light page), and stayed neutral grey where the glass takes a wallpaper's tint (Spotlight: 37,38,38 under a band of 32,37,39 in the tester's screenshot). No tint can match glass that follows its background, so Hex was a panel of another colour inside iOS's panel, with its own corners. The material was there for one reason: iOS can leave Apple's keyboard under a third-party one, and Hex's keys are translucent. What the extension can observe turned out to mark that case exactly. iOS makes a new input view controller each time the keyboard comes up, tells the one before it disappeared, and frees it. In a field that takes focus as its screen appears and has an input accessory view, opened with Hex, it doesn't: switching to Apple's keyboard gives Hex no viewWillDisappear and keeps its controller and remote view; Apple's keyboard is added beside it, and switching back makes a second Hex on top without taking Apple's away. Opened with Apple's keyboard, the same field hides and frees Hex as usual and nothing is left behind, and so do a field focused by a tap, Safari and Spotlight (iOS 27.0 and 27.2 simulators, a keyboard extension logging its own lifecycle). Changed: - KeyboardsOnScreen (new, pure): Hex's keyboards on screen in this process, in order, each with its field (UIKit's documentIdentifier). A keyboard is over another when an earlier one was never told to disappear and is still in the same field; a field UIKit hasn't named counts as the same one. - KeyboardViewController keeps one for the process (viewWillAppear, viewWillDisappear, deinit, and the field in textDidChange) and shows its backdrop only while its keyboard is over another. Otherwise the backdrop is hidden and Hex draws nothing behind its keys: its background is iOS's glass, the colour of iOS's band and of the globe row, on any background. - KeyboardBackdropView is unchanged in what it draws (the ultra-thin material, shaded in dark mode, the panel's corners). Replaced: the always-on material from #2256. Its protection is kept for the case it was for; in that case Hex still shows the material's slightly different tone until the keyboard is next dismissed. Verified: - xcodebuild test on an iPhone 17 Pro simulator (iOS 27.2), Mac Studio: 693 tests, 3 skipped (AppleSpeechClipTests and the two TypingReplayTests, which need local files), 0 failures. KeyboardLayoutTests has the on-screen rule (dismiss and reopen, the kept keyboard, another field, an unnamed field, a keyboard appearing again) beside the material's and outline's cases. - iOS 27.0 and 27.2 simulators with this build: the accessory field opened with Hex is clear; after Hex, Apple's keyboard, Hex it is covered and shows no key shapes (light and dark); reopened it is clear again. Opened with Apple's keyboard, a tap-focused field, Safari, another app after Safari and Spotlight stay clear after switching, with nothing showing through. Hex's area equals the glass beside it exactly (0 of 255) over a white app, light and dark web pages and Spotlight, light and dark. - The strip over real glass, light and dark: suggestions, the correction chip, the Full Access hint, the emoji panel and emoji search (live), and recording, transcribing and Undo dictation in the snapshot stage. - Apple's keys overlaid on Hex's (iPhone 17 Pro, iOS 27.2 simulator), with and without iOS's band: every key edge on Apple's pixel, as before. - Ryan's iPhone 17 Pro (iOS 27.2): Spotlight over his wallpaper, Notes, a Safari form and DuckDuckGo. The step at Hex's top edge went from 8, 5 to the background's own texture (0 in Notes), and at its bottom edge from 6, 5, 8, 9 to 1, 0, 0, 0. Switching to Apple's keyboard and back in each, and dismissing and refocusing DuckDuckGo's field, stayed clear with no trace of another keyboard. Not verified: the leftover-keys case on a real iPhone (no field there reproduces it, so the cover engaging on a device is untested), a keyboard process iOS restarts between the two keyboards (the new process can't know of the earlier keyboard), Paste and Paste dictation over glass (they need Full Access on the simulator), iOS 26 and earlier, an iPad, a Duo.
133 lines
7 KiB
Swift
133 lines
7 KiB
Swift
import UIKit
|
|
|
|
/// A thin blurred material under everything the keyboard extension draws, shown only when iOS
|
|
/// may have left Apple's keyboard under Hex. The rest of the time Hex draws nothing behind its
|
|
/// keys, so its background is iOS's own glass panel: the same colour as the band iOS adds above
|
|
/// a third-party keyboard and the globe row under it, over any app or wallpaper.
|
|
///
|
|
/// iOS 26 and later draw a glass panel behind a third-party keyboard, and Hex's keys are
|
|
/// translucent. In a field that takes focus as its screen appears and has an input accessory
|
|
/// view, opened with Hex, switching to Apple's keyboard and back leaves Apple's whole key plane
|
|
/// in the app's view tree under the new Hex (`KeyboardsOnScreen` has the mechanism; iOS 27.0
|
|
/// and 27.2 simulators, every switch, also under a bare keyboard extension with a clear view).
|
|
/// A keyboard can't see or remove that view, only cover it, and `KeyboardsOnScreen.isOverAnother`
|
|
/// says when: an earlier Hex keyboard iOS never took off screen in the same field.
|
|
///
|
|
/// The cover was always on: first an opaque fill (34,34,35 dark), a slab 20 darker than the
|
|
/// glass over light pages; then this material everywhere, which reads 36 where the glass is 31
|
|
/// (Notes) and 46 where it is 54 (a light page, iPhone 17 Pro, iOS 27.2, dark mode) and stays
|
|
/// neutral grey where the glass takes a wallpaper's tint (Spotlight: 37,38,38 under a band of
|
|
/// 32,37,39). Either way Hex was a panel of another colour inside iOS's panel, with its own
|
|
/// corners and a seam under the band. Now the material is only there in the one case that
|
|
/// needs it, where the leftover keys are an even, slightly lighter tone with no shapes.
|
|
@MainActor
|
|
final class KeyboardBackdropView: UIView {
|
|
/// The thinnest system material: closest to the bare glass (228,230,232 on a glass of
|
|
/// 226,227,232, light keyboard over a white app, iOS 27.2 simulator), with the same blur as
|
|
/// the thicker ones.
|
|
nonisolated static func blurStyle(isDark: Bool) -> UIBlurEffect.Style {
|
|
isDark ? .systemUltraThinMaterialDark : .systemUltraThinMaterialLight
|
|
}
|
|
|
|
/// The panel's top corners are circular with a 26 pt radius (iPhone 17, 17 Pro, 17 Pro Max,
|
|
/// Air, 17e and SE, iOS 27.0 and 27.2). Where iOS draws nothing above a third-party
|
|
/// keyboard, the keyboard's top edge is the panel's, so the material rounds its own top
|
|
/// corners the same way and never draws over the app beside them. Where iOS adds its
|
|
/// 17 pt above, the panel's corners end 8.5 pt into the keyboard and the rest of each
|
|
/// rounded corner is bare glass.
|
|
nonisolated static let panelCornerRadius: CGFloat = 26
|
|
/// The glass's rim (an outline, and a highlight on one side) is about 1 pt wide: the
|
|
/// material stops inside it, at the sides and the top, so the panel's edge looks as it does
|
|
/// around Apple's keys and the material's corners are the panel's, 1 pt in.
|
|
nonisolated static let rimInset: CGFloat = 1
|
|
|
|
/// The dark material lightens the glass: 46 on Notes' 31 and 59 on a light page's 54
|
|
/// (iPhone 17 Pro, iOS 27.2). This much black over it brings both as near the glass as one
|
|
/// shade can (36 and 46, about a seventh off each way). The light material needs none.
|
|
nonisolated static func shadeAlpha(isDark: Bool) -> CGFloat { isDark ? 0.22 : 0 }
|
|
|
|
private let material = UIVisualEffectView(effect: nil)
|
|
private let shade = UIView()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
isUserInteractionEnabled = false
|
|
isAccessibilityElement = false
|
|
backgroundColor = .clear
|
|
material.isUserInteractionEnabled = false
|
|
material.clipsToBounds = true
|
|
material.layer.cornerCurve = .circular
|
|
material.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
|
|
addSubview(material)
|
|
shade.isUserInteractionEnabled = false
|
|
shade.backgroundColor = .black
|
|
material.contentView.addSubview(shade)
|
|
applyAppearance()
|
|
registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (view: KeyboardBackdropView, _) in
|
|
view.applyAppearance()
|
|
}
|
|
}
|
|
|
|
@available(*, unavailable)
|
|
required init?(coder: NSCoder) { fatalError() }
|
|
|
|
override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
material.frame = Self.frame(in: bounds)
|
|
material.layer.cornerRadius = Self.cornerRadius(in: bounds)
|
|
shade.frame = material.bounds
|
|
}
|
|
|
|
private func applyAppearance() {
|
|
// Light or dark with the keyboard's traits, like its keys.
|
|
let isDark = FullKeyboardPalette.isDark(traits: traitCollection)
|
|
material.effect = UIBlurEffect(style: Self.blurStyle(isDark: isDark))
|
|
shade.alpha = Self.shadeAlpha(isDark: isDark)
|
|
}
|
|
|
|
/// Where the material draws in a keyboard of `bounds`: `inset` inside the panel's rim at
|
|
/// each side and the top, down to the keyboard's bottom.
|
|
nonisolated static func frame(in bounds: CGRect, inset: CGFloat = KeyboardBackdropView.rimInset) -> CGRect {
|
|
let dx = min(inset, bounds.width / 2), dy = min(inset, bounds.height)
|
|
return CGRect(x: bounds.minX + dx, y: bounds.minY + dy, width: bounds.width - 2 * dx, height: bounds.height - dy)
|
|
}
|
|
|
|
/// The material's top corner radius: the panel's, less the rim, where the keyboard is wide
|
|
/// and tall enough for it.
|
|
nonisolated static func cornerRadius(
|
|
in bounds: CGRect,
|
|
radius: CGFloat = KeyboardBackdropView.panelCornerRadius,
|
|
inset: CGFloat = KeyboardBackdropView.rimInset
|
|
) -> CGFloat {
|
|
let rect = frame(in: bounds, inset: inset)
|
|
return max(0, min(radius - inset, rect.width / 2, rect.height))
|
|
}
|
|
|
|
/// The material's outline: straight sides and bottom, and at the top the panel's rounded
|
|
/// corners, `inset` inside them (the same centres, where the keyboard's top is the panel's).
|
|
nonisolated static func outline(
|
|
in bounds: CGRect,
|
|
radius: CGFloat = KeyboardBackdropView.panelCornerRadius,
|
|
inset: CGFloat = KeyboardBackdropView.rimInset
|
|
) -> UIBezierPath {
|
|
let rect = frame(in: bounds, inset: inset)
|
|
guard rect.width > 0, rect.height > 0 else { return UIBezierPath() }
|
|
let r = cornerRadius(in: bounds, radius: radius, inset: inset)
|
|
guard r > 0 else { return UIBezierPath(rect: rect) }
|
|
let path = UIBezierPath()
|
|
path.move(to: CGPoint(x: rect.minX, y: rect.maxY))
|
|
path.addLine(to: CGPoint(x: rect.minX, y: rect.minY + r))
|
|
path.addArc(
|
|
withCenter: CGPoint(x: rect.minX + r, y: rect.minY + r), radius: r,
|
|
startAngle: .pi, endAngle: 1.5 * .pi, clockwise: true
|
|
)
|
|
path.addLine(to: CGPoint(x: rect.maxX - r, y: rect.minY))
|
|
path.addArc(
|
|
withCenter: CGPoint(x: rect.maxX - r, y: rect.minY + r), radius: r,
|
|
startAngle: 1.5 * .pi, endAngle: 0, clockwise: true
|
|
)
|
|
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
|
|
path.close()
|
|
return path
|
|
}
|
|
}
|