diff --git a/bitchat/Views/ContentComposerView.swift b/bitchat/Views/ContentComposerView.swift index 48d84611..1c56a4eb 100644 --- a/bitchat/Views/ContentComposerView.swift +++ b/bitchat/Views/ContentComposerView.swift @@ -261,7 +261,7 @@ private extension ContentComposerView { Image(systemName: "camera.circle.fill") .font(.bitchatSystem(size: 24)) .foregroundColor(composerAccentColor) - .frame(width: 36, height: 36) + .modifier(ComposerActionFrame()) .contentShape(Circle()) .onTapGesture { mediaPickerMode = .photoLibrary @@ -282,7 +282,7 @@ private extension ContentComposerView { Image(systemName: "photo.circle.fill") .font(.bitchatSystem(size: 24)) .foregroundColor(composerAccentColor) - .frame(width: 36, height: 36) + .modifier(ComposerActionFrame()) } .buttonStyle(.plain) .accessibilityLabel(Strings.choosePhoto) @@ -301,10 +301,10 @@ private extension ContentComposerView { .opacity(hasText ? 1 : 0) .allowsHitTesting(hasText) } - .frame(width: 36, height: 36) + .modifier(ComposerActionFrame()) } else { sendButtonView(enabled: hasText) - .frame(width: 36, height: 36) + .modifier(ComposerActionFrame()) } } @@ -337,7 +337,7 @@ private extension ContentComposerView { .font(.bitchatSystem(size: 24)) .foregroundColor(micColor) .modifier(PulsingOpacityModifier(active: busyTalker != nil && !voiceRecordingVM.state.isActive)) - .frame(width: 36, height: 36) + .modifier(ComposerActionFrame()) .contentShape(Circle()) .overlay( Color.clear @@ -385,7 +385,7 @@ private extension ContentComposerView { Image(systemName: "arrow.up.circle.fill") .font(.bitchatSystem(size: 24)) .foregroundColor(enabled ? activeColor : Color.gray) - .frame(width: 36, height: 36) + .modifier(ComposerActionFrame()) } .buttonStyle(.plain) .disabled(!enabled) @@ -494,3 +494,11 @@ private struct AutocompleteKeyboardNavigationModifier: ViewModifier { } #endif } + +struct ComposerActionFrame: ViewModifier { + // Match the .title2 scaling used by the composer's size-24 icons. + @ScaledMetric(relativeTo: .title2) private var scaledSize: CGFloat = 36 + func body(content: Content) -> some View { + content.frame(width: max(36, scaledSize), height: max(36, scaledSize)) + } +} diff --git a/bitchatTests/ComposerActionFrameTests.swift b/bitchatTests/ComposerActionFrameTests.swift new file mode 100644 index 00000000..c1d0ad66 --- /dev/null +++ b/bitchatTests/ComposerActionFrameTests.swift @@ -0,0 +1,71 @@ +#if os(iOS) +import XCTest +import SwiftUI +import UIKit +@testable import bitchat + +@MainActor +final class ComposerActionFrameTests: XCTestCase { + private func measure(_ view: V, at size: DynamicTypeSize) -> CGSize { + let host = UIHostingController(rootView: view.environment(\.dynamicTypeSize, size)) + _ = host.view + host.view.setNeedsLayout() + host.view.layoutIfNeeded() + return host.sizeThatFits(in: CGSize(width: 500, height: 500)) + } + + func testSizingAcrossDynamicType() { + for size in DynamicTypeSize.allCases { + let frame = measure( + Color.clear.modifier(ComposerActionFrame()), + at: size + ) + + XCTAssertGreaterThanOrEqual(frame.width, 36) + XCTAssertGreaterThanOrEqual(frame.height, 36) + + if size <= .large { + XCTAssertEqual(frame.width, 36, accuracy: 0.5) + XCTAssertEqual(frame.height, 36, accuracy: 0.5) + } + + for symbol in [ + "camera.circle.fill", + "mic.circle.fill", + "arrow.up.circle.fill" + ] { + let icon = Image(systemName: symbol) + .font(.bitchatSystem(size: 24)) + let natural = measure(icon.fixedSize(), at: size) + let allocation = measure( + icon.modifier(ComposerActionFrame()), + at: size + ) + let context = "\(symbol) at \(size)" + + XCTAssertGreaterThanOrEqual( + allocation.width + 0.5, + natural.width, + "Frame must contain \(context)" + ) + XCTAssertGreaterThanOrEqual( + allocation.height + 0.5, + natural.height, + "Frame must contain \(context)" + ) + + if size == .accessibility5 { + XCTAssertGreaterThan( + natural.width, 36, + "Fixture must exercise an enlarged icon" + ) + XCTAssertGreaterThan( + natural.height, 36, + "Fixture must exercise an enlarged icon" + ) + } + } + } + } +} +#endif