Giter Site home page Giter Site logo

beforeold / dynamicislandutilities Goto Github PK

View Code? Open in Web Editor NEW

This project forked from theblixguy/dynamicislandutilities

0.0 0.0 0.0 244 KB

A collection of utilities that provides functionality around the Dynamic Island on the iPhone 14 Pro/Max.

License: Apache License 2.0

Swift 100.00%

dynamicislandutilities's Introduction

DynamicIslandUtilities

A collection of utilities that provides functionality around the Dynamic Island on the iPhone 14 Pro/Max.

I will be adding more utilities to this package in the near future.

Utilities

DynamicIsland

A type that provides the size, origin, rect and some other information related to the Dynamic Island. For example, you can do:

let size = DynamicIsland.size

to get the size of the Dynamic Island cutout. This size is the same on both the iPhone 14 Pro and Max.

Warning At the moment, this provides the static size of the island, not the dynamic size (the island will expand if there's a live activity running).

DynamicIslandProgressIndicatorViewController

A UIViewController that provides a progress indicator around the Dynamic Island cutout.

To use it, simply subclass the view controller. You can subclass it even if you're not targetting iOS 16 yet, the minimum requirement is iOS 11.

In order to control the progress indicator, you need to use the configuration object by accessing dynamicIslandProgressIndicatorConfiguration, which will return a view into the progress indicator, allowing you to tweak the color, progress value/visibility or show an indeterminate animation.

dynamicIslandProgressIndicatorConfiguration.progressColor = .green
dynamicIslandProgressIndicatorConfiguration.isProgressIndeterminate = false

// Manual progress

doFixedWork { currentProgress in 
  if currentProgress == 100 {
    dynamicIslandProgressIndicatorConfiguration.hideProgressIndicator()
  } else {
    dynamicIslandProgressIndicatorConfiguration.progress = currentProgress
  }
}

/// Indeterminate progress

dynamicIslandProgressIndicatorConfiguration.showIndeterminateProgressAnimation()
doSomeWorkThatMayFinishLater { result in
 ...
 dynamicIslandProgressIndicatorConfiguration.hideProgressIndicator()
}

In order to access this property, you need to check DynamicIsland.isAvailable (this is enforced at runtime), which also nudges you to provide fallback logic:

if DynamicIsland.isAvailable {
  // Show a cool progress indicator around the Dynamic Island
  dynamicIslandProgressIndicatorConfiguration.showIndeterminateProgressAnimation()
} else {
  // Fallback to a default indicator
  showIndeterminateProgressBar()
}

Example:

Indeterminate

Manual

Note If you're using SwiftUI, I will be providing a native version for that soon. In the meantime, you can wrap the view controller manually.

Requirements

  • Swift Package Manager
  • Xcode 14

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.