Why Do Some Views Appear as a Red No Entry Sign in Widgets

Why do some views appear as a red no entry sign in widgets?

Background

Widget Views are static.

They don't support animation, navigation nor user interaction (with the exception of Link). And they must be written in pure SwiftUI.



List of views that are not allowed in WidgetKit

Note that the list is not exhaustive, provided mostly with examples:

  1. Interactive views (ones you can interact with, e.g., by touching them):

    • List
    • Form
    • ScrollView
    • TabView
    • Map
    • Picker
    • Slider
    • and so on...
  2. Animated views:

    • ProgressView
  3. Navigation views (you can't use the standard navigation - for this you have Link):

    • NavigationView
    • NavigationLink
  4. UIKit Wrappers for UIKit Views/ViewControllers:

    • UIViewRepresentable
    • UIViewControllerRepresentable


Replacements

If you want to use any of the above views, e.g. an interactive view like List, you need to create it out of non-interactive views - here VStack + ForEach.

How to prevent iOS 14 Widget opening app and react to callback

Can I programmatically say "prevent opening app", when tapping on one of these buttons I've created in my Widget?

No, this is simply not possible (at least so far, in iOS 14).

By default whenever you tap on a Widget, the App will be opened. You can only specify deep links etc. but they'll always open the app.



I already read [...] that iOS 14 Widgets are NOT interactive

In this context interactive means that you can't touch/drag/interact with a Widget view like you'd normally do with a view in your main app (see Why do some views appear as a red no entry sign in widgets?).

Also, when you click on a Widget, you don't really interact with its view - you just open the app. As of iOS 14 you can't change it.



Related Topics



Leave a reply



Submit