All Projects → theblixguy → Invalidating

theblixguy / Invalidating

Licence: MIT License
Backports the new @invalidating property wrapper to older platforms

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Invalidating

WebPKit
A framework that extends a variety of Cocoa APIs with capabilities for encoding and decoding WebP files for all of Apple's platforms.
Stars: ✭ 29 (-45.28%)
Mutual labels:  tvos, uikit, appkit
Driftwood
Driftwood is a DSL to make Auto Layout easy on iOS, tvOS and macOS.
Stars: ✭ 14 (-73.58%)
Mutual labels:  tvos, uikit, appkit
AppUIKit
iOS interface design for macOS app
Stars: ✭ 25 (-52.83%)
Mutual labels:  uikit, appkit
Swiftui
A collaborative list of awesome SwiftUI resources. Feel free to contribute!
Stars: ✭ 774 (+1360.38%)
Mutual labels:  tvos, uikit
Vtacknowledgementsviewcontroller
Acknowledgements screen displaying a list of licenses, for example from CocoaPods dependencies.
Stars: ✭ 863 (+1528.3%)
Mutual labels:  tvos, uikit
ikyle.me-code-examples
Smaller code examples from my blog posts on ikyle.me
Stars: ✭ 29 (-45.28%)
Mutual labels:  uikit, appkit
TextStory
Happier, more flexible NSTextStorage
Stars: ✭ 60 (+13.21%)
Mutual labels:  uikit, appkit
NativeMarkKit
NativeMark is a flavor of Markdown designed to be rendered by native apps.
Stars: ✭ 36 (-32.08%)
Mutual labels:  uikit, appkit
CompositionalLayoutDSL
CompositionalLayoutDSL, library to simplify the creation of UICollectionViewCompositionalLayout. It wraps the UIKit API and makes the code shorter and easier to read.
Stars: ✭ 47 (-11.32%)
Mutual labels:  tvos, appkit
RFKit
Toolkit for daily Cocoa development. Since 2012.
Stars: ✭ 20 (-62.26%)
Mutual labels:  tvos, uikit
SwiftCurrent
A library for managing complex workflows in Swift
Stars: ✭ 286 (+439.62%)
Mutual labels:  tvos, uikit
Acknowlist
Acknowledgements screen displaying a list of licenses, for example from CocoaPods dependencies.
Stars: ✭ 392 (+639.62%)
Mutual labels:  tvos, uikit
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+20100%)
Mutual labels:  tvos, uikit
curry
curry is a framework built to enhance and compliment Foundation and UIKit.
Stars: ✭ 47 (-11.32%)
Mutual labels:  tvos, uikit
SPConfetti
Show the confetti only when the user is having fun, and if not having fun, don't show it.
Stars: ✭ 187 (+252.83%)
Mutual labels:  tvos, uikit
Swift-IOS-ANE
FlashRuntimeExtensions.swift. Example Air Native Extension written in Swift 5 for iOS, macOS and tvOS
Stars: ✭ 56 (+5.66%)
Mutual labels:  tvos
quick-swift-check
Interoperability between Quick, Nimble and SwiftCheck.
Stars: ✭ 12 (-77.36%)
Mutual labels:  tvos
SwiftUI-Shimmer
Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for example, to show that an operation is in progress. It works well on light and dark modes, and across iOS, macOS, tvOS and watchOS.
Stars: ✭ 168 (+216.98%)
Mutual labels:  tvos
ViewDidAppearFirstTime
🙈 Adds viewWillAppearFirstTime(_:) and viewDidAppearFirstTime(_:) to UIViewController
Stars: ✭ 14 (-73.58%)
Mutual labels:  uikit
taiga-ui
Angular UI Kit and components library for awesome people
Stars: ✭ 2,251 (+4147.17%)
Mutual labels:  uikit

ViewInvalidating

A property wrapper that backports the new @Invalidating property wrapper to older versions of iOS/tvOS/macOS. For more information on this new property wrapper, see the WWDC 2021 talk "What's new in AppKit" for a brief introduction.

The syntax and types closely follows what Apple is doing, so when it's time to finally update your project's deployment target to iOS 15+/tvOS 15+/macOS 12+, you can easily migrate to using Apple's version by making very minimal changes. See the migration section for more info!

Usage

Annotate your Equatable properties with @ViewInvalidating and provide options that will be used to invalidate the view whenever the property's value changes:

final class MyView: UIView {
  // Calls setNeedsLayout()
  @ViewInvalidating(.layout) var cornerRadius: CGFloat = 12.0
  
  // Calls setNeedsLayout() then setNeedsUpdateConstraints()
  @ViewInvalidating(.layout, .constraints) var heightConstraintValue: CFloat = 200.0
  
  // Calls setNeedsLayout() then setNeedsUpdateConstraints() then invalidateIntrinsicContentSize()
  @ViewInvalidating(.layout, .constraints, .intrinsicContentSize) var magicProperty: CGFloat = 1234.0

You can initialize the property wrapper with up to 10 options. You can of course add extensions to support more options though, but realistically speaking you'll likely never have a need to pass more than a few of them!

By default, there is support for a total of 5 invalidation options per platform:

Common

  • Layout
  • Display
  • Constraints
  • Intrinsic Size

macOS only

  • Restorable State

iOS 14+ only

  • Configuration

Adding custom invalidators

You can add custom invalidators by creating a type that conforms to UIViewInvalidatingType or NSViewInvalidatingType protocol (depending on the target platform) and implementing the invalidate method requirement:

extension Invalidations {
  struct Focus: UIViewInvalidatingType {
    static let focus: Self = .init()

    func invalidate(view: UIView) {
      view.setNeedsFocusUpdate()
    }
  }
}

You can then expose it to the property wrapper by extending the InvalidatingStaticMember type:

extension InvalidatingStaticMember where Base: UIViewInvalidatingType {
  static var focus: InvalidatingStaticMember<Invalidations.Focus> { .init(.focus) }
}

Note:

If you're using Xcode 13, you should do this instead:

extension UIViewInvalidatingType where Self == Invalidations.Focus {
 static var focus: Self { .focus }
}

The InvalidatingStaticMember type only exists to workaround some language limitations which have been addressed in Swift 5.5, which ships with Xcode 13. So if you're on the latest Xcode, you do not need to use the workaround. The InvalidatingStaticMember will also be unavailable.

Then you can use your new invalidator on @ViewInvalidating:

final class MyView: UIView {

  // Calls setNeedsLayout() and Focus.invalidate(self)
  @ViewInvalidating(.layout, .focus) var customProperty: CGFloat = 1.0
}

Requirements

  • Deployment target of iOS 11+, tvOS 11+ or macOS 10.11+
  • Xcode 11 or above

Installation

Add the following to your project's Package.swift file:

.package(url: "https://github.com/theblixguy/Invalidating", from: "0.1.0")

or add this package via the Xcode UI by going to File > Swift Packages > Add Package Dependency.

Migration to iOS 15+/tvOS 15+/macOS 12+ deployment target

When it's time to update your project's deployment target to iOS 15+/tvOS 15+/macOS 12+, you will need to make some very minor changes to your code to make it compatible with Apple's @Invalidating and related types.

The types that ship with this package have been annotated with @available and contain the right mappings to Apple's types on its renamed argument to make it super easy for you to update your code. Once you have update the deployment target, you will see some errors:

Migration Fix-it Migration Fix-it

As you can see, they all offer a fix-it to automatically change the type names. With a click of a button, the errors disappears without you even having to manually rename them:

Migration Fix-it Migration Fix-it

License

MIT License

Copyright (c) 2021 Suyash Srijan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].