Swiftpack.co - Package - jiachenyee/NetworkActivityIndicator

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

  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

Github

link
Stars: 3

Dependencies

Used By

Total: 0

Releases

1.0.0 -

yay release