Swiftpack.co - theblixguy/DynamicIslandUtilities as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by theblixguy.
theblixguy/DynamicIslandUtilities 0.0.4
A collection of utilities that provides functionality around the Dynamic Island on the iPhone 14 Pro/Max.
⭐️ 36
🕓 1 week ago
iOS
.package(url: "https://github.com/theblixguy/DynamicIslandUtilities.git", from: "0.0.4")

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

GitHub

link
Stars: 37
Last commit: Yesterday
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Moving things around
1 week ago
  • Rename hasDynamicIsland to isAvailable and move it to the DynamicIsland enum. Now you can do DynamicIsland.isAvailable to check whether you're running on an iPhone 14 Pro or iPhone 14 Pro Max.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics