Skip to content

Commit

Permalink
Remove assets | Add SpinWheel pointer and bolt view
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersyd committed Apr 7, 2021
1 parent dae451a commit 55675e2
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 67 deletions.
6 changes: 0 additions & 6 deletions Assets.xcassets/Contents.json

This file was deleted.

23 changes: 0 additions & 23 deletions Assets.xcassets/fortune_wheel_bolt.imageset/Contents.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 0 additions & 23 deletions Assets.xcassets/fortune_wheel_pointer.imageset/Contents.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions Source/FortuneWheel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import SwiftUI
public struct FortuneWheel: View {

var titles: [String], size: CGFloat, onSpinEnd: ((Int) -> ())?, strokeWidth: CGFloat, strokeColor: Color = Color(hex: "252D4F")
var colors: [Color] = Color.spin_wheel_color
var colors: [Color] = Color.spin_wheel_color, pointerColor: Color = Color(hex: "DA4533")
@StateObject var viewModel: FortuneWheelViewModel

public init(titles: [String], size: CGFloat, onSpinEnd: ((Int) -> ())?,
colors: [Color]? = nil, strokeWidth: CGFloat = 15, strokeColor: Color? = nil,
colors: [Color]? = nil, pointerColor: Color? = nil, strokeWidth: CGFloat = 15, strokeColor: Color? = nil,
animDuration: Double = Double(6), timeCurveAnimation: Animation? = nil) {

let animation = Animation.timingCurve(0.51, 0.97, 0.56, 0.99, duration: animDuration)
self.titles = titles
self.size = size
if let colors = colors { self.colors = colors }
if let pointerColor = pointerColor { self.pointerColor = pointerColor }
self.strokeWidth = strokeWidth
if let strokeColor = strokeColor { self.strokeColor = strokeColor }
_viewModel = StateObject(wrappedValue: FortuneWheelViewModel(titles: titles, animDuration: animDuration,
Expand Down Expand Up @@ -49,19 +50,14 @@ public struct FortuneWheel: View {
viewModel.spinWheel()
})
)
Image.fortune_wheel_bolt.resizable().frame(width: 28, height: 28)
SpinWheelBolt()
}
Image.fortune_wheel_pointer.resizable().frame(width: 65, height: 65).offset(x: 0, y: -25)
SpinWheelPointer(pointerColor: pointerColor).offset(x: 0, y: -25)
}
}
}

fileprivate extension Image {
static let fortune_wheel_bolt = Image("fortune_wheel_bolt")
static let fortune_wheel_pointer = Image("fortune_wheel_pointer")
}

fileprivate extension Color {
extension Color {

static let spin_wheel_color: [Color] = [Color(hex: "FBE488"), Color(hex: "75AB53"), Color(hex: "D1DC59"),
Color(hex: "EC9D42"), Color(hex: "DE6037"), Color(hex: "DA4533"),
Expand Down
36 changes: 35 additions & 1 deletion Source/SpinWheel/SpinWheelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@

import SwiftUI

struct Triangle: Shape {
public func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: rect.midX, y: rect.minY))
path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.midX, y: rect.minY))
path.addCurve(to: CGPoint(x: rect.midX, y: rect.minY), control1: CGPoint(x: rect.maxX, y: rect.minY), control2: CGPoint(x: rect.midX, y: rect.minY))
return path
}
}

struct SpinWheelPointer: View {
var pointerColor: Color
var body: some View {
Triangle().frame(width: 50, height: 50)
.foregroundColor(pointerColor).cornerRadius(24)
.rotationEffect(.init(degrees: 180))
.shadow(color: Color(hex: "212121", alpha: 0.5), radius: 5, x: 0.0, y: 1.0)
}
}

struct SpinWheelBolt: View {
var body: some View {
ZStack {
Circle().frame(width: 28, height: 28)
.foregroundColor(Color(hex: "F4C25B"))
Circle().frame(width: 18, height: 18)
.foregroundColor(Color(hex: "FFD25A"))
.shadow(color: Color(hex: "404040", alpha: 0.35), radius: 3, x: 0.0, y: 1.0)
}
}
}

struct SpinWheelView: View {

var data: [Double], labels: [String]
Expand All @@ -25,7 +59,7 @@ struct SpinWheelView: View {
ZStack(alignment: .center) {
ForEach(0..<data.count) { index in
SpinWheelCell(startAngle: startAngle(for: index), endAngle: endAngle(for: index))
.fill(colors[index])
.fill(colors[index % colors.count])
Text(labels[index]).foregroundColor(Color.white)
.offset(viewOffset(for: index, in: geo.size)).zIndex(1)
}
Expand Down

0 comments on commit 55675e2

Please sign in to comment.