Skip to content

Commit

Permalink
Fix: Remove symbolic links on xcframework
Browse files Browse the repository at this point in the history
  • Loading branch information
fermoya committed Nov 16, 2021
1 parent 5a945d1 commit 3c0485f
Show file tree
Hide file tree
Showing 23 changed files with 2,636 additions and 261 deletions.
2 changes: 1 addition & 1 deletion Documentation/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Get a interactive fading effect on your items by using `interactive(opacity:)`:

```swift
Pager(...)
.interacive(opacity: 0.4)
.interactive(opacity: 0.4)
.preferredItemSize(CGSize(width: 150, height: 150))
.itemSpacing(10)
```
Expand Down
619 changes: 361 additions & 258 deletions SwiftUIPager.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions SwiftUIPager/Helpers/Buildable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Buildable.swift
// iPod
//
// Created by Fernando Moya de Rivas on 09/12/2019.
// Copyright © 2019 Fernando Moya de Rivas. All rights reserved.
//

import Foundation

/// Adds a helper function to mutate a properties and help implement _Builder_ pattern
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
protocol Buildable { }

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Buildable {

/// Mutates a property of the instance
///
/// - Parameter keyPath: `WritableKeyPath` to the instance property to be modified
/// - Parameter value: value to overwrite the instance property
func mutating<T>(keyPath: WritableKeyPath<Self, T>, value: T) -> Self {
var newSelf = self
newSelf[keyPath: keyPath] = value
return newSelf
}

}
45 changes: 45 additions & 0 deletions SwiftUIPager/Helpers/CGPoint+Angle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// CGPoint+Angle.swift
// SwiftUIPagerExample
//
// Created by Fernando Moya de Rivas on 23/07/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension CGPoint {

var angle: Angle? {
guard x != 0 || y != 0 else { return nil }
guard x != 0 else { return y > 0 ? Angle(degrees: 90) : Angle(degrees: 270) }
guard y != 0 else { return x > 0 ? Angle(degrees: 0) : Angle(degrees: 180) }
var angle = atan(abs(y) / abs(x)) * 180 / .pi
switch (x, y) {
case (let x, let y) where x < 0 && y < 0:
angle = 180 + angle
case (let x, let y) where x < 0 && y > 0:
angle = 180 - angle
case (let x, let y) where x > 0 && y < 0:
angle = 360 - angle
default:
break
}

return .init(degrees: Double(angle))
}

static func -(lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
}

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Angle {
var isAlongXAxis: Bool {
let degrees = ((Int(self.degrees.rounded()) % 360) + 360) % 360
return degrees >= 330 || degrees <= 30 || (degrees >= 150 && degrees <= 210)
}
}
52 changes: 52 additions & 0 deletions SwiftUIPager/Helpers/OnAnimationCompletedModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// OnAnimationCompletedModifier.swift
// SwiftUIPagerExample
//
// Created by Fernando Moya de Rivas on 14/1/21.
// Copyright © 2021 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI

/// `ViewModifier` used to observe the end of an animation
@available(iOS 13.2, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
struct OnAnimationCompletedModifier<Value>: AnimatableModifier where Value: VectorArithmetic {

var animatableData: Value {
didSet {
notifyCompletionIfFinished()
}
}

private var target: Value
private var completion: () -> Void

init(target: Value, completion: @escaping () -> Void) {
self.completion = completion
self.animatableData = target
self.target = target
}

private func notifyCompletionIfFinished() {
guard animatableData == target else { return }
DispatchQueue.main.async {
self.completion()
}
}

func body(content: Content) -> some View {
content
}
}

@available(iOS 13.2, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

/// Calls the completion handler whenever an animation on the given value completes.
///
/// - Parameter value: The value to observe
/// - Parameter completion: The completion callback
func onAnimationCompleted<Value: VectorArithmetic>(for value: Value, completion: @escaping () -> Void) -> some View {
return modifier(OnAnimationCompletedModifier(target: value, completion: completion))
}
}
39 changes: 39 additions & 0 deletions SwiftUIPager/Helpers/OnDeactivateModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// OnDeactivateModifier.swift
// SwiftUIPagerExample
//
// Created by Fernando Moya de Rivas on 07/07/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI

/// This modifier allows the `View` to listen to the `UIScene.didActivateNotification` in `iOS`
/// and perform an action when received.
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
struct OnDeactivateView<Content: View>: View {

var content: Content
var perform: () -> Void

var body: some View {
#if os(iOS)
return content
.onReceive(NotificationCenter.default.publisher(for: UIScene.didActivateNotification), perform: { _ in
self.perform()
})
#else
return content
#endif
}

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

func onDeactivate(perform: @escaping () -> Void) -> some View {
return OnDeactivateView(content: self, perform: perform)
}

}
22 changes: 22 additions & 0 deletions SwiftUIPager/Helpers/View+Helper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// View+Helper.swift
// SwiftUIPager
//
// Created by Fernando Moya de Rivas on 19/01/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

func frame(size: CGSize) -> some View {
frame(width: size.width, height: size.height)
}

func eraseToAny() -> AnyView {
AnyView(self)
}

}
126 changes: 126 additions & 0 deletions SwiftUIPager/Page.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//
// Pager.swift
// SwiftUIPager
//
// Created by Fernando Moya de Rivas on 19/01/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI
import Combine

/// Encapsulates `Pager` state.
///
/// Initialize with one of its convenience methods:
/// - `firstPage()`
/// - `withIndex(_:)`
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public class Page: ObservableObject {

// Needed for `iOS 13` or else it won't trigger an update
public var objectWillChange = PassthroughSubject<Void, Never>()
var _index: Int

/// Current page index.
/// - Note: Modifying its value won't trigger a `SwiftUI` update, use `update(_:)` method instead.
public var index: Int {
get { _index }
set {
guard isInfinite else {
return _index = min(totalPages - 1, max(0, newValue))
}
_index = (newValue + totalPages) % totalPages
}
}

/// Total number of pages
var totalPages: Int = Int.max

#if !os(tvOS)

/// `swipeGesture` translation on the X-Axis
var draggingOffset: CGFloat = 0

/// `swipeGesture` last translation on the X-Axis
var lastDraggingValue: DragGesture.Value?

/// `swipeGesture` velocity on the X-Axis
var draggingVelocity: Double = 0

#endif

/// Increment resulting from the last swipe
var pageIncrement = 0

var isInfinite = false

/// Initializes a new instance
///
/// - Parameter page: Current page index
private init(page: Int) {
self._index = page
}

}

// MARK: Public

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Page {

/// An update to perform on a `Page` index
public enum Update {

/// Will increase the `index` by `1`
case next

/// Will decrease the `index` by `1`
case previous

/// Will move to the first page
case moveToFirst

/// Will move to the last page
case moveToLast

/// Will set the `index` to the new value
case new(index: Int)
}

/// Convenience method to initialize a new `Page`
///
/// - Parameter index: Current page index
public static func withIndex(_ index: Int) -> Page {
Page(page: index)
}

/// Convenience method to initialize a new `Page`
///
/// - Parameter index: Current page index
public static func first() -> Page {
withIndex(0)
}

/// Will update `Page` accordingly and trigger `objectWillChange`
///
/// - Parameter update: update to perform
///
/// If you do not wish to trigger an update because you want to take control of the update, set `index` direclty
public func update(_ update: Update) {
switch update {
case .next:
index += 1
case .previous:
index -= 1
case .moveToFirst:
index = 0
case .moveToLast:
index = totalPages - 1
case .new(let newIndex):
index = newIndex
}

objectWillChange.send()
}

}
28 changes: 28 additions & 0 deletions SwiftUIPager/PageConfiguration/ContentLoadingPolicy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// File.swift
//
//
// Created by Fernando Moya de Rivas on 05/07/2020.
//

import Foundation

/// Policy to follow when loading content
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public enum ContentLoadingPolicy: Equatable {

/// Content is loaded on demand by applying a recycling the ratio.
///
/// - Parameter recyclingRatio: Manages the number of items that should be displayed in the screen.
///
/// A ratio of `5`, for instance, will load enough items in memory to fill five times the size of `Pager`.
/// - Note: `recyclingRatio` must be greather than `0`.
case lazy(recyclingRatio: UInt)

/// Choose `eager` to load all items at once
case eager

/// Default policy, a.k.a, `lazy(recyclingRatio: 5)`
static var `default`: ContentLoadingPolicy = .lazy(recyclingRatio: 5)
}

42 changes: 42 additions & 0 deletions SwiftUIPager/PageConfiguration/GesturePriority.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// GesturePriority.swift
// SwiftUIPagerExample
//
// Created by Fernando Moya de Rivas on 01/07/2020.
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved.
//

import SwiftUI

/// Defines a set of priorities to interact with gestures
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public enum GesturePriority {
/// Refers to `highPriorityGesture` modifier
case high

/// Refers to `simultaneousGesture` modifier
case simultaneous

/// Refers to `gesture` modifier
case normal

/// Default value, a.k.a, `normal`
static let `default`: GesturePriority = .normal
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

func gesture<T>(_ gesture: T, priority: GesturePriority) -> some View where T : Gesture {
Group {
if priority == .high {
highPriorityGesture(gesture)
} else if priority == .simultaneous {
simultaneousGesture(gesture)
} else {
self.gesture(gesture)
}
}
}

}
Loading

0 comments on commit 3c0485f

Please sign in to comment.