Widgets: Can you have a non-customisable static widget?

I want to add a large widget to my app, but it doesn't make sense to simply expand the information that's displayed in a small or medium widget to fill up the space of a large widget.

Let's say I have a bunch of events in my app, and the user can add a small/medium widget to their Home Screen and choose which one of their events the widget shows. This is fine and works well, but for a large widget I want to have a totally different experience.

I want to display the next four upcoming events in a list. These events are set by the order they're going to occur (date-wise) so you can't really pick which four you want to display, so I don't want to be able to edit the widget. However, if I add such a widget you can still hold down and edit the widget to select an event.

Also - and I'm not sure why it does this - when you hold down and edit the widget, it displays the title and description that are assigned to my small/medium AppIntentConfiguration widget, and not the title and description that are provided to the large StaticConfiguration widget, i.e.:

struct WidgetExtension: Widget  // Small/medium dynamic widget
{
	var body: some WidgetConfiguration {
		AppIntentConfiguration(
			kind: kWidgetKind,
			intent: WidgetEventIntent.self,
			provider: WidgetEventTimelineProvider()
		) { entry in
			WidgetEntry(entry: entry)
		}
		.configurationDisplayName(smallMediumTitle). // This and the line below...
		.description(NSLocalizedString(smallMediumDescription)  // are seen when editing the large widget
		.supportedFamilies([.systemSmall, .systemMedium])
	}
}

struct WidgetExtension_Large: Widget  // Large static widget
{
	var body: some WidgetConfiguration {
		StaticConfiguration(
			kind: kWidgetKind,
			provider: WidgetEventTimelineProvider_Large()
		) { entry in
			WidgetEntry_Large(entry: entry)
		}
		.configurationDisplayName(largeTitle)
		.description(largeDescription)
		.supportedFamilies([.systemLarge])
	}
}

If it's not possible to have a non-editable widget, it might be more fun to let the user select four events themselves, so I'd need to change the large widget to an AppIntentConfiguration widget, but what would the four parameters look like?

Currently, I have this for the small/medium widget that lets you select one event:

  @Parameter(title: "Event")
	var event: WidgetEventDetails?

	init(event: WidgetEventDetails? = nil) {
		self.event = event
	}

	init() {
	}

	static var parameterSummary: some ParameterSummary {
		Summary {
			\.$event
		}
	}

How would I change it to select four events? It might be helpful to only be able to select a second event if a first one has been chosen, and a third if a first & second have been chosen etc. Any ideas? Thanks.

Answered by jcgoforth in 770204022

What you have above is invalid, because you are trying to make two different widget definitions with the same “kind”. That value serves as the unique identifier for a widget definition. For a single given widget, they cannot have differences between configuration options at the various sizes (much to my own frustration). The only way to do what you are trying to do is make one widget for small/medium and a different widget for large (which means specifying a different ”kind”. The two different widgets can share a name and description so they sort of look like the same widget but there are a number of places that that it will be obvious they are split

Accepted Answer

What you have above is invalid, because you are trying to make two different widget definitions with the same “kind”. That value serves as the unique identifier for a widget definition. For a single given widget, they cannot have differences between configuration options at the various sizes (much to my own frustration). The only way to do what you are trying to do is make one widget for small/medium and a different widget for large (which means specifying a different ”kind”. The two different widgets can share a name and description so they sort of look like the same widget but there are a number of places that that it will be obvious they are split

Ah, hold on. That's a typo. The large one should be kWidgetKind_Large.

I've just changed it to that, and now the widget isn't editable. So, I guess that was the issue... Thanks!

Widgets: Can you have a non-customisable static widget?
 
 
Q