Swiftpack.co - fummicc1/SimpleRoulette as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by fummicc1.
fummicc1/SimpleRoulette v1.2.1
SwiftUI library to create Roulette with ease.
⭐️ 20
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/fummicc1/SimpleRoulette.git", from: "v1.2.1")

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

GitHub

link
Stars: 20
Last commit: 28 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.2
28 weeks ago

What's Changed

Full Changelog: https://github.com/fummicc1/SimpleRoulette/compare/1.3.1...1.3.2

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics