klemensstrasser,
@klemensstrasser@mastodon.social avatar

SwiftUI question!

Is there a nice way to repeatedly apply a ViewModifier?

Reason: Have an enum with all my accessibilityRotors, and want to apply the ViewModifier for all enabled rotors without cluttering the code.

ryanlintott,
@ryanlintott@mastodon.social avatar

@klemensstrasser I had to figure out a way to apply a variable array of accessibility actions to a view using a view modifier and I came up with this. It might be similar to what you're trying to do with rotors.

You can find the code here in my ILikeToMoveIt SPM:
https://github.com/ryanlintott/ILikeToMoveIt/blob/main/Sources/ILikeToMoveIt/AccessibilityMoveable.swift

maxmelzer,
@maxmelzer@mastodon.social avatar

@klemensstrasser Can you put a Group around the switch statement and apply the viewModifier to the Group? That is often the solution

klemensstrasser,
@klemensstrasser@mastodon.social avatar

@maxmelzer That’s the wrong way around 😬 I don’t have multiple views that all need the same modifier, I have a single view that gets “the same” modifier a couple of times.

Here is the code, first one shows the modifiers, second what the modifier does

image/jpeg

maxmelzer,
@maxmelzer@mastodon.social avatar

@klemensstrasser Ah, fun! Maybe implement a version of your ViewModifier that takes a List of enums instead of just one?

klemensstrasser,
@klemensstrasser@mastodon.social avatar

@maxmelzer But what would that help? 👀 How could I then apply all of them cleanly in the viewModifier?

maxmelzer,
@maxmelzer@mastodon.social avatar

@klemensstrasser Ah, sorry, I didn’t grok that your ViewModifier is calling another ViewModifier … tricky.

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