79253133

Date: 2024-12-05 01:12:16
Score: 0.5
Natty:
Report link

This isn't working because onAppear isn't called after ThingListView is rendered for the first time (i.e. it isn't called when navigating back to the app). If you fully quit the app and run your shortcut, you'll see that it now works (because then onAppear is actually called for the first time after you set your navigateToThingAddView flag inside the intent).

One quick fix would be to use the following instead:

.onChange(of: navigateToThingAddView) { _, newValue in
  if newValue {
    showThingAddView = true
    navigateToThingAddView = false
  }
}

I should note that this whole setup with @AppStorage and a boolean flag is a bit clunky. A better way to accomplish this would be to use @Dependency to pass navigation info – see https://stackoverflow.com/a/77342508. You could also use onOpenURL (see the other answer on that same question). Both would allow you to navigate without a dummy flag stored in UserDefaults and without having to worry about setting that flag back to false.

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: tenuki