Skip to content

A simple package that shows the network activity indicator on the device, regardless of whether it has a notch or not

License

Notifications You must be signed in to change notification settings

jiachenyee/NetworkActivityIndicator

Repository files navigation

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

About

A simple package that shows the network activity indicator on the device, regardless of whether it has a notch or not

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages