Skip to content

Commit

Permalink
Update components
Browse files Browse the repository at this point in the history
  • Loading branch information
juicyfru1t committed Oct 1, 2024
1 parent 2e2ce74 commit dc7818c
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 62 deletions.
4 changes: 2 additions & 2 deletions Sources/Addons/Alert/AlertTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import UIKit

/// Types of text fields added to the alert.
public enum AlertTextField {
public enum AlertTextField: Sendable {

/// A text field, with text and placeholder customization.
case standard(
Expand All @@ -13,7 +13,7 @@ public enum AlertTextField {
/// A text field, customizable via block for configuring the text field prior to displaying the alert.
/// This block has no return value and takes a single parameter corresponding to the text field object.
/// Use that parameter to change the text field properties.
case custom(configuration: (UITextField) -> Void)
case custom(configuration: @Sendable (UITextField) -> Void)
}

extension AlertTextField {
Expand Down
1 change: 1 addition & 0 deletions Sources/Addons/Alert/AlertTextFieldsManager.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if canImport(UIKit)
import UIKit

@MainActor
internal final class AlertTextFieldsManager: NSObject {

private let textFields: [UITextField?]
Expand Down
6 changes: 3 additions & 3 deletions Sources/Addons/DocumentPreview/DocumentPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public struct DocumentPreview: CustomStringConvertible {
/// Called when a document interaction controller’s document has been handed off to the specified application.
public let didEndSendingToApplication: ((_ bundleID: String?) -> Void)?

public var description: String {
"DocumentPreview(\"\(url)\")"
}
public let description: String

/// Creates and returns a new `DocumentPreview` object.
/// - Parameters:
Expand Down Expand Up @@ -71,6 +69,8 @@ public struct DocumentPreview: CustomStringConvertible {

self.willBeginSendingToApplication = willBeginSendingToApplication
self.didEndSendingToApplication = didEndSendingToApplication

description = "DocumentPreview(\"\(url)\")"
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Addons/DocumentPreview/DocumentPreviewAnchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import UIKit

/// Anchor of the starting point for animating the display of a document preview.
@MainActor
public struct DocumentPreviewAnchor {

/// The rectangle to use as the starting point for animating
Expand Down
18 changes: 11 additions & 7 deletions Sources/Addons/DocumentPreview/DocumentPreviewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ internal final class DocumentPreviewManager:
_ controller: UIDocumentInteractionController
) -> UIView? {
documentPreview.anchor.map { anchor in
anchor.view ?? container.view
MainActor.assumeIsolated { [container] in
anchor.view ?? container.view
}
}
}

internal func documentInteractionControllerRectForPreview(
_ controller: UIDocumentInteractionController
) -> CGRect {
documentPreview.anchor.map { anchor in
anchor.rect ?? CGRect(
x: container.view.bounds.midX,
y: container.view.bounds.midY,
width: .zero,
height: .zero
)
MainActor.assumeIsolated { [container] in
anchor.rect ?? CGRect(
x: container.view.bounds.midX,
y: container.view.bounds.midY,
width: .zero,
height: .zero
)
}
} ?? .zero
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Addons/HUD/Animation/HUDAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import UIKit

/// The animation type that should be used when the ``HUD`` is shown and hidden.
@MainActor
public enum HUDAnimation {

/// Custom animation for showing and hiding the HUD.
Expand Down
1 change: 1 addition & 0 deletions Sources/Addons/HUD/Animation/HUDCustomAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
/// A type describing the animation of showing, updating and hiding the ``HUD``.
///
/// See ``HUDDefaultAnimation`` for example.
@MainActor
public protocol HUDCustomAnimation {

/// Animates the appearance for the specified `view`.
Expand Down
6 changes: 3 additions & 3 deletions Sources/Addons/HUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UIKit
/// The HUD is displayed on top of the `UIWindow` with a dimmed background and progress in the center of the screen.
/// The style and progress of the HUD is fully customizable.
/// Use the ``progress`` and ``style`` properties for this.
@MainActor
public struct HUD: CustomStringConvertible {

/// Creates a HUD with ``HUDStyle/default`` style.
Expand All @@ -21,9 +22,7 @@ public struct HUD: CustomStringConvertible {
/// Configuration the appearance of the HUD.
public let style: HUDStyle

public var description: String {
"HUD(\(progress))"
}
public let description: String

/// Creates a HUD with progress and style representations.
/// - Parameters:
Expand All @@ -35,6 +34,7 @@ public struct HUD: CustomStringConvertible {
) {
self.progress = progress
self.style = style
description = "HUD(\(progress))"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Addons/HUD/HUDStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import UIKit

/// The style that will be applied to the appearance of the HUD.
public struct HUDStyle {
public struct HUDStyle: Sendable {

/// Default style.
///
Expand Down
4 changes: 3 additions & 1 deletion Sources/Addons/HUD/HUDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ extension HUDView {

let timer = duration.map { duration in
Timer.scheduledTimer(withTimeInterval: duration, repeats: false) { _ in
hideHUD(in: window, completion: nil)
MainActor.assumeIsolated {
hideHUD(in: window, completion: nil)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
/// The type of progress view animation of the ``HUD``.
///
/// An animation is used to update and show the `header`, `indicator` and `footer` parts of the progress view.
@MainActor
public enum ProgressAnimation {

/// Custom animation for showing progress view of the HUD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
/// A type describing the animation of updating progress view of``HUD``.
///
/// See ``ProgressDefaultAnimation`` for example.
@MainActor
public protocol ProgressCustomAnimation {

/// Animates updates of parts of the progress view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UIKit
/// Erased protocol type ``ProgressContent``.
///
/// - SeeAlso: ``ProgressContent``
@MainActor
public protocol AnyProgressContent {

/// A console log representation of `self`.
Expand Down
1 change: 1 addition & 0 deletions Sources/Addons/HUD/Progress/Content/ProgressContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UIKit
/// This protocol provides a blueprint for a content object, which encompasses content for a content view.
/// The content encapsulates all of the supported properties and behaviors for content view customization.
/// You use the content to create the content view.
@MainActor
public protocol ProgressContent: AnyProgressContent, Equatable {

/// The view type associated with the content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public struct ProgressPercentageIndicator: ProgressIndicator {
/// Additional indents to expand the container.
public let insets: UIEdgeInsets

public var logDescription: String? {
".percentage(\(ratio))"
}
public let logDescription: String?

/// Creates new indicator content.
/// - Parameters:
Expand All @@ -45,8 +43,10 @@ public struct ProgressPercentageIndicator: ProgressIndicator {
self.ratio = ratio
self.color = color
self.insets = insets
logDescription = ".percentage(\(ratio))"
}

@MainActor
public func updateContentView(_ contentView: View) -> View {
contentView.content = self

Expand Down
30 changes: 16 additions & 14 deletions Sources/Addons/HUD/Progress/Progress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Foundation
/// which are configured through the content
/// by implementing the appropriate protocols ``ProgressHeader``, ``ProgressIndicator`` and ``ProgressFooter``.
/// Each component is displayed with an animation defined in the ``animation`` property.

@MainActor
public struct Progress: CustomStringConvertible {

/// Erased type of header content.
Expand All @@ -22,20 +24,7 @@ public struct Progress: CustomStringConvertible {
/// Animation of the appearance of progress components.
public let animation: ProgressAnimation?

public var description: String {
let fields = [
"header": header,
"indicator": indicator,
"footer": footer
]

return fields
.compactMap { key, value in
value.logDescription.map { (key, $0) }
}
.map { "\($0): \($1)" }
.joined(separator: ", ")
}
public let description: String

/// Creates a new object with progress components and animation.
/// - Parameters:
Expand All @@ -57,6 +46,19 @@ public struct Progress: CustomStringConvertible {
self.indicator = indicator
self.footer = footer
self.animation = animation

let fields: [String: AnyProgressContent] = [
"header": header,
"indicator": indicator,
"footer": footer
]

description = fields
.compactMap { key, value in
value.logDescription.map { (key, $0) }
}
.map { "\($0): \($1)" }
.joined(separator: ", ")
}
}

Expand Down
8 changes: 5 additions & 3 deletions Sources/Addons/MediaPicker/MediaPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public struct MediaPicker: CustomStringConvertible {
/// called when the user has selected a still image or movie or has canceled the pick operation.
public let didFinish: (_ result: MediaPickerResult?) -> Void

public var description: String {
"ImagePicker(from: \"\(source)\")"
}
public let description: String

/// Creates a configuration for selecting media items.
/// - Parameters:
Expand Down Expand Up @@ -71,6 +69,8 @@ public struct MediaPicker: CustomStringConvertible {

self.didInitialize = didInitialize
self.didFinish = didFinish

description = "ImagePicker(from: \"\(source)\")"
}

/// Creates a configuration for selecting media items.
Expand Down Expand Up @@ -103,6 +103,8 @@ public struct MediaPicker: CustomStringConvertible {

self.didInitialize = didInitialize
self.didFinish = didFinish

description = "ImagePicker(from: \"\(source)\")"
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/Addons/MediaPicker/MediaPickerCameraSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import UIKit

/// The object that defines the settings for the camera.
public struct MediaPickerCameraSettings {
public struct MediaPickerCameraSettings: Sendable {

/// Default settings
public static let `default` = Self()
Expand Down
3 changes: 2 additions & 1 deletion Sources/Addons/MediaPicker/MediaPickerSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UIKit
///
/// A given source may not be available on a given device because the source is not physically present
/// or because it cannot currently be accessed.
@MainActor
public enum MediaPickerSource: CustomStringConvertible {

/// Specifies the device’s photo library as the source for the image picker controller.
Expand All @@ -19,7 +20,7 @@ public enum MediaPickerSource: CustomStringConvertible {
/// Specifies the device’s built-in camera with default settings as the source for the image picker controller.
public static let camera = Self.camera(settings: .default)

public var description: String {
nonisolated public var description: String {
switch self {
case .photoLibrary:
return "Photo library"
Expand Down
2 changes: 2 additions & 0 deletions Sources/Addons/Sharing/Activity/SharingActivity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extension SharingActivity {
}
}

@MainActor
public static func custom<Value: SharingVisualActivity>(_ value: Value) -> Self {
Self { navigator in
SharingActivityManager(
Expand All @@ -33,6 +34,7 @@ extension SharingActivity {
}
}

@MainActor
public static func custom<Value: SharingSilentActivity>(_ value: Value) -> Self {
Self { navigator in
SharingActivityManager(
Expand Down
Loading

0 comments on commit dc7818c

Please sign in to comment.