Code Monkey home page Code Monkey logo

networkactivityindicator's Introduction

Network Activity Indicator

This is a simple package that shows network activity indicator, regardless of whether the device has a notch or not

Why?

It is a simple way to create an unobstructive, discrete activity indicator when networking. Also, the old one, by Apple, did not work with the notch and got deprecated ๐Ÿ˜”.


Installation

Swift Package Manager

let package = Package(
    name: "MyApp",
    dependencies: [
        .Package(url: "https://github.com/jiachenyee/NetworkActivityIndicator.git", majorVersion: 1)
    ]
)

Implementation

Set-Up

import NetworkActivityIndicator

// REQURIRED: Add the NetworkActivityIndicatorDelegate protocol
class ViewController: UIViewController, NetworkActivityIndicatorDelegate { 

    // REQUIRED: This variable will be used to update the status bar hidden state
    // You should not edit these four lines 
    var statusBarHidden = false {
        didSet {
            setNeedsStatusBarAppearanceUpdate()
        }
    }
    
    // REQUIRED: Create your network activity indicator
    let networkActivityIndicator = NetworkActivityIndicator()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        // REQUIRED: Assign the delegate
        // Without connecting it to the delegate
        networkActivityIndicator.delegate = self
    }

    // REQUIRED: Set the status bar hidden to connect it to the delegate value
    override var prefersStatusBarHidden: Bool {
        statusBarHidden
    }

    // OPTIONAL: Handle whenever the state of the network activity indicator changes.
    // You can really do whatever you want here
    func networkActivityIndicator(stateChanged isAnimating: Bool) {
        // your code
    }
}

Start/Stop Animating

Start

Start animating the activity indicator

networkActivityIndicator.start()

Stop

Stop animating the activity indicator

networkActivityIndicator.stop()

Toggle

Toggle the network activity indicator. If it is animating, stop, otherwise, start.

networkActivityIndicator.toggle()

isAnimating

Directly update the isAnimating variable to make it start and stop

networkActivityIndicator.isAnimating = true   // start
networkActivityIndicator.isAnimating = false  // stop
networkActivityIndicator.isAnimating.toggle() // toggle

Questions / Issues

Why is the status bar and network activity indicator overlapping?
  1. Make sure that this is implemented
var statusBarHidden = false {
    didSet {
        setNeedsStatusBarAppearanceUpdate()
    }
}
  1. Make sure that you added the prefersStatusBarHidden in the view controller
override var prefersStatusBarHidden: Bool {
    statusBarHidden
}

Apache License 2.0

Permissions Limitations Conditions
โœ… Commercial use โŒ Trademark use โ„น๏ธ License and copyright notice
โœ… Modification โŒ Liability โ„น๏ธ State changes
โœ… Distribution โŒ Warranty
โœ… Patent use
โœ… Private use

Read the license

networkactivityindicator's People

Contributors

jiachenyee avatar

Stargazers

 avatar  avatar

Watchers

 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.