Giter Club home page Giter Club logo

activityindicators's Introduction

ActivityIndicators

Use this small library to add a simple activity indicator to your SwiftUI apps!

Installation

The preferred way of installing this library is through the Swift Package Manager.

  1. In Xcode, open your project and navigate to File โ†’ Swift Packages โ†’ Add Package Dependency...
  2. Paste the repository URL (https://github.com/sketch204/ActivityIndicators) and click Next.
  3. For Rules, select Branch (with branch set to master).
  4. Click Finish.

Usage

All indicators are encapsulated in the Indicator type. There are a number of indicator styles available, as shown in the gif above. You can add the Default style indicator to your layout with the following code snippet.

import SwiftUI

struct YourView: View {
    @State private var isLoading: Bool = true

    var body: some View {
        VStack {
            Indicator.Default(isAnimating: isLoading)
            
            Button("Toggle Loading") {
                self.isLoading.toggle()
            }
        }
    }
}

The types of indicator that are available are:

  • Default
  • Continuous
  • BallString
  • Pulse
  • Radar

Each indicator also takes in an optional color parameter of type Color at the end its initializer. This is used to specify the color of the indicator. The default value of this parameter is the primary label color. The only exception to this is the Pulse type which cannot use transparent colors and instead uses the non-opaque label color of your platform.

Another example

// Create a red 'Pulse' indicator
Indicator.Pulse(isAnimating: isAnimating, color: .red)

Resizing

By default most indicators take a size of 40x40 pixels. This can be customized by using the resizable modifier on the indicator directly. This modifier behaves similar to how SwiftUI.Image's resizable modifier behaves, specifically, making the indicator take up all of the space that the parent offers it. This allows you to follow the resizable modifier with a frame modifier to set a custom size for the indicator.

Here's a simple example:

// Create an indicator of size 100x100 pixels.
Indicator.Default(isAnimating: isAnimating)
    .resizable()
    .frame(width: 100, height: 100)

Note: At the moment, non-square sizes may be glitchy under specific circumstances. This should be fixed soon, but for now try to provide equal widths and heights to square the indicators, for best results.

activityindicators's People

Contributors

sketch204 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.