/SimpleRoulette

SwiftUI library to create Roulette with ease.

Primary LanguageSwiftMIT LicenseMIT

Images

Pod Platform Pod License Pod Version Carthage Compatible Swift Package Manager compatible

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.

dependencies: [
    .package(url: "https://github.com/fummicc1/SimpleRoulette.git", from: "1.2.0")
    // or
    .package(url: "https://github.com/fummicc1/SimpleRoulette.git", branch: "main")
]

Cocoapods

Create Podfile and add dependency like the following.

pod 'SimpleRoulette', '~> 1.2'

Carthage

Create Cartfile and add dependency like the following.

github "fummicc1/SimpleRoulette"

Usage

RouletteView

RouletteView confirms to View, so you can use it like the follwing.

struct ContentView: View {

    @ObservedObject var model: RouletteModel

    var body: some View {
        VStack {
            RouletteView(
                model: model
            )
        }.onAppear { model.start(speed: .random()) }
    }
}

// Call ContentView
ContentView(
    model: RouletteModel(
        PartData(
            index: 0,
            content: .label("Swift"),
            area: .flex(3),
            fillColor: Color.red
        ),
        PartData(
            index: 1,
            content: .label("Kotlin"),
            area: .flex(1),
            fillColor: Color.purple
        ),
        PartData(
            index: 2,
            content: .label("JavaScript"),
            area: .flex(2),
            fillColor: Color.yellow
        ),
        PartData(
            index: 3,
            content: .label("Dart"),
            area: .flex(1),
            fillColor: Color.green
        ),
        PartData(
            index: 4,
            content: .label("Python"),
            area: .flex(2),
            fillColor: Color.blue
        ),
        PartData(
            index: 5,
            content: .label("C++"),
            area: .degree(60),
            fillColor: Color.orange
        ),
    )
)

RouletteModel

RouletteModel is ObservableObject. You can observe the event that roulette has been stopped and what is the stop via onDecide Publisher.

Usage

RouletteModel.start function immediately start roulette. If you would stop roulette automatically, please specify the duration in seconds of rotation at automaticallyStopAfter: Double? parameter. Default value of automaticallyStopAfter is nil which means that roulette continues rotating unless you call RouletteModel.stop method.

Documentation

Contributing

Pull requests, bug reports and feature requests are welcome 🚀

License

MIT LICENSE