Some random tweaks made on a train 🚆 (#4636)

* Fix the search text field's tint colour.

* Don't allow optional content IDs in the placeholder avatar.

* Use SwiftUI to resolve the hex values in the Inspector app.

This fixes incorrect values being shown in dark/high-contrast modes.

* Fix a layout bug with the colour swatch in the Inspector app on iPhone.

* Switch to the chats tab when selecting a room with the global search screen.

* Run the latest SwiftFormat.
This commit is contained in:
Doug
2025-10-21 11:04:54 +02:00
committed by GitHub
parent 325fe09c98
commit bab9b89416
12 changed files with 55 additions and 68 deletions

View File

@@ -19,6 +19,8 @@ struct ColorsScreen: View {
}
struct ColorItem: View {
@Environment(\.self) private var environment
let color: Color
let name: String
@@ -30,10 +32,11 @@ struct ColorItem: View {
Text(name)
.font(.compound.bodyLG)
.foregroundColor(.compound.textPrimary)
Text(color.hexValue())
Text(color.hexValue(in: environment))
.font(.compound.bodySM.monospaced())
.foregroundColor(.compound.textSecondary)
}
.layoutPriority(1)
}
}
@@ -55,24 +58,24 @@ struct ColorItem: View {
}
private extension Color {
func hexValue() -> String {
let uiColor = UIColor(self)
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
var alpha: CGFloat = 0
uiColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
return "#\(red.asHex)\(green.asHex)\(blue.asHex)"
func hexValue(in environment: EnvironmentValues) -> String {
let resolved = resolve(in: environment)
return if resolved.opacity == 1 {
"#\(resolved.red.asHex)\(resolved.green.asHex)\(resolved.blue.asHex)"
} else {
"#\(resolved.red.asHex)\(resolved.green.asHex)\(resolved.blue.asHex) (\(resolved.opacity.asPercentage) opacity)"
}
}
}
private extension CGFloat {
private extension Float {
var asHex: String {
String(format: "%02X", Int((self * 255).rounded()))
}
var asPercentage: String {
String(format: "%.0f%%", self * 100)
}
}
struct ColorsScreen_Previews: PreviewProvider {

View File

@@ -14,21 +14,18 @@ public extension View {
@MainActor
@ViewBuilder
func compoundSearchField() -> some View {
if #available(iOS 26, *) {
self
} else {
introspect(.navigationStack, on: .supportedVersions, scope: .ancestor) { navigationController in
// Uses the navigation stack as .searchField is unreliable when pushing the second search bar, during the create rooms flow.
guard let searchController = navigationController.navigationBar.topItem?.searchController else { return }
// Ported from Riot iOS as this is the only reliable way to get the exact look we want.
// However this is fragile and tied to gutwrenching the current UISearchBar internals.
let textColor = UIColor.compound.textPrimary
introspect(.navigationStack, on: .supportedVersions, scope: .ancestor) { navigationController in
// Uses the navigation stack as .searchField is unreliable when pushing the second search bar, during the create rooms flow.
guard let searchController = navigationController.navigationBar.topItem?.searchController else { return }
// Ported from Riot iOS as this is the only reliable way to get the exact look we want.
// However this is fragile and tied to gutwrenching the current UISearchBar internals.
let searchTextField = searchController.searchBar.searchTextField
searchTextField.tintColor = .compound.iconAccentTertiary
if #unavailable(iOS 26.0) {
let placeholderColor = UIColor.compound.textSecondary
let textFieldTintColor = UIColor.compound.iconAccentTertiary
let textFieldBackgroundColor = UIColor.compound._bgSubtleSecondaryAlpha
let searchTextField = searchController.searchBar.searchTextField
// Magnifying glass icon.
let leftImageView = searchTextField.leftView as? UIImageView
@@ -43,9 +40,8 @@ public extension View {
clearButton?.tintColor = placeholderColor
// Text field.
searchTextField.textColor = textColor
searchTextField.backgroundColor = textFieldBackgroundColor
searchTextField.tintColor = textFieldTintColor
searchTextField.textColor = .compound.textPrimary
searchTextField.backgroundColor = .compound._bgSubtleSecondaryAlpha
// Hide the effect views so we can use the rounded rect style without any materials.
let effectBackgroundTop = searchTextField.value(forKey: "_effectBackgroundTop") as? UIView