SimpleRoulette

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.3.0")
    // or
    .package(url: "https://github.com/fummicc1/SimpleRoulette.git", branch: "main")
]

Cocoapods

Create Podfile and add dependency like the following.

pod 'SimpleRoulette', '~> 1.3'

Carthage

Create Cartfile and add dependency like the following.

github "fummicc1/SimpleRoulette"

Usage

RouletteView

All you need to know is just RouletteView and PartData. RouletteView confirms to View, so you can use it like the follwing.

```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
            ),
        ]
    }
}

RouletteModel

If you want to pause / restart roulette. Please use RouletteModel like the following.

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
        ),
    )
)

Documentation

Contributing

Pull requests, bug reports and feature requests are welcome 🚀

License

MIT LICENSE