Files
buzz/mobile/ios/Runner/ConcentricSheetSurface.swift
klopez4212 cb69ad9e4f Adapt iPhone Duo layouts, rail navigation, and native sheets (#8568)
Duo keeps conversations and Settings details open across closed, book
and flat postures. Book mode splits at the fold; flattening restores the
sidebar. Native rail controls, full-width navigation backdrops and
sheet-local safe areas keep content aligned. Ordinary iPhones remain
single-pane in portrait and landscape; tablet and Duo split layouts
remain enabled.

Includes the recovered preview's matching pane widths, Buzz empty-pane
mark, stable Settings chevrons, Bestie pane routing and Duo-only upward
New menu attachment. Current main's Activity redesign, Search content
fade and unread-navigation button are retained. Menu selection checks
sit beside their labels.

Shared mobile changes remain in scope: the native iOS status editor,
Appearance preview layout, avatar crop preservation, onboarding footer
layout, profile/invite sheet geometry and nested conversation
navigation. This PR is not exclusively Duo-gated. Nested navigator
observers preserve recording cancellation and navigation callbacks; crop
resizing preserves the selected image region. iOS 27.1 APIs remain
compile-time and runtime gated.

Validation on the reconciled source: Flutter analysis, Activity/Home
journeys, the full mobile test suite, file-size checks and Swift package
tests. The iPhone single-pane fix was also exercised on an iPhone 18 Pro
simulator before reconciliation. Fresh hosted CI and physical-device
confirmation of the reconciled build are separate and remain pending.

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Signed-off-by: Tom Brow <tomb@squareup.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Tom Brow <tomb@squareup.com>
2026-11-12 19:00:58 +00:00

267 lines
8.5 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 independentCorners: Bool
private let channel: FlutterMethodChannel
private let corners: String
private let usesGlass: Bool
private let topRadius: Double?
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"
topRadius = (arguments?["topRadius"] as? NSNumber)?.doubleValue
independentCorners = (arguments?["independentCorners"] as? NSNumber)?.boolValue == true
usesGlass = (arguments?["usesGlass"] as? NSNumber)?.boolValue == true
rootView = ConcentricSurfaceRootView(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,
glassTintColorValue: (arguments?["glassTintColor"] as? NSNumber)?.uint32Value
)
applyInterfaceStyle(from: arguments?["brightness"])
applyCornerConfiguration(minimumRadius: minimumRadius, capsule: arguments?["capsule"] as? Bool == true)
(rootView as? ConcentricSurfaceRootView)?.onLayout = { [weak self] in
guard let self else { return }
self.channel.invokeMethod("cornerRadiiChanged", arguments: self.cornerRadii())
}
channel.setMethodCallHandler { [weak self] call, result in
guard let self else {
result(nil)
return
}
switch call.method {
case "getCornerRadii":
self.rootView.layoutIfNeeded()
result(self.cornerRadii())
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,
glassTintColorValue: (arguments["glassTintColor"] 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,
capsule: arguments["capsule"] as? Bool == true
)
result(nil)
default:
result(FlutterMethodNotImplemented)
}
}
}
deinit {
channel.setMethodCallHandler(nil)
}
func view() -> UIView {
rootView
}
private func updateColors(
colorValue: UInt32,
backdropColorValue: UInt32?,
glassTintColorValue: UInt32?
) {
let surfaceColor = Self.color(from: colorValue)
if let glassView = surfaceView as? UIVisualEffectView {
if #available(iOS 26.0, *), let effect = glassView.effect as? UIGlassEffect {
effect.tintColor = glassTintColorValue.map { Self.color(from: $0) }
glassView.effect = effect
}
glassView.backgroundColor = .clear
glassView.contentView.backgroundColor = surfaceColor.withAlphaComponent(min(surfaceColor.cgColor.alpha, 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, capsule: Bool) {
if #available(iOS 26.0, *) {
if capsule {
surfaceView.cornerConfiguration = .capsule()
return
}
let radius = UICornerRadius.containerConcentric(minimum: minimumRadius)
if independentCorners {
surfaceView.cornerConfiguration = .corners(
topLeftRadius: corners == "bottom" ? nil : topRadius.map { .fixed($0) } ?? radius,
topRightRadius: corners == "bottom" ? nil : topRadius.map { .fixed($0) } ?? radius,
bottomLeftRadius: radius,
bottomRightRadius: radius
)
return
}
surfaceView.cornerConfiguration =
corners == "bottom"
? .uniformBottomRadius(
radius,
topLeftRadius: nil,
topRightRadius: nil
)
: topRadius.map {
.uniformBottomRadius(
radius,
topLeftRadius: .fixed($0),
topRightRadius: .fixed($0)
)
} ?? .uniformCorners(radius: radius)
} else {
surfaceView.layer.cornerRadius = minimumRadius
if corners == "bottom" {
surfaceView.layer.maskedCorners = [
.layerMinXMaxYCorner,
.layerMaxXMaxYCorner,
]
}
}
}
private func cornerRadii() -> [String: CGFloat] {
if #available(iOS 26.0, *) {
return [
"topLeft": surfaceView.effectiveRadius(corner: .topLeft),
"topRight": surfaceView.effectiveRadius(corner: .topRight),
"bottomLeft": surfaceView.effectiveRadius(corner: .bottomLeft),
"bottomRight": surfaceView.effectiveRadius(corner: .bottomRight),
]
}
let radius = surfaceView.layer.cornerRadius
return [
"topLeft": corners == "bottom" ? 0 : radius,
"topRight": corners == "bottom" ? 0 : radius,
"bottomLeft": radius,
"bottomRight": radius,
]
}
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)
}
}
/// Reading effective radii during layout lets UIKit invalidate the geometry
/// when the enclosing display or presentation changes.
private final class ConcentricSurfaceRootView: UIView {
var onLayout: (() -> Void)?
override func layoutSubviews() {
super.layoutSubviews()
onLayout?()
}
}