41 lines
1.3 KiB
Swift
41 lines
1.3 KiB
Swift
//
|
|
// FortuneWheel.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 2023/12/07.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct FortuneWheel: View {
|
|
|
|
private let model: FortuneWheelModel
|
|
@StateObject private var viewModel: FortuneWheelViewModel
|
|
|
|
public init(model: FortuneWheelModel) {
|
|
self.model = model
|
|
_viewModel = StateObject(wrappedValue: FortuneWheelViewModel(model: model))
|
|
}
|
|
|
|
public var body: some View {
|
|
ZStack(alignment: .top) {
|
|
ZStack(alignment: .center) {
|
|
SpinWheelView(data: (0..<model.titles.count).map { _ in Double(100 / model.titles.count) },
|
|
labels: model.titles, colors: model.colors)
|
|
.frame(width: model.size, height: model.size)
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: model.size / 2)
|
|
.stroke(lineWidth: model.strokeWidth)
|
|
.foregroundColor(model.strokeColor)
|
|
)
|
|
.rotationEffect(.degrees(viewModel.degree))
|
|
.onAppear {
|
|
viewModel.spinWheel()
|
|
}
|
|
SpinWheelBolt()
|
|
}
|
|
SpinWheelPointer(pointerColor: model.pointerColor).offset(x: 0, y: -25)
|
|
}
|
|
}
|
|
}
|