Skip to content

Commit

Permalink
Fixes + improvements
Browse files Browse the repository at this point in the history
- fix bug with debug gesture
- fix build warnings in Xcode 16
- add / update a few snippets
  • Loading branch information
tadija committed Oct 7, 2024
1 parent a55523f commit 5f2c531
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Sources/Minions/Extensions/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public extension Locale {

// MARK: - String Helpers

extension String: LocalizedError {
extension String: @retroactive LocalizedError {
public var errorDescription: String? {
self
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Minions/Extensions/Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public extension Array {
// MARK: - String Helpers

/// - See: https://twitter.com/jckarter/status/1230987212730167296
extension String: Error {}
extension String: @retroactive Error {}

/// - See: https://www.hackingwithswift.com/example-code/strings/how-to-capitalize-the-first-letter-of-a-string
public extension String {
Expand Down
40 changes: 39 additions & 1 deletion Sources/Minions/Extensions/SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ public extension View {
self
}
}

/// - See: https://stackoverflow.com/a/71203870/2165585
@ViewBuilder
func modify(@ViewBuilder _ transform: (Self) -> (some View)?) -> some View {
if let view = transform(self), !(view is EmptyView) {
view
}
else {
self
}
}

}

// MARK: - View+Debug
Expand Down Expand Up @@ -107,7 +119,7 @@ public extension View {

func debugGesture<G: Gesture>(_ gesture: G) -> some View {
debugModifier {
$0.gesture(gesture)
$0.simultaneousGesture(gesture)
}
}
}
Expand Down Expand Up @@ -173,6 +185,32 @@ public struct ScaleButtonStyle: ButtonStyle {
}
}

// MARK: - Custom transition

extension AnyTransition {
static var verticalScale: AnyTransition {
.modifier(
active: VerticalScaleEffect(scale: 0),
identity: VerticalScaleEffect(scale: 1)
)
}
}

public struct VerticalScaleEffect: GeometryEffect {

public var scale: CGFloat

public var animatableData: CGFloat {
get { scale }
set { scale = newValue }
}

public func effectValue(size: CGSize) -> ProjectionTransform {
let scaleTransform: CGAffineTransform = .init(scaleX: 1, y: scale)
return ProjectionTransform(scaleTransform)
}
}

// MARK: - LabelStyle

public extension LabelStyle where Self == VerticalLabelStyle {
Expand Down
18 changes: 9 additions & 9 deletions Sources/Minions/Extensions/UIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,16 @@ public extension UIWindow {
.compactMap { $0 as? UIWindowScene }
}

static var first: UIWindow? {
static var firstWindow: UIWindow? {
allScenes.first?.windows.first
}

static var activeScene: UIWindowScene? {
allScenes
.filter { $0.activationState == .foregroundActive }
.first
}

static var keyWindow: UIWindow? {
activeScene?.keyWindow
}
Expand Down Expand Up @@ -499,8 +505,8 @@ public extension UIWindow {
#if os(visionOS)
false
#else
guard let first else { return false }
return !first.frame.equalTo(first.screen.bounds)
guard let firstWindow else { return false }
return !firstWindow.frame.equalTo(firstWindow.screen.bounds)
#endif
}

Expand Down Expand Up @@ -544,12 +550,6 @@ public extension UIWindow {
activeScene?.statusBarManager?.statusBarFrame
#endif
}

private static var activeScene: UIWindowScene? {
allScenes
.filter { $0.activationState == .foregroundActive }
.first
}
}

// MARK: - Custom Types
Expand Down
2 changes: 1 addition & 1 deletion Sources/Minions/Haptics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public struct Haptics {
}

#if os(watchOS)
extension WKHapticType: CaseIterable {
extension WKHapticType: @retroactive CaseIterable {
public static var allCases: [WKHapticType] {[
.notification,
.directionUp,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Minions/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public final class Log {
// MARK: Internal API

static func write(
thread: Thread = .current,
thread: String = getThreadName(.current),
fileID: String,
line: Int,
function: String,
items: Any...
) {
DispatchQueue.global(qos: .utility).async {
let line = Line(
thread: getThreadName(thread),
thread: thread,
file: extractFilename(fileID),
number: line,
function: function,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Minions/RestAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public extension RestAPIResponse {

// MARK: - Helpers

extension URL: ExpressibleByStringLiteral, Identifiable {
extension URL: @retroactive ExpressibleByStringLiteral, @retroactive Identifiable {

/// Helper for constructing `URL` using `String` literals.
public init(stringLiteral value: String) {
Expand Down
10 changes: 8 additions & 2 deletions Sources/Minions/Screen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,23 @@ private extension Device {
/// 12, 12 Pro, 13, 13 Pro, 14
return 6.06
case 2556:
/// 14 Pro, 15, 15 Pro
/// 14 Pro, 15, 15 Pro, 16
return 6.1
case 2622:
/// 16 Pro
return 6.3
case 2688:
/// Xs Max, 11 Pro Max
return 6.5
case 2778:
/// 12 Pro Max, 13 Pro Max, 14 Plus
return 6.7
case 2796:
/// 14 Pro Max, 15+, 15 Pro Max
/// 14 Pro Max, 15+, 15 Pro Max, 16+
return 6.7
case 2868:
/// 16 Pro Max
return 6.9

/// - Note: iPads

Expand Down

0 comments on commit 5f2c531

Please sign in to comment.