krzyzanowskim,
@krzyzanowskim@mastodon.social avatar

deleted_by_author

  • Loading...
    mattiem,
    @mattiem@mastodon.social avatar

    @krzyzanowskim I have used the function-in-environment approach before with success. But I don't think fits all situations.

    https://developer.apple.com/documentation/swiftui/environmentvalues/dismiss

    fcanas,
    @fcanas@mastodon.social avatar

    @krzyzanowskim There's nothing wrong with a singleton or NotificationCenter except you may need actions scoped independently some day. I don't have an answer to careful view hierarchy setup. It depends on your style and what you're guarding against. I like lumping environment dependencies into a single or small number of EnvironmentObjects that are passed by parameter at very high levels of the UI. Then they can be treated as (for-example) window-level singletons with more scoped access.

    ctietze,
    @ctietze@mastodon.social avatar

    @krzyzanowskim This rang my alarm:

    "Whatever I come up with stinks with either requiring carefully setup view hierarchy on top level..."

    I'm not sure what you're implying you're looking for. Care-free setup? Careless?

    What would that look like?

    Environment state injection is pretty flexible and very loosely coupled.

    NotificationCenter is, too.

    Can you clarify what you're looking for a bit more, maybe?

    krzyzanowskim,
    @krzyzanowskim@mastodon.social avatar

    deleted_by_author

  • Loading...
  • ctietze,
    @ctietze@mastodon.social avatar

    @krzyzanowskim Yeah I see, for this you need to extract whatever onCreateNote is applied to into another View type to attach (and read) the EnvironmentValue from there.

    This Y- or T-shaped hierarchy of components (text field and button + their parent(s)) absolutely requires manual orchestration.

    I also believe that's good, because I don't see how one would want to (!) design a component hierarchy differently.

    Or go full Redux/TCA, but then everythings always indirect.

    SergKoren,
    @SergKoren@writing.exchange avatar

    @krzyzanowskim If I understand your question, @Observable is your friend. Or maybe, .onChange()

    groue,
    @groue@hachyderm.io avatar

    @krzyzanowskim One possible bus could be a shared value stored as a State in a common ancestor view. If giving the button a binding to this value is painful because the button is too deep, then why not using the SwiftUI environment to pass a closure inspired from EnvironmentValues.dismiss, refresh, etc ?

    Stevenpotato,
    @Stevenpotato@mastodon.social avatar

    @krzyzanowskim A single EnvironmentObject?

    krzyzanowskim,
    @krzyzanowskim@mastodon.social avatar

    deleted_by_author

  • Loading...
  • Stevenpotato,
    @Stevenpotato@mastodon.social avatar
    emiliopelaez,
    @emiliopelaez@mastodon.social avatar

    @krzyzanowskim if you don’t want to use a singleton (which I wouldn’t want to do), there isn’t really a way of doing this that doesn’t involve setting something up in a common ancestor.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • SwiftUI
  • slotface
  • kavyap
  • thenastyranch
  • everett
  • tacticalgear
  • rosin
  • Durango
  • DreamBathrooms
  • mdbf
  • magazineikmin
  • InstantRegret
  • Youngstown
  • khanakhh
  • ethstaker
  • JUstTest
  • ngwrru68w68
  • cisconetworking
  • modclub
  • tester
  • osvaldo12
  • cubers
  • GTA5RPClips
  • normalnudes
  • Leos
  • provamag3
  • anitta
  • megavids
  • lostlight
  • All magazines