Skip to content

Commit 3c0485f

Browse files
committed
Fix: Remove symbolic links on xcframework
1 parent 5a945d1 commit 3c0485f

23 files changed

+2636
-261
lines changed

Documentation/Usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Get a interactive fading effect on your items by using `interactive(opacity:)`:
197197

198198
```swift
199199
Pager(...)
200-
.interacive(opacity: 0.4)
200+
.interactive(opacity: 0.4)
201201
.preferredItemSize(CGSize(width: 150, height: 150))
202202
.itemSpacing(10)
203203
```

SwiftUIPager.xcodeproj/project.pbxproj

Lines changed: 361 additions & 258 deletions
Large diffs are not rendered by default.

SwiftUIPager/Helpers/Buildable.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Buildable.swift
3+
// iPod
4+
//
5+
// Created by Fernando Moya de Rivas on 09/12/2019.
6+
// Copyright © 2019 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Adds a helper function to mutate a properties and help implement _Builder_ pattern
12+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
13+
protocol Buildable { }
14+
15+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
16+
extension Buildable {
17+
18+
/// Mutates a property of the instance
19+
///
20+
/// - Parameter keyPath: `WritableKeyPath` to the instance property to be modified
21+
/// - Parameter value: value to overwrite the instance property
22+
func mutating<T>(keyPath: WritableKeyPath<Self, T>, value: T) -> Self {
23+
var newSelf = self
24+
newSelf[keyPath: keyPath] = value
25+
return newSelf
26+
}
27+
28+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// CGPoint+Angle.swift
3+
// SwiftUIPagerExample
4+
//
5+
// Created by Fernando Moya de Rivas on 23/07/2020.
6+
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
12+
extension CGPoint {
13+
14+
var angle: Angle? {
15+
guard x != 0 || y != 0 else { return nil }
16+
guard x != 0 else { return y > 0 ? Angle(degrees: 90) : Angle(degrees: 270) }
17+
guard y != 0 else { return x > 0 ? Angle(degrees: 0) : Angle(degrees: 180) }
18+
var angle = atan(abs(y) / abs(x)) * 180 / .pi
19+
switch (x, y) {
20+
case (let x, let y) where x < 0 && y < 0:
21+
angle = 180 + angle
22+
case (let x, let y) where x < 0 && y > 0:
23+
angle = 180 - angle
24+
case (let x, let y) where x > 0 && y < 0:
25+
angle = 360 - angle
26+
default:
27+
break
28+
}
29+
30+
return .init(degrees: Double(angle))
31+
}
32+
33+
static func -(lhs: CGPoint, rhs: CGPoint) -> CGPoint {
34+
return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
35+
}
36+
37+
}
38+
39+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
40+
extension Angle {
41+
var isAlongXAxis: Bool {
42+
let degrees = ((Int(self.degrees.rounded()) % 360) + 360) % 360
43+
return degrees >= 330 || degrees <= 30 || (degrees >= 150 && degrees <= 210)
44+
}
45+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// OnAnimationCompletedModifier.swift
3+
// SwiftUIPagerExample
4+
//
5+
// Created by Fernando Moya de Rivas on 14/1/21.
6+
// Copyright © 2021 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
/// `ViewModifier` used to observe the end of an animation
12+
@available(iOS 13.2, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
13+
struct OnAnimationCompletedModifier<Value>: AnimatableModifier where Value: VectorArithmetic {
14+
15+
var animatableData: Value {
16+
didSet {
17+
notifyCompletionIfFinished()
18+
}
19+
}
20+
21+
private var target: Value
22+
private var completion: () -> Void
23+
24+
init(target: Value, completion: @escaping () -> Void) {
25+
self.completion = completion
26+
self.animatableData = target
27+
self.target = target
28+
}
29+
30+
private func notifyCompletionIfFinished() {
31+
guard animatableData == target else { return }
32+
DispatchQueue.main.async {
33+
self.completion()
34+
}
35+
}
36+
37+
func body(content: Content) -> some View {
38+
content
39+
}
40+
}
41+
42+
@available(iOS 13.2, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
43+
extension View {
44+
45+
/// Calls the completion handler whenever an animation on the given value completes.
46+
///
47+
/// - Parameter value: The value to observe
48+
/// - Parameter completion: The completion callback
49+
func onAnimationCompleted<Value: VectorArithmetic>(for value: Value, completion: @escaping () -> Void) -> some View {
50+
return modifier(OnAnimationCompletedModifier(target: value, completion: completion))
51+
}
52+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// OnDeactivateModifier.swift
3+
// SwiftUIPagerExample
4+
//
5+
// Created by Fernando Moya de Rivas on 07/07/2020.
6+
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
/// This modifier allows the `View` to listen to the `UIScene.didActivateNotification` in `iOS`
12+
/// and perform an action when received.
13+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
14+
struct OnDeactivateView<Content: View>: View {
15+
16+
var content: Content
17+
var perform: () -> Void
18+
19+
var body: some View {
20+
#if os(iOS)
21+
return content
22+
.onReceive(NotificationCenter.default.publisher(for: UIScene.didActivateNotification), perform: { _ in
23+
self.perform()
24+
})
25+
#else
26+
return content
27+
#endif
28+
}
29+
30+
}
31+
32+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
33+
extension View {
34+
35+
func onDeactivate(perform: @escaping () -> Void) -> some View {
36+
return OnDeactivateView(content: self, perform: perform)
37+
}
38+
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// View+Helper.swift
3+
// SwiftUIPager
4+
//
5+
// Created by Fernando Moya de Rivas on 19/01/2020.
6+
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
12+
extension View {
13+
14+
func frame(size: CGSize) -> some View {
15+
frame(width: size.width, height: size.height)
16+
}
17+
18+
func eraseToAny() -> AnyView {
19+
AnyView(self)
20+
}
21+
22+
}

SwiftUIPager/Page.swift

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
//
2+
// Pager.swift
3+
// SwiftUIPager
4+
//
5+
// Created by Fernando Moya de Rivas on 19/01/2020.
6+
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
import Combine
11+
12+
/// Encapsulates `Pager` state.
13+
///
14+
/// Initialize with one of its convenience methods:
15+
/// - `firstPage()`
16+
/// - `withIndex(_:)`
17+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
18+
public class Page: ObservableObject {
19+
20+
// Needed for `iOS 13` or else it won't trigger an update
21+
public var objectWillChange = PassthroughSubject<Void, Never>()
22+
var _index: Int
23+
24+
/// Current page index.
25+
/// - Note: Modifying its value won't trigger a `SwiftUI` update, use `update(_:)` method instead.
26+
public var index: Int {
27+
get { _index }
28+
set {
29+
guard isInfinite else {
30+
return _index = min(totalPages - 1, max(0, newValue))
31+
}
32+
_index = (newValue + totalPages) % totalPages
33+
}
34+
}
35+
36+
/// Total number of pages
37+
var totalPages: Int = Int.max
38+
39+
#if !os(tvOS)
40+
41+
/// `swipeGesture` translation on the X-Axis
42+
var draggingOffset: CGFloat = 0
43+
44+
/// `swipeGesture` last translation on the X-Axis
45+
var lastDraggingValue: DragGesture.Value?
46+
47+
/// `swipeGesture` velocity on the X-Axis
48+
var draggingVelocity: Double = 0
49+
50+
#endif
51+
52+
/// Increment resulting from the last swipe
53+
var pageIncrement = 0
54+
55+
var isInfinite = false
56+
57+
/// Initializes a new instance
58+
///
59+
/// - Parameter page: Current page index
60+
private init(page: Int) {
61+
self._index = page
62+
}
63+
64+
}
65+
66+
// MARK: Public
67+
68+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
69+
extension Page {
70+
71+
/// An update to perform on a `Page` index
72+
public enum Update {
73+
74+
/// Will increase the `index` by `1`
75+
case next
76+
77+
/// Will decrease the `index` by `1`
78+
case previous
79+
80+
/// Will move to the first page
81+
case moveToFirst
82+
83+
/// Will move to the last page
84+
case moveToLast
85+
86+
/// Will set the `index` to the new value
87+
case new(index: Int)
88+
}
89+
90+
/// Convenience method to initialize a new `Page`
91+
///
92+
/// - Parameter index: Current page index
93+
public static func withIndex(_ index: Int) -> Page {
94+
Page(page: index)
95+
}
96+
97+
/// Convenience method to initialize a new `Page`
98+
///
99+
/// - Parameter index: Current page index
100+
public static func first() -> Page {
101+
withIndex(0)
102+
}
103+
104+
/// Will update `Page` accordingly and trigger `objectWillChange`
105+
///
106+
/// - Parameter update: update to perform
107+
///
108+
/// If you do not wish to trigger an update because you want to take control of the update, set `index` direclty
109+
public func update(_ update: Update) {
110+
switch update {
111+
case .next:
112+
index += 1
113+
case .previous:
114+
index -= 1
115+
case .moveToFirst:
116+
index = 0
117+
case .moveToLast:
118+
index = totalPages - 1
119+
case .new(let newIndex):
120+
index = newIndex
121+
}
122+
123+
objectWillChange.send()
124+
}
125+
126+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Fernando Moya de Rivas on 05/07/2020.
6+
//
7+
8+
import Foundation
9+
10+
/// Policy to follow when loading content
11+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
12+
public enum ContentLoadingPolicy: Equatable {
13+
14+
/// Content is loaded on demand by applying a recycling the ratio.
15+
///
16+
/// - Parameter recyclingRatio: Manages the number of items that should be displayed in the screen.
17+
///
18+
/// A ratio of `5`, for instance, will load enough items in memory to fill five times the size of `Pager`.
19+
/// - Note: `recyclingRatio` must be greather than `0`.
20+
case lazy(recyclingRatio: UInt)
21+
22+
/// Choose `eager` to load all items at once
23+
case eager
24+
25+
/// Default policy, a.k.a, `lazy(recyclingRatio: 5)`
26+
static var `default`: ContentLoadingPolicy = .lazy(recyclingRatio: 5)
27+
}
28+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// GesturePriority.swift
3+
// SwiftUIPagerExample
4+
//
5+
// Created by Fernando Moya de Rivas on 01/07/2020.
6+
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
/// Defines a set of priorities to interact with gestures
12+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
13+
public enum GesturePriority {
14+
/// Refers to `highPriorityGesture` modifier
15+
case high
16+
17+
/// Refers to `simultaneousGesture` modifier
18+
case simultaneous
19+
20+
/// Refers to `gesture` modifier
21+
case normal
22+
23+
/// Default value, a.k.a, `normal`
24+
static let `default`: GesturePriority = .normal
25+
}
26+
27+
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
28+
extension View {
29+
30+
func gesture<T>(_ gesture: T, priority: GesturePriority) -> some View where T : Gesture {
31+
Group {
32+
if priority == .high {
33+
highPriorityGesture(gesture)
34+
} else if priority == .simultaneous {
35+
simultaneousGesture(gesture)
36+
} else {
37+
self.gesture(gesture)
38+
}
39+
}
40+
}
41+
42+
}

0 commit comments

Comments
 (0)