Skip to content

Commit

Permalink
Add dependencies in init
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersyd committed Apr 7, 2021
1 parent d1af86a commit 8e87025
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
7 changes: 2 additions & 5 deletions Example/FortuneWheel/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}

18 changes: 11 additions & 7 deletions Source/FortuneWheel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@ import SwiftUI
@available(iOS 14.0, *)
public struct FortuneWheel: View {

var titles: [String], colors: [Color], strokeWidth: CGFloat, strokeColor: Color
var titles: [String], size: CGFloat, strokeWidth: CGFloat, strokeColor: Color = Color(hex: "252D4F")
var colors: [Color] = Color.spin_wheel_color
@StateObject var viewModel: FortuneWheelViewModel

init(titles: [String], colors: [Color] = Color.spin_wheel_color, strokeWidth: CGFloat = 15, strokeColor: Color = Color(hex: "252D4F"),
public init(titles: [String], size: CGFloat, colors: [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.colors = colors
self.size = size
if let colors = colors { self.colors = colors }
self.strokeWidth = strokeWidth
self.strokeColor = strokeColor
if let strokeColor = strokeColor { self.strokeColor = strokeColor }
_viewModel = StateObject(wrappedValue: FortuneWheelViewModel(titles: titles, animDuration: animDuration,
timeCurveAnimation: timeCurveAnimation ?? Animation.timingCurve(0.51, 0.97, 0.56, 0.99, duration: animDuration)))
timeCurveAnimation: timeCurveAnimation ?? animation))
}

public var body: some View {
ZStack(alignment: .top) {
ZStack(alignment: .center) {
SpinWheelView(data: (0..<titles.count).map { _ in Double(100/titles.count) },
labels: titles, colors: colors)
.frame(width: 320, height: 320)
.frame(width: size, height: size)
.overlay(
RoundedRectangle(cornerRadius: 160).stroke(lineWidth: strokeWidth)
RoundedRectangle(cornerRadius: size/2).stroke(lineWidth: strokeWidth)
.foregroundColor(strokeColor)
)
.rotationEffect(.degrees(viewModel.degree))
Expand Down

0 comments on commit 8e87025

Please sign in to comment.