mirror of
https://github.com/block/buzz.git
synced 2026-10-30 05:51:46 +00:00
## Summary - add iOS and Android voice-note recording and preview directly in the mobile composer - add waveform playback, scrubbing, speed controls, haptics, and one-shot playback in chat - package recordings in a canonical H.264/AAC MP4 envelope on both platforms so existing relays accept them - preserve the shared composer interaction and attachment-card treatment across mobile platforms Mobile counterpart to #6978. ## Testing - `just ci` - `just mobile-check` - `just mobile-test` (2,026 tests) - Android debug build compiled, installed, launched, and Voice note verified in the attachment menu on Pixel 10 - signed iOS device build installed on iPhone --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz> Signed-off-by: Kenny Lopez <klopez4212@gmail.com> Signed-off-by: Carl <3c4caeafb646d23867f1c4832e68211d77e2561946171625f75c3ce1a3f2670f@buzz.block.builderlab.xyz> Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz> Co-authored-by: Carl <3c4caeafb646d23867f1c4832e68211d77e2561946171625f75c3ce1a3f2670f@buzz.block.builderlab.xyz>
196 lines
5.8 KiB
Swift
196 lines
5.8 KiB
Swift
import Flutter
|
|
import UIKit
|
|
|
|
final class ConcentricSheetSurfaceFactory: NSObject, FlutterPlatformViewFactory {
|
|
private let messenger: FlutterBinaryMessenger
|
|
|
|
init(messenger: FlutterBinaryMessenger) {
|
|
self.messenger = messenger
|
|
super.init()
|
|
}
|
|
|
|
func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
|
|
FlutterStandardMessageCodec.sharedInstance()
|
|
}
|
|
|
|
func create(
|
|
withFrame frame: CGRect,
|
|
viewIdentifier viewId: Int64,
|
|
arguments args: Any?
|
|
) -> FlutterPlatformView {
|
|
ConcentricSheetSurfacePlatformView(
|
|
frame: frame,
|
|
viewIdentifier: viewId,
|
|
messenger: messenger,
|
|
arguments: args
|
|
)
|
|
}
|
|
}
|
|
|
|
final class ConcentricSheetSurfacePlatformView: NSObject, FlutterPlatformView {
|
|
private let rootView: UIView
|
|
private let surfaceView: UIView
|
|
private let channel: FlutterMethodChannel
|
|
private let corners: String
|
|
private let usesGlass: Bool
|
|
|
|
init(
|
|
frame: CGRect,
|
|
viewIdentifier viewId: Int64,
|
|
messenger: FlutterBinaryMessenger,
|
|
arguments args: Any?
|
|
) {
|
|
let arguments = args as? [String: Any]
|
|
let colorValue = (arguments?["color"] as? NSNumber)?.uint32Value ?? 0xFFFF_FFFF
|
|
let backdropColorValue = (arguments?["backdropColor"] as? NSNumber)?.uint32Value
|
|
let minimumRadius = (arguments?["minimumRadius"] as? NSNumber)?.doubleValue ?? 24
|
|
corners = arguments?["corners"] as? String ?? "all"
|
|
usesGlass = (arguments?["usesGlass"] as? NSNumber)?.boolValue == true
|
|
|
|
rootView = UIView(frame: frame)
|
|
rootView.isUserInteractionEnabled = false
|
|
rootView.isOpaque = !usesGlass && backdropColorValue != nil
|
|
rootView.backgroundColor = backdropColorValue.map { Self.color(from: $0) } ?? .clear
|
|
|
|
if #available(iOS 26.0, *), usesGlass {
|
|
let effect = UIGlassEffect(style: .regular)
|
|
effect.isInteractive = false
|
|
surfaceView = UIVisualEffectView(effect: effect)
|
|
} else {
|
|
surfaceView = UIView()
|
|
}
|
|
surfaceView.frame = rootView.bounds
|
|
surfaceView.isUserInteractionEnabled = false
|
|
surfaceView.isOpaque = !usesGlass
|
|
surfaceView.clipsToBounds = true
|
|
surfaceView.layer.cornerCurve = .continuous
|
|
surfaceView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
rootView.addSubview(surfaceView)
|
|
|
|
channel = FlutterMethodChannel(
|
|
name: "buzz/concentric_sheet_surface/\(viewId)",
|
|
binaryMessenger: messenger
|
|
)
|
|
|
|
super.init()
|
|
|
|
updateColors(
|
|
colorValue: colorValue,
|
|
backdropColorValue: backdropColorValue
|
|
)
|
|
applyInterfaceStyle(from: arguments?["brightness"])
|
|
applyCornerConfiguration(minimumRadius: minimumRadius)
|
|
|
|
channel.setMethodCallHandler { [weak self] call, result in
|
|
guard let self else {
|
|
result(nil)
|
|
return
|
|
}
|
|
switch call.method {
|
|
case "updateColors":
|
|
guard
|
|
let arguments = call.arguments as? [String: Any],
|
|
let colorValue = arguments["color"] as? NSNumber
|
|
else {
|
|
result(
|
|
FlutterError(
|
|
code: "invalid_arguments",
|
|
message: "Expected a surface color.",
|
|
details: nil
|
|
)
|
|
)
|
|
return
|
|
}
|
|
|
|
self.updateColors(
|
|
colorValue: colorValue.uint32Value,
|
|
backdropColorValue: (arguments["backdropColor"] as? NSNumber)?.uint32Value
|
|
)
|
|
result(nil)
|
|
case "updateGeometry":
|
|
guard
|
|
let arguments = call.arguments as? [String: Any],
|
|
let minimumRadius = arguments["minimumRadius"] as? NSNumber
|
|
else {
|
|
result(
|
|
FlutterError(
|
|
code: "invalid_arguments",
|
|
message: "Expected a minimum corner radius.",
|
|
details: nil
|
|
)
|
|
)
|
|
return
|
|
}
|
|
self.applyInterfaceStyle(from: arguments["brightness"])
|
|
self.applyCornerConfiguration(
|
|
minimumRadius: minimumRadius.doubleValue
|
|
)
|
|
result(nil)
|
|
default:
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
}
|
|
|
|
deinit {
|
|
channel.setMethodCallHandler(nil)
|
|
}
|
|
|
|
func view() -> UIView {
|
|
rootView
|
|
}
|
|
|
|
private func updateColors(colorValue: UInt32, backdropColorValue: UInt32?) {
|
|
let surfaceColor = Self.color(from: colorValue)
|
|
if let glassView = surfaceView as? UIVisualEffectView {
|
|
glassView.backgroundColor = .clear
|
|
glassView.contentView.backgroundColor = surfaceColor.withAlphaComponent(0.12)
|
|
} else {
|
|
surfaceView.backgroundColor = surfaceColor
|
|
}
|
|
rootView.isOpaque = !usesGlass && backdropColorValue != nil
|
|
rootView.backgroundColor = backdropColorValue.map { Self.color(from: $0) } ?? .clear
|
|
}
|
|
|
|
private func applyCornerConfiguration(minimumRadius: CGFloat) {
|
|
if #available(iOS 26.0, *) {
|
|
let radius = UICornerRadius.containerConcentric(minimum: minimumRadius)
|
|
surfaceView.cornerConfiguration =
|
|
corners == "bottom"
|
|
? .uniformBottomRadius(
|
|
radius,
|
|
topLeftRadius: nil,
|
|
topRightRadius: nil
|
|
)
|
|
: .uniformCorners(radius: radius)
|
|
} else {
|
|
surfaceView.layer.cornerRadius = minimumRadius
|
|
if corners == "bottom" {
|
|
surfaceView.layer.maskedCorners = [
|
|
.layerMinXMaxYCorner,
|
|
.layerMaxXMaxYCorner,
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
private func applyInterfaceStyle(from value: Any?) {
|
|
switch value as? String {
|
|
case "dark":
|
|
rootView.overrideUserInterfaceStyle = .dark
|
|
case "light":
|
|
rootView.overrideUserInterfaceStyle = .light
|
|
default:
|
|
rootView.overrideUserInterfaceStyle = .unspecified
|
|
}
|
|
}
|
|
|
|
private static func color(from value: UInt32) -> UIColor {
|
|
let alpha = CGFloat((value >> 24) & 0xFF) / 255
|
|
let red = CGFloat((value >> 16) & 0xFF) / 255
|
|
let green = CGFloat((value >> 8) & 0xFF) / 255
|
|
let blue = CGFloat(value & 0xFF) / 255
|
|
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
|
|
}
|
|
}
|