Skip to content

Commit

Permalink
Use polyfill API for Layout (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Apr 12, 2023
1 parent 7a56103 commit c9b410b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "placement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sampettersson/Placement",
"state" : {
"revision" : "2dc510fb7d36dd49dc3857c95d69653cc3836a40",
"version" : "1.4.1"
}
}
],
"version" : 2
}
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import PackageDescription
let package = Package(
name: "WrapLayout",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.watchOS(.v6),
.tvOS(.v13),
.iOS(.v14)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand All @@ -21,13 +18,16 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/sampettersson/Placement", from: "1.4.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "WrapLayout",
dependencies: []
dependencies: [
"Placement"
]
),
.testTarget(
name: "WrapLayoutTests",
Expand Down
11 changes: 6 additions & 5 deletions Sources/WrapLayout/WrapLayout.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import SwiftUI
import Placement

@available(iOS 16, *)
public struct WrapLayout: Layout {
public struct WrapLayout: PlacementLayout {

public struct CacheStorage {

struct CalculatedElement {
let element: LayoutSubviews.Element
let element: Subviews.Element
let size: CGSize
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public struct WrapLayout: Layout {
}

public func sizeThatFits(
proposal: ProposedViewSize,
proposal: PlacementProposedViewSize,
subviews: Subviews,
cache: inout CacheStorage
) -> CGSize {
Expand Down Expand Up @@ -110,7 +110,7 @@ public struct WrapLayout: Layout {

public func placeSubviews(
in bounds: CGRect,
proposal: ProposedViewSize,
proposal: PlacementProposedViewSize,
subviews: Subviews,
cache: inout CacheStorage
) {
Expand All @@ -127,6 +127,7 @@ public struct WrapLayout: Layout {
x: bounds.minX + cursorX,
y: bounds.minY + cursorY
),
anchor: .topLeading,
proposal: .init(width: element.size.width, height: element.size.height)
)

Expand Down
4 changes: 2 additions & 2 deletions _WrapLayoutDemo/WrapLayoutDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.3;
Expand Down Expand Up @@ -328,7 +328,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 12.3;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "placement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sampettersson/Placement",
"state" : {
"revision" : "2dc510fb7d36dd49dc3857c95d69653cc3836a40",
"version" : "1.4.1"
}
}
],
"version" : 2
}
4 changes: 1 addition & 3 deletions _WrapLayoutDemo/WrapLayoutDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ struct ContentView: View {
}

#if DEBUG
@available(iOS 16, *)
struct BookWrapLayout_Previews: PreviewProvider {
static var previews: some View {
BookWrapLayout()
Expand Down Expand Up @@ -45,7 +44,6 @@ func makeRandom() -> BookWrapLayout.Element {
}

/// very beginning
@available(iOS 16, *)
struct BookWrapLayout: View {

struct Element: Equatable, Identifiable {
Expand Down Expand Up @@ -90,7 +88,7 @@ struct BookWrapLayout: View {
.animation(.interactiveSpring(), value: elements)

}
.background(.black.opacity(0.1))
.background(Color.black.opacity(0.1))

}

Expand Down

0 comments on commit c9b410b

Please sign in to comment.