wordpress-mobile / WordPress-iOS

WordPress for iOS - Official repository
http://ios.wordpress.org/
GNU General Public License v2.0
3.69k stars 1.12k forks source link

Widgets: Provide mandatory iOS 17 SDK Support #21672

Open staskus opened 1 year ago

staskus commented 1 year ago

Tasks

Description

After building the app with Xcode 15, Home and Lock screen widgets are no longer working and show please adopt containerBackground API message:

This is related to a new Removable background introduced at WWDC2023. More context:

Expected behavior

Widgets should support new APIs and this message should not be shown

Steps to reproduce the behavior

  1. Build Jetpack app with Xcode 15
  2. Try to add a widget
Tested on [device], iOS [version], Jetpack iOS / WordPress iOS [version]
staskus commented 1 year ago

In order to remove this message we need to support containerBackground API. The best way is to create an extension so both iOS17 and <=iOS16 would be supported:

extension View {
    func widgetBackground(_ backgroundView: some View) -> some View {
        if #available(iOSApplicationExtension 17.0, *) {
            return containerBackground(for: .widget) {
                backgroundView
            }
        } else {
            return background(backgroundView)
        }
    }
}

and attach it to the end of the view. This makes the background removable. Most notably, on iPadOS Lock Screen.

Issue

We use AccessoryWidgetBackground for our background. I couldn't find a way to integrate to containerBackground API, since SwiftUI requires to present it within ZStack. There were questions related to this on Apple forums. Likely that there's a solution I couldn't identify.