Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ struct ContentView: View {
CubeTransition()
}
HStack(spacing: 20) {
BallZigZag()
BallZigZagDeflect()
BallTrianglePath()
BallZigZag(color: .blue, type: .filled)
BallZigZagDeflect(color: .blue, type: .filled)
BallTrianglePath(color: .blue, type: .filled)
BallScale()
}
HStack(spacing: 20) {
LineScale()
LineScaleParty()
BallPulseSync()
BallPulseSync(color: .blue, type: .filled)
BallBeat()
}
HStack(spacing: 20) {
Expand Down
12 changes: 9 additions & 3 deletions Sources/BallPulseSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ public struct BallPulseSync: View {
private let timingFunction = TimingFunction.easeInOut
private let keyTimes = [0, 0.33, 0.66, 1]
private let directionValues: [CGFloat] = [0, 1, -1, 0]

private let color: Color
private let type: BallType

public var body: some View {
GeometryReader(content: render)
}

public init() { }
public init(color: Color = .black, type: BallType = .outlined) {
self.color = color
self.type = type
}

func render(geometry: GeometryProxy) -> some View {
let dimension = min(geometry.size.width, geometry.size.height)
Expand All @@ -38,7 +43,8 @@ public struct BallPulseSync: View {
timingFunctions: timingFunctions,
keyTimes: keyTimes,
referenceTime: referenceTime) {
Circle()
type.view
.foregroundColor(color)
.frame(width: objectDimension, height: objectDimension)
.offset(x: 0, y: values[$0])
}
Expand Down
26 changes: 23 additions & 3 deletions Sources/BallTrianglePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@

import SwiftUI

fileprivate struct SmallRing: Shape {
public enum BallType {
case filled, outlined

@ViewBuilder
var view: some View {
switch self {
case .filled:
Circle()
case .outlined:
SmallRing()
}
}
}

internal struct SmallRing: Shape {

func path(in rect: CGRect) -> Path {
let dimension = min(rect.size.width, rect.size.height)
Expand All @@ -26,12 +40,17 @@ public struct BallTrianglePath: View {
private let directionValues: [[UnitPoint]] = [[.zero, .init(x: 0.5, y: 1), .init(x: -0.5, y: 1), .zero],
[.zero, .init(x: -1, y: 0), .init(x: -0.5, y: -1), .zero],
[.zero, .init(x: 0.5, y: -1), .init(x: 1, y: 0), .zero]]
private let color: Color
private let type: BallType

public var body: some View {
GeometryReader(content: render)
}

public init() { }
public init(color: Color = .black, type: BallType = .outlined) {
self.color = color
self.type = type
}

func render(geometry: GeometryProxy) -> some View {
let dimension = min(geometry.size.width, geometry.size.height)
Expand All @@ -54,7 +73,8 @@ public struct BallTrianglePath: View {
duration: duration,
timingFunctions: timingFunctions,
keyTimes: keyTimes) {
SmallRing()
type.view
.foregroundColor(color)
.frame(width: objectDimension, height: objectDimension)
.position(x: positions[index].x, y: positions[index].y)
.offset(x: values[index][$0].x, y: values[index][$0].y)
Expand Down
12 changes: 9 additions & 3 deletions Sources/BallZigZag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ public struct BallZigZag: View {
private let keyTimes = [0, 0.33, 0.66, 1]
private let directionValues: [[UnitPoint]] = [[.zero, .init(x: -1, y: -1), .init(x: 1, y: -1), .zero],
[.zero, .init(x: 1, y: 1), .init(x: -1, y: 1), .zero]]

private let color: Color
private let type: BallType

public var body: some View {
GeometryReader(content: render)
}

public init() { }
public init(color: Color = .black, type: BallType = .outlined) {
self.color = color
self.type = type
}

func render(geometry: GeometryProxy) -> some View {
let dimension = min(geometry.size.width, geometry.size.height)
Expand All @@ -37,7 +42,8 @@ public struct BallZigZag: View {
duration: duration,
timingFunctions: timingFunctions,
keyTimes: keyTimes) {
Circle()
type.view
.foregroundColor(color)
.frame(width: objectDimension, height: objectDimension)
.offset(x: values[index][$0].x, y: values[index][$0].y)
}
Expand Down
12 changes: 9 additions & 3 deletions Sources/BallZigZagDeflect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ public struct BallZigZagDeflect: View {
private let keyTimes = [0, 0.16, 0.33, 0.5, 0.66, 0.83, 1]
private let directionValues: [[UnitPoint]] = [[.zero, .init(x: -1, y: -1), .init(x: 1, y: -1), .zero, .init(x: 1, y: -1), .init(x: -1, y: -1), .zero],
[.zero, .init(x: 1, y: 1), .init(x: -1, y: 1), .zero, .init(x: -1, y: 1), .init(x: 1, y: 1), .zero]]

private let color: Color
private let type: BallType

public var body: some View {
GeometryReader(content: render)
}

public init() { }
public init(color: Color = .black, type: BallType = .outlined) {
self.color = color
self.type = type
}

func render(geometry: GeometryProxy) -> some View {
let dimension = min(geometry.size.width, geometry.size.height)
Expand All @@ -37,7 +42,8 @@ public struct BallZigZagDeflect: View {
duration: duration,
timingFunctions: timingFunctions,
keyTimes: keyTimes) {
Circle()
type.view
.foregroundColor(color)
.frame(width: objectDimension, height: objectDimension)
.offset(x: values[index][$0].x, y: values[index][$0].y)
}
Expand Down