Giter Site home page Giter Site logo

awesomeplayer165 / pillboxview Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 2.0 516 KB

A Pillbox Capsule-like informational view for iOS written in UIKit

License: MIT License

Swift 100.00%
uikit pillbox pillboxview capsule ios swift collaborate github github-codespaces gitpod

pillboxview's Introduction

PillboxView

PillboxView is a small pill that presents a view on an asynchronous on-going task, the state of an asynchronous task, or instant task. It shows a small bubble, pill looking box that sides from the top of the screen. You most likely have seen this throughout iOS when the ringer state is changed, Airpods are connected and when you copy your Discord ID, among others.

Note: Discord does not use this dependency, they were my inspiration for creating this since I could not find a dependency that did this

๐Ÿ“ Here is the API documentation for the latest version powered by DocC

Installation

PillboxView is available through Swift Package Manager.

Project Dependency

In order to support both native AppKit and UIKit, PillboxView is leveraging the NSUI project. NSUI allows a single codebase to support both platforms with less #if pragma statements

The package description file package.swift defines that dependency. You should be aware of that information before including PillboxView into your own project

Example

  • Display a title message

  • Show an activity indicator to show ongoing activity IMG_439D92B0A93B-1

  • Indicate your task's success with a green checkmark IMG_9C967D1A90FD-1 or failure with a red x IMG_72EF15491E30-1

  • Animates between images and frames for clean effect

The repo of a complete example app can be found here

Quick Start

Asynchronous Task

This is great for network calls to assure the user that there is something going on.

All you have to do is pass in a title message and your UIViewController's UIView

import UIKit
import PillboxView

class ViewController: UIViewController {

    let pill = PillView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        pill.showTask(message: "Refreshing Data", vcView: self.view)
        
        // Update the task message while the task is ongoing
        pill.updateTask(message: "Still refreshing data...")
        
        // some time later...
        DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
          pill.completedTask(state: true) // this indicates the task's success
        }
    }
}

Error

This is especially useful if you want to display a concise error message, and the task's completion time is very quick (like checking the values of a UITextField and reporting if any are invalid.)

import UIKit
import PillboxView

class ViewController: UIViewController {

    let pill = PillView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        pill.showError(message: "Refreshing Data", vcView: self.view)
    }
}

Conclusion

Let me know how this is and help me improve this project with ideas, suggestions.

Requirements

iOS 13.0 or higher

License

PillboxView is available under the MIT license. See the LICENSE file for more info.

pillboxview's People

Contributors

awesomeplayer165 avatar martindufort avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pillboxview's Issues

Adding macOS Compatibility (via AppKit)

I have forked this repo in order to add macOS compatibility and add it to one of our project.

In order to do so, without a huge amount of #if os(macOS) layered everywhere, I decided to leverage the compatibility framework UXKit: https://github.com/ZeeZide/UXKit

Are you interested in a PR that would support macOS compatibility or you intend on keeping this compatible with iOS macCatalyst only.

This will also imply that your package will have a dependency on UXKit to be compiled without errors.
Thanks

Want to specify how long instant error stays

An example could be having a no internet pill for the duration of there being no internet, although this may be too intruding for the user and may not comply with my UI/UX taste.

Version errors in `PillboxView` source code

When working through my project, even though I have set my minimum version number in Xcode to 13, the minimum of PillboxView, it still shows errors throughout my project/workspace.

Add `UITapGestureRecognizer` for error task

Allow the user to click the pill and a target function would fire off - the developer would own this UITapGestureRecognizer or would allow PillboxView to create one and assign it. Either way, the tap would cover the whole PillboxView.pillView.

PIllView is never remove from the view hierarchy after being dismissed

When showing a PillView, the view is added to the vcView hierarchy.
However when dismissing the PillView all internals elements are removed but the PillView is never removed from the hierarchy.

See these lines:

vcView.addSubview(pillView)

imageView.removeFromSuperview()

vcView.addSubview(pillView)

imageView.removeFromSuperview()

Expected behavior
The PillView should be removed from the vcView hierarchy after being dismissed

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.