Periphery cleanup (#5893)

This commit is contained in:
Mauro
2026-07-20 11:16:11 +02:00
committed by GitHub
parent 175aca596e
commit 9093631f8b
275 changed files with 381 additions and 2268 deletions
@@ -195,7 +195,6 @@ enum A11yIdentifiers {
struct RoomDetailsScreen {
let addTopic = "room_details-add_topic"
let avatar = "room_details-avatar"
let dmAvatar = "room_details-dm_avatar"
let people = "room_details-people"
let notifications = "room_details-notifications"
let pollsHistory = "room_details-polls_history"
@@ -333,8 +332,6 @@ enum A11yIdentifiers {
}
struct SpacesScreen {
let userAvatar = "spaces_screen-user_avatar"
let roomNamePrefix = "spaces_screen-room_name"
func spaceRoomName(_ name: String) -> String {
"\(roomNamePrefix):\(name)"
+1 -1
View File
@@ -13,7 +13,6 @@ nonisolated enum CallIntent: String, Codable, CaseIterable {
}
nonisolated extension CallIntent {
// periphery:ignore - Unused, but added to detect new cases when updating the SDK.
init(rustCallIntent: MatrixRustSDK.RtcCallIntent) {
switch rustCallIntent {
case .audio: self = .audio
@@ -21,6 +20,7 @@ nonisolated extension CallIntent {
}
}
// periphery:ignore - might be useful to have
var rustCallIntent: MatrixRustSDK.RtcCallIntent {
switch self {
case .audio: .audio
@@ -8,7 +8,6 @@
import Foundation
// periphery:ignore - property wrappers generate false positives
@propertyWrapper
struct CancellableTask<S: Sendable, F: Error> {
private var storedValue: Task<S, F>?
@@ -97,10 +97,6 @@ private nonisolated extension [Bit] {
try takeBits(8)
}
mutating func takeUInt16() throws(BitError) -> UInt16 {
try takeBits16(16)
}
mutating func takeBinarySegment(_ version: Int) throws(BitError) -> [UInt8] {
let characterCountLength = version > 9 ? 16 : 8
let charactersCount = try takeBits16(characterCountLength)
@@ -45,18 +45,6 @@ nonisolated extension AttributedString {
return components
}
/// Replaces the specified placeholder with a string that links to the specified URL.
/// - Parameters:
/// - linkPlaceholder: The text in the string that will be replaced. Make sure this is unique within the string.
/// - string: The text for the link that will be substituted into the placeholder.
/// - url: The URL that the link should open.
mutating func replace(_ linkPlaceholder: String, with string: String, asLinkTo url: URL) {
// Replace the placeholder with a link.
var replacement = AttributedString(string)
replacement.link = url
replace(linkPlaceholder, with: replacement)
}
/// Replaces the specified placeholder with the supplied attributed string.
/// - Parameters:
/// - placeholder: The text in the string that will be replaced. Make sure this is unique within the string.
@@ -13,8 +13,4 @@ extension CompoundIcon {
init(asset: ImageAsset) {
self.init(customImage: asset.swiftUIImage)
}
init(asset: ImageAsset, size: CompoundIcon.Size, relativeTo font: Font) {
self.init(customImage: asset.swiftUIImage, size: size, relativeTo: font)
}
}
@@ -13,19 +13,6 @@ protocol ConfirmationDialogProtocol {
}
extension View {
func confirmationDialog<Item: ConfirmationDialogProtocol, Actions: View>(item: Binding<Item?>,
titleVisibility: Visibility = .automatic,
@ViewBuilder actions: (Item) -> Actions) -> some View {
let binding = Binding<Bool>(get: {
item.wrappedValue != nil
}, set: { newValue in
if !newValue {
item.wrappedValue = nil
}
})
return confirmationDialog(item.wrappedValue?.title ?? "", isPresented: binding, titleVisibility: titleVisibility, presenting: item.wrappedValue, actions: actions)
}
// periphery: ignore - not used yet but might be useful
func confirmationDialog<Item: ConfirmationDialogProtocol, Actions: View, Message: View>(item: Binding<Item?>,
titleVisibility: Visibility = .automatic,
@@ -1,46 +0,0 @@
//
// Copyright 2025 Element Creations Ltd.
// Copyright 2022-2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Compound
import SwiftUI
extension Label {
/// Creates a label using a local asset as a Compound icon and a title generated from a string.
/// The icon size will be 24pt, scaling relative to the `bodyLG` with Dynamic Type.
/// - Parameters:
/// - title: A string used as the label’s title.
/// - iconAsset: The asset to use as the custom Compound icon.
///
/// The supplied asset should have a square frame or it may end up distorted.
init(_ title: some StringProtocol, iconAsset: ImageAsset) where Title == Text, Icon == CompoundIcon {
self.init {
Text(title)
} icon: {
CompoundIcon(customImage: iconAsset.swiftUIImage)
}
}
/// Creates a label using a local asset as a Compound icon and a title generated from a string.
/// - Parameters:
/// - title: A string used as the label’s title.
/// - iconAsset: The asset to use as the custom Compound icon.
/// - size: The size of the icon.
/// - font: The font that the icon will scale relative to for Dynamic Type.
///
/// The supplied asset should have a square frame or it may end up distorted.
init(_ title: some StringProtocol,
iconAsset: ImageAsset,
iconSize: CompoundIcon.Size,
relativeTo font: Font) where Title == Text, Icon == CompoundIcon {
self.init {
Text(title)
} icon: {
CompoundIcon(customImage: iconAsset.swiftUIImage, size: iconSize, relativeTo: font)
}
}
}
@@ -10,6 +10,7 @@ import SwiftUI
import UniformTypeIdentifiers
nonisolated extension String {
// periphery:ignore - might be useful to have
/// Returns the string as an `AttributedString` with the specified character tinted in a different color.
/// - Parameters:
/// - character: The character to be tinted.
@@ -10,6 +10,7 @@ import Combine
import Foundation
public extension Task where Success == Never, Failure == Never {
// periphery:ignore - might be useful to have
/// Dispatches the given closure onto the given queue, wrapped within
/// a continuation to make it non-blocking and awaitable.
///
@@ -1,194 +0,0 @@
//
// Copyright 2025 Element Creations Ltd.
// Copyright 2023-2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
import XCTest
extension XCTestCase {
/// XCTest utility that assists in subscribing to a publisher and deferring the fulfilment and results until some other actions have been performed.
/// - Parameters:
/// - publisher: The publisher to wait on.
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - until: callback that evaluates outputs until some condition is reached
/// - Returns: The deferred fulfilment to be executed after some actions and that returns the result of the publisher.
func deferFulfillment<P: Publisher>(_ publisher: P,
timeout: TimeInterval = 10,
message: String? = nil,
until condition: @escaping (P.Output) -> Bool) -> DeferredFulfillment<P.Output> {
var result: Result<P.Output, Error>?
let expectation = expectation(description: message ?? "Awaiting publisher")
var hasFullfilled = false
let cancellable = publisher
.sink { completion in
switch completion {
case .failure(let error):
result = .failure(error)
expectation.fulfill()
case .finished:
break
}
} receiveValue: { value in
if condition(value), !hasFullfilled {
result = .success(value)
expectation.fulfill()
hasFullfilled = true
}
}
return DeferredFulfillment<P.Output> {
await self.fulfillment(of: [expectation], timeout: timeout)
cancellable.cancel()
let unwrappedResult = try XCTUnwrap(result, "Awaited publisher did not produce any output")
return try unwrappedResult.get()
}
}
/// XCTest utility that assists in observing an async sequence, deferring the fulfilment and results until some condition has been met.
/// - Parameters:
/// - asyncSequence: The sequence to wait on.
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - until: callback that evaluates outputs until some condition is reached
/// - Returns: The deferred fulfilment to be executed after some actions and that returns the result of the sequence.
func deferFulfillment<Value>(_ asyncSequence: any AsyncSequence<Value, Never>,
timeout: TimeInterval = 10,
message: String? = nil,
until condition: @escaping (Value) -> Bool) -> DeferredFulfillment<Value> {
var result: Result<Value, Error>?
let expectation = expectation(description: message ?? "Awaiting sequence")
var hasFulfilled = false
let task = Task {
for await value in asyncSequence {
if condition(value), !hasFulfilled {
result = .success(value)
expectation.fulfill()
hasFulfilled = true
}
}
}
return DeferredFulfillment<Value> {
await self.fulfillment(of: [expectation], timeout: timeout)
task.cancel()
let unwrappedResult = try XCTUnwrap(result, "Awaited sequence did not produce any output")
return try unwrappedResult.get()
}
}
/// XCTest utility that assists in subscribing to a publisher and deferring the fulfilment and results until some other actions have been performed.
/// - Parameters:
/// - publisher: The publisher to wait on.
/// - keyPath: the key path for the expected values
/// - transitionValues: the values through which the keypath needs to transition through
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - Returns: The deferred fulfilment to be executed after some actions and that returns the result of the publisher.
func deferFulfillment<P: Publisher, K: KeyPath<P.Output, V>, V: Equatable>(_ publisher: P,
keyPath: K,
transitionValues: [V],
timeout: TimeInterval = 10,
message: String? = nil) -> DeferredFulfillment<P.Output> {
var expectedOrder = transitionValues
return deferFulfillment(publisher, timeout: timeout, message: message) { value in
let receivedValue = value[keyPath: keyPath]
if let index = expectedOrder.firstIndex(where: { $0 == receivedValue }), index == 0 {
expectedOrder.remove(at: index)
}
return expectedOrder.isEmpty
}
}
/// XCTest utility that assists in subscribing to an async sequence and deferring the fulfilment and results until some other actions have been performed.
/// - Parameters:
/// - asyncSequence: The sequence to wait on.
/// - transitionValues: the values through which the sequence needs to transition through
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - Returns: The deferred fulfilment to be executed after some actions and that returns the result of the sequence.
func deferFulfillment<Value: Equatable>(_ asyncSequence: any AsyncSequence<Value, Never>,
transitionValues: [Value],
timeout: TimeInterval = 10,
message: String? = nil) -> DeferredFulfillment<Value> {
var expectedOrder = transitionValues
return deferFulfillment(asyncSequence, timeout: timeout, message: message) { value in
if let index = expectedOrder.firstIndex(where: { $0 == value }), index == 0 {
expectedOrder.remove(at: index)
}
return expectedOrder.isEmpty
}
}
/// XCTest utility that assists in subscribing to a publisher and deferring the failure for a particular value until some other actions have been performed.
/// - Parameters:
/// - publisher: The publisher to wait on.
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - until: callback that evaluates outputs until some condition is reached
/// - Returns: The deferred fulfilment to be executed after some actions. The publisher's result is not returned from this fulfilment.
func deferFailure<P: Publisher>(_ publisher: P,
timeout: TimeInterval,
message: String? = nil,
until condition: @escaping (P.Output) -> Bool) -> DeferredFulfillment<Void> where P.Failure == Never {
let expectation = expectation(description: message ?? "Awaiting publisher")
expectation.isInverted = true
var hasFulfilled = false
let cancellable = publisher
.sink { value in
if condition(value), !hasFulfilled {
expectation.fulfill()
hasFulfilled = true
}
}
return DeferredFulfillment<Void> {
await self.fulfillment(of: [expectation], timeout: timeout)
cancellable.cancel()
}
}
/// XCTest utility that assists in subscribing to an async sequence and deferring the failure for a particular value until some other actions have been performed.
/// - Parameters:
/// - asyncSequence: The sequence to wait on.
/// - timeout: A timeout after which we give up.
/// - message: An optional custom expectation message
/// - until: callback that evaluates outputs until some condition is reached
/// - Returns: The deferred fulfilment to be executed after some actions. The sequence's result is not returned from this fulfilment.
func deferFailure<Value>(_ asyncSequence: any AsyncSequence<Value, Never>,
timeout: TimeInterval,
message: String? = nil,
until condition: @escaping (Value) -> Bool) -> DeferredFulfillment<Void> {
let expectation = expectation(description: message ?? "Awaiting sequence")
expectation.isInverted = true
var hasFulfilled = false
let task = Task {
for await value in asyncSequence {
if condition(value), !hasFulfilled {
expectation.fulfill()
hasFulfilled = true
}
}
}
return DeferredFulfillment<Void> {
await self.fulfillment(of: [expectation], timeout: timeout)
task.cancel()
}
}
struct DeferredFulfillment<T> {
let closure: () async throws -> T
@discardableResult func fulfill() async throws -> T {
try await closure()
}
}
}
@@ -43,6 +43,7 @@ enum RoomAliasAttribute: AttributedStringKey {
enum EventOnRoomIDAttribute: AttributedStringKey {
struct Value: Hashable {
let roomID: String
// periphery:ignore - used via the synthesized Hashable conformance
let eventID: String
}
@@ -52,6 +53,7 @@ enum EventOnRoomIDAttribute: AttributedStringKey {
enum EventOnRoomAliasAttribute: AttributedStringKey {
struct Value: Hashable {
let alias: String
// periphery:ignore - used via the synthesized Hashable conformance
let eventID: String
}
@@ -73,25 +75,32 @@ enum InlineCodeAttribute: AttributedStringKey {
static let name = "MXInlineCodeAttribute"
}
// periphery: ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
nonisolated extension AttributeScopes {
struct ElementXAttributes: AttributeScope {
let blockquote: BlockquoteAttribute
let userID: UserIDAttribute
// periphery:ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
let userDisplayName: UserDisplayNameAttribute
// periphery:ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
let roomDisplayName: RoomDisplayNameAttribute
let roomID: RoomIDAttribute
let roomAlias: RoomAliasAttribute
let eventOnRoomID: EventOnRoomIDAttribute
let eventOnRoomAlias: EventOnRoomAliasAttribute
// periphery:ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
let allUsersMention: AllUsersMentionAttribute
let codeBlock: CodeBlockAttribute
// periphery:ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
let inlineCode: InlineCodeAttribute
// periphery:ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
let swiftUI: SwiftUIAttributes
// periphery:ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
let uiKit: UIKitAttributes
}
+1 -4
View File
@@ -94,6 +94,7 @@ nonisolated struct InfoPlistReader {
infoPlistValue(forKey: Keys.productionAppName)
}
// periphery:ignore - only used in release builds
/// Whether or not the build is from the Nightly stream.
var isNightlyBuild: Bool {
infoPlistValue(forKey: Keys.isNightlyBuild)
@@ -105,10 +106,6 @@ nonisolated struct InfoPlistReader {
customSchemeForName("Application")
}
var elementCallScheme: String {
customSchemeForName("Element Call")
}
// MARK: - Mention Pills
/// Mention Pills UTType
@@ -96,6 +96,7 @@ nonisolated enum MXLog {
#if DEBUG
private static let devPrefix = URL.documentsDirectory.pathComponents[2].uppercased()
// periphery:ignore - used for debugging
/// A helper method for print debugging, only available on debug builds.
///
/// When running on the simulator this will log `[USERNAME] message` so that
@@ -78,7 +78,9 @@ struct MessageText: UIViewRepresentable {
/// Cache key for `sizeThatFits`. Keyed on the reserved trailing size as well as the proposed
/// width to account for any changes on the send info label that happen after the first rendering.
private struct SizeCacheKey: Hashable {
// periphery:ignore - used via the synthesized Hashable conformance
let width: Double
// periphery:ignore - used via the synthesized Hashable conformance
let reservedSize: CGSize
}
@@ -48,8 +48,6 @@ struct PillView: View {
}
struct PillView_Previews: PreviewProvider, TestablePreview {
static let mockMediaProvider = MediaProviderMock(.init())
static var previews: some View {
PillView(context: PillContext.mock(viewState: .mention(isOwnMention: false,
displayText: PillUtilities.userPillDisplayText(username: "User",
@@ -29,18 +29,10 @@ class ScrollViewAdapter: NSObject, UIScrollViewDelegate {
.init(isScrollingSubject)
}
private let isAtTopEdgeSubject: CurrentValueSubject<Bool, Never> = .init(false)
var isAtTopEdge: CurrentValuePublisher<Bool, Never> {
isAtTopEdgeSubject
.asCurrentValuePublisher()
}
// MARK: - UIScrollViewDelegate
func scrollViewDidScroll(_ scrollView: UIScrollView) {
didScrollSubject.send(())
let insetContentOffset = scrollView.contentOffset.y + scrollView.contentInset.top
isAtTopEdgeSubject.send(insetContentOffset >= 3)
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
@@ -68,6 +68,7 @@ class StateStoreViewModelV2<State: BindableState, ViewAction> {
/// Intentionally non-generic so that it doesn't grow uncontrollably
let mediaProvider: MediaProviderProtocol?
// periphery:ignore - might be useful to have
/// An optional content scanning service so that views can validate media themselves.
/// `nil` when no content scanner is configured for the server, or when the screen
/// intentionally doesn't provide one because it has no media to scan.
@@ -412,7 +412,6 @@ struct LoadableImage_Previews: PreviewProvider, TestablePreview {
mediaProvider.imageFromSourceSizeClosure = { _, _ in nil }
mediaProvider.loadFileFromSourceFilenameClosure = { _, _ in .failure(.failedRetrievingFile) }
mediaProvider.loadImageDataFromSourceClosure = { _ in .failure(.failedRetrievingImage) }
mediaProvider.loadImageFromSourceSizeClosure = { _, _ in .failure(.failedRetrievingImage) }
mediaProvider.loadThumbnailForSourceSourceSizeClosure = { _, _ in .failure(.failedRetrievingThumbnail) }
mediaProvider.loadImageRetryingOnReconnectionSizeClosure = { _, _ in
Task { throw MediaProviderError.failedRetrievingImage }
@@ -41,12 +41,6 @@ struct TopBannerLayer {
}
extension View {
/// Overlays the given banner view at the top edge of this view, using a
/// slide from the top edge when `isVisible` is toggled.
func topBanner(_ banner: some View, isVisible: Bool, footer: some View = EmptyView()) -> some View {
topBanners([TopBannerLayer(banner, isVisible: isVisible)], footer: footer)
}
/// Overlays the given Z-axis banner slots at the top edge of this view.
/// Later items in the array are overlayed on top of earlier ones. Within
/// each slot, visible vertical banners are stacked in a VStack and slide
@@ -182,7 +182,6 @@ enum TestablePreviewsDictionary {
"StaticLocationSheet_Previews" : StaticLocationSheet_Previews.self,
"StickerRoomTimelineView_Previews" : StickerRoomTimelineView_Previews.self,
"SwipeRightAction_Previews" : SwipeRightAction_Previews.self,
"SwipeToReplyView_Previews" : SwipeToReplyView_Previews.self,
"TextRoomTimelineView_Previews" : TextRoomTimelineView_Previews.self,
"ThreadDecorator_Previews" : ThreadDecorator_Previews.self,
"TimelineDeliveryStatusView_Previews" : TimelineDeliveryStatusView_Previews.self,