-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed build errors for macOS by adjusting availability of functions t…
…o iOS only and changing availability of the package to macOS 11 or later. WidgetSize parameters and methods referencing current device sizes moved to a separate file and made only available on iOS. Moved OverlappingImage to a folder and moved the UIImage inits to a separate file. Removed the example test that cause build crashes. Added Swift Package Index badges.
- Loading branch information
1 parent
1c1c47e
commit 03acfb1
Showing
12 changed files
with
125 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// OverlappingImage+UIImage.swift | ||
// FrameUp | ||
// | ||
// Created by Ryan Lintott on 2022-01-25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
#if canImport(UIKit) | ||
extension OverlappingImage { | ||
/// Creates an image view that overlaps content at the edges of its frame | ||
/// - Parameters: | ||
/// - uiImage: Image that will overlap content. | ||
/// - top: Overlap percent at top edge. | ||
/// - bottom: Overlap percent at bottom edge. | ||
public init(uiImage: UIImage, top: CGFloat = 0, bottom: CGFloat = 0) { | ||
self.init(Image(uiImage: uiImage), aspectRatio: uiImage.size.aspectRatio, top: top, bottom: bottom) | ||
} | ||
|
||
/// Creates an image view that overlaps content at the edges of its frame | ||
/// - Parameters: | ||
/// - uiImage: Image that will overlap content. | ||
/// - left: Overlap percent at left edge. | ||
/// - right: Overlap percent at right edge. | ||
public init(uiImage: UIImage, left: CGFloat = 0, right: CGFloat = 0) { | ||
self.init(Image(uiImage: uiImage), aspectRatio: uiImage.size.aspectRatio, left: left, right: right) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// WidgetSize+CurrentDevice.swift | ||
// FrameUp | ||
// | ||
// Created by Ryan Lintott on 2022-01-25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
#if os(iOS) | ||
public extension WidgetSize { | ||
/// The screen size ignoring orientation. | ||
private static let currentScreenSize = UIScreen.main.fixedCoordinateSpace.bounds.size | ||
|
||
/// The current device. | ||
private static let currentDevice = UIDevice.current.userInterfaceIdiom | ||
|
||
/// Find the supported sizes for a specified device | ||
/// - Parameter device: iPhone, iPad, etc | ||
/// - Returns: An array of widget sizes | ||
static func supportedSizes(for device: UIUserInterfaceIdiom) -> [WidgetSize] { | ||
switch device { | ||
case .pad: | ||
if #available(iOS 15.0, *) { | ||
return [.small, .medium, .large, .extraLarge] | ||
} else { | ||
fallthrough | ||
} | ||
case .phone: | ||
return [.small, .medium, .large] | ||
default: | ||
return [] | ||
} | ||
} | ||
|
||
/// Supported widget sizes for the current device. | ||
static var supportedSizesForCurrentDevice: [WidgetSize] { | ||
supportedSizes(for: currentDevice) | ||
} | ||
|
||
/// Size for this widget on the current device. | ||
/// - Parameter iPadTarget: Widget frame target. iPad widgets have a design canvas frame used for laying out the content, and a smaller Home Screen frame that the content is scaled to fit. | ||
/// - Returns: Size for this widget for the current device. Zero if device does not have widgets or if no size is available. | ||
func sizeForCurrentDevice(iPadTarget: WidgetTarget = .homeScreen) -> CGSize { | ||
switch Self.currentDevice { | ||
case .pad: | ||
return sizeForiPad(screenSize: Self.currentScreenSize, target: iPadTarget) | ||
case .phone: | ||
return sizeForiPhone(screenSize: Self.currentScreenSize) | ||
default: | ||
return .zero | ||
} | ||
} | ||
|
||
/// How much the widget is scaled down to fit on the Home Screen. | ||
/// | ||
/// Home Screen width divided by design canvas width | ||
/// - Parameter screenSize: iPad screen size ignoring orientation. | ||
/// - Returns: Widget scale factor between design canvas and Home Screen. | ||
func scaleFactorForiPad(screenSize: CGSize) -> CGFloat { | ||
sizeForiPad(screenSize: Self.currentScreenSize, target: .homeScreen).width / sizeForiPad(screenSize: Self.currentScreenSize, target: .designCanvas).width | ||
} | ||
|
||
/// How much the widget is scaled down to fit on the Home Screen. | ||
/// | ||
/// Home Screen width divided by design canvas width. iPhone value will always be 1. | ||
var scaleFactorForCurrentDevice: CGFloat { | ||
guard Self.currentDevice == .pad else { | ||
return 1 | ||
} | ||
|
||
return scaleFactorForiPad(screenSize: Self.currentScreenSize) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters