Merge pull request #44 from fummicc1/refactoring Refactoring
Merge pull request #44 from fummicc1/refactoring
Refactoring
SimpleRoulette helps you to create customizable Roulette, with SwiftUI. (Compatible with both macOS and iOS.)
Create Package.swift and add dependency like the following.
Package.swift
dependencies: [ .package(url: "https://github.com/fummicc1/SimpleRoulette.git", from: "1.3.0") // or .package(url: "https://github.com/fummicc1/SimpleRoulette.git", branch: "main") ]
Create Podfile and add dependency like the following.
Podfile
pod 'SimpleRoulette', '~> 1.3'
Create Cartfile and add dependency like the following.
Cartfile
github "fummicc1/SimpleRoulette"
All you need to know is just RouletteView and PartData. RouletteView confirms to View, so you can use it like the follwing.
RouletteView
PartData
View
```swift struct ContentView: View { var body: some View { RouletteView( parts: partDatas ) .startOnAppear(automaticallyStopAfter: 5) { part in guard let text = part.content.text else { return } title = text } } var partDatas: [PartData] { [ PartData( content: .label("Swift"), area: .flex(3), fillColor: Color.red ), PartData( content: .label("Kotlin"), area: .flex(1), fillColor: Color.purple ), PartData( content: .label("JavaScript"), area: .flex(2), fillColor: Color.yellow ), PartData( content: .label("Dart"), area: .flex(1), fillColor: Color.green ), PartData( content: .label("Python"), area: .flex(2), fillColor: Color.blue ), PartData( content: .label("C++"), area: .degree(60), fillColor: Color.orange ), ] } }
If you want to pause / restart roulette. Please use RouletteModel like the following.
RouletteModel
struct ContentView: View { @StateObject var model: RouletteModel var body: some View { VStack { RouletteView(model: model) }.onAppear { model.start() DispatchQueue.main.asyncAfter(deadline: .now() + 3) { model.pause() // you can pause DispatchQueue.main.asyncAfter(deadline: .now() + 5) { model.restart() // you can restart } } } } } // Call ContentView ContentView( model: RouletteModel( PartData( content: .label("Swift"), area: .flex(3), fillColor: Color.red ), PartData( content: .label("Kotlin"), area: .flex(1), fillColor: Color.purple ), PartData( content: .label("JavaScript"), area: .flex(2), fillColor: Color.yellow ), PartData( content: .label("Dart"), area: .flex(1), fillColor: Color.green ), PartData( content: .label("Python"), area: .flex(2), fillColor: Color.blue ), PartData( content: .label("C++"), area: .degree(60), fillColor: Color.orange ), ) )
Pull requests, bug reports and feature requests are welcome 🚀
MIT LICENSE
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
SimpleRoulette
SimpleRoulette helps you to create customizable Roulette, with SwiftUI. (Compatible with both macOS and iOS.)
Demo
iOS
macOS
Install
Swift Package Manager
Create
Package.swift
and add dependency like the following.Cocoapods
Create
Podfile
and add dependency like the following.Carthage
Create
Cartfile
and add dependency like the following.Usage
RouletteView
All you need to know is just
RouletteView
andPartData
.RouletteView
confirms toView
, so you can use it like the follwing.RouletteModel
If you want to pause / restart roulette. Please use
RouletteModel
like the following.Documentation
Contributing
Pull requests, bug reports and feature requests are welcome 🚀
License
MIT LICENSE