Skip to content

Commit

Permalink
feat: update iOS home widget for iOS 17 API
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Jan 6, 2024
1 parent 5e05f2d commit 5e2106f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ios/CourseAppWidget/CourseAppWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct CourseAppWidgetEntryView: View {
.padding([.trailing, .leading], 8)
.multilineTextAlignment(.center)
}
.background(getContentBackgroudColor())
.widgetBackground(getContentBackgroudColor())
}
}
}
Expand All @@ -134,6 +134,7 @@ struct CourseAppWidget: Widget {
}
.configurationDisplayName("上課提醒")
.description("提醒本日下一堂課")
.disableContentMarginsIfNeeded()
}
}

Expand All @@ -143,3 +144,25 @@ struct CourseAppWidget_Previews: PreviewProvider {
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}

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

extension WidgetConfiguration {
func disableContentMarginsIfNeeded() -> some WidgetConfiguration {
if #available(iOSApplicationExtension 17.0, *) {
return self.contentMarginsDisabled()
} else {
return self
}
}
}

0 comments on commit 5e2106f

Please sign in to comment.