Skip to content

Instantly share code, notes, and snippets.

@wingovers
wingovers / About.md
Last active July 1, 2024 04:32
Transparent SwiftUI view clipped, cropped screenshot returned as UIImage (draft)

Had the darnedest time get the origin set correctly.

A few things that weren't obvious (to me at least):

  1. Convert the target child view to a UIHostingView, not self or body, otherwise your origin will be inexplicably quite off and screenshot will look drunk.
  2. Add +1 to the origin's y-axis, at least on the iPhone XS, because of course. Otherwise see above.
  3. A drawing group must be applied within the background modifier of your view, if your view has a background. Otherwise what's below bleeds through. And if you apply that else where that hierarchy disappears.
  4. In UIGraphics, override the background color to clear. UIHostingView conveniently resets the background to the system background color after the graphic returns. If you don't do this, within UIGraphics you can layer things transparently behind the UIView, but the readout back to SwiftUI will not be the cropped droid you were looking for.
  5. Scale and rotate do not work together as ExclusiveGestures. Ok.
  6. All the gestures perform for the us
@wingovers
wingovers / PotentialApproach.md
Last active April 22, 2024 21:22
Nesting ObservableObjects / Observing Repositories for SwiftUI

Nesting ObservableObjects / Observing Repositories for SwiftUI View Models

Situation

A simple app has a few repository objects that own the in-memory instance of specific models and organize persistence appropriately. Its instantiated by a DI container and passed to view models.

Observation

SwiftUI views do not diff and update upon changes within the repo's model. The view model does not fire its objectWillChange publisher – even though the repository is marked as @Published.

@wingovers
wingovers / Autofiller.swift
Last active January 16, 2022 13:45
Guess iOS Device Owner Name
// Ryan Ferrell say(hello) { github.com/wingovers }
class Autofiller {
enum NameComponent {
case givenName
case familyName
case fullNameInCurrentPersonNameComponentsFormatterStyle
}