Files
buzz/mobile/ios/Runner/ComposerToolStripGlass.swift
klopez4212 d647c9fd98 Refine iOS composer and transcribe recordings into drafts (#9574)
Refine the iOS composer with 40-point glass controls, native attachment
menus, persistent emoji access, and selected-text formatting. The mic
now transcribes recordings on device into an editable, unsent draft;
Dictation has no five-minute recording cap or timer label, and its
waveform fills the space between the controls. Voice note remains
available in attachments with its five-minute cap. Unsupported devices
fail before recording, and audio is retained until the draft is durably
saved. Stopped dictation remains recoverable across editor teardown;
failed retention and cleanup can be retried. Recovered transcripts are
inserted only once across navigation or restart, preserving live exact
mention bindings.

Preserve selection handles over glass with animated avatars. Reduce the
conversation fade to 100 points above the keyboard and transition
continuously to 180 as the keyboard closes, without a first-frame jump
when opening; Home is unchanged.

Validation: 5,117 mobile tests and 27 crypto tests pass; analysis
passes. Prior native suite on iPhone 16/iOS 26.5: 119 pass, one
pre-existing expected failure, zero unexpected failures. Physical Air
preview approved; simulator selection/dragging and attachment flows
exercised. Fixed the native navigation test's timing race and a
community-cache cleanup test that checked a parent directory before its
asynchronous removal completed. Repository-wide `just ci` previously
stopped in unchanged `buzz-test-client` load-generator tests; new-head
hosted checks are pending.

Snapshots: production composer in an iPhone Air simulator fixture with
fictional conversation text; Photos snapshot retained from the
attachment preview.

| Composer | Attachments | Photos |
| --- | --- | --- |
| ![Keyboard-up
composer](https://github.com/user-attachments/assets/b7c8f0a4-25f8-4ca2-b8ae-11e18655e64a)
| ![Native attachment
menu](https://github.com/user-attachments/assets/5eaf5259-8e04-4da7-93f5-1b2eccab3c3c)
|
![Photos](https://github.com/user-attachments/assets/a6216b7d-5eaf-482c-b587-6052825b88fc)
|

---------

Signed-off-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Signed-off-by: Tom Brow <tomb@squareup.com>
Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Tom Brow <tomb@squareup.com>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz>
Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz>
2026-11-20 16:35:20 +00:00

122 lines
4.4 KiB
Swift

import Flutter
import SwiftUI
import UIKit
final class ComposerToolStripGlassFactory: NSObject, FlutterPlatformViewFactory {
private let messenger: FlutterBinaryMessenger
init(messenger: FlutterBinaryMessenger) { self.messenger = messenger }
func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
FlutterStandardMessageCodec.sharedInstance()
}
func create(
withFrame frame: CGRect,
viewIdentifier viewId: Int64,
arguments args: Any?
) -> FlutterPlatformView {
ComposerToolStripGlass(frame: frame, id: viewId, messenger: messenger, arguments: args)
}
}
private final class ComposerToolStripGlass: NSObject, FlutterPlatformView {
private let container = UIView()
private let channel: FlutterMethodChannel
private var hostingController: UIViewController?
private var updateGeometry: ((CGSize, String, Bool) -> Void)?
init(frame: CGRect, id: Int64, messenger: FlutterBinaryMessenger, arguments: Any?) {
channel = FlutterMethodChannel(name: "buzz/composer_tool_strip_glass/\(id)", binaryMessenger: messenger)
super.init()
container.frame = frame
container.isOpaque = false
container.backgroundColor = .clear
container.isUserInteractionEnabled = false
let brightness = (arguments as? [String: Any])?["brightness"] as? String
container.overrideUserInterfaceStyle = brightness == "dark" ? .dark : .light
if #available(iOS 26.0, *) {
let model = ComposerGlassModel()
let host = UIHostingController(rootView: ComposerMatchedGlass(model: model))
host.view.isOpaque = false
host.view.backgroundColor = .clear
host.view.isUserInteractionEnabled = false
host.view.frame = container.bounds
host.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
container.addSubview(host.view)
hostingController = host
updateGeometry = { size, phase, reduced in
let next = ComposerGlassGeometry(size: size, phase: phase)
guard model.geometry != next else { return }
let animate = model.geometry != nil && !reduced && !UIAccessibility.isReduceMotionEnabled
withAnimation(animate ? .timingCurve(0.645, 0.045, 0.355, 1, duration: 0.18) : nil) {
model.geometry = next
}
}
} else {
let surface = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
surface.autoresizingMask = [.flexibleTopMargin]
surface.layer.cornerRadius = 24
surface.layer.cornerCurve = .continuous
surface.clipsToBounds = true
container.addSubview(surface)
updateGeometry = { [weak container] size, _, _ in
guard let container else { return }
surface.frame = CGRect(x: 0, y: container.bounds.height - size.height, width: size.width, height: size.height)
}
}
channel.setMethodCallHandler { [weak self] call, result in
guard call.method == "geometry",
let args = call.arguments as? [String: Any],
let width = args["width"] as? Double,
let height = args["height"] as? Double,
width.isFinite, height.isFinite, width >= 0, height >= 0,
let phase = args["phase"] as? String
else {
result(FlutterMethodNotImplemented)
return
}
self?.updateGeometry?(CGSize(width: width, height: height), phase, args["reducedMotion"] as? Bool ?? false)
result(nil)
}
}
func view() -> UIView { container }
deinit { channel.setMethodCallHandler(nil) }
}
private struct ComposerGlassGeometry: Equatable {
let size: CGSize
let phase: String
}
@available(iOS 26.0, *)
private final class ComposerGlassModel: ObservableObject {
@Published var geometry: ComposerGlassGeometry?
}
@available(iOS 26.0, *)
private struct ComposerMatchedGlass: View {
@ObservedObject var model: ComposerGlassModel
@Namespace private var glassNamespace
var body: some View {
GlassEffectContainer {
ZStack(alignment: .bottomLeading) {
if let geometry = model.geometry {
Color.clear
.frame(width: geometry.size.width, height: geometry.size.height)
.glassEffect(.regular, in: RoundedRectangle(cornerRadius: 24))
.glassEffectID("composer-tools", in: glassNamespace)
.glassEffectTransition(.matchedGeometry)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
}
.ignoresSafeArea()
.allowsHitTesting(false)
.accessibilityHidden(true)
}
}