1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 import Foundation 6 import SwiftUI 7 import WidgetKit 8 9 struct DinoGameWidget: Widget { 10 let kind: String = "DinoGameWidget" 11 var body: some WidgetConfiguration { 12 StaticConfiguration(kind: kind, provider: Provider()) { entry in 13 DinoGameWidgetEntryView(entry: entry) 14 } 15 .configurationDisplayName( 16 Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_DISPLAY_NAME") 17 ) 18 .description(Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_DESCRIPTION")) 19 .supportedFamilies([.systemSmall]) 20 } 21 } 22 23 struct DinoGameWidgetEntryView: View { 24 let background = "widget_dino_background" 25 let backgroundPlaceholder = "widget_dino_background_placeholder" 26 var entry: Provider.Entry 27 @Environment(\.redactionReasons) var redactionReasons 28 var body: some View { 29 // We wrap this widget in a link on top of using `widgetUrl` so that the voice over will treat 30 // the widget as one tap target. Without the wrapping, voice over treats the content within 31 // the widget as multiple tap targets. 32 Link(destination: WidgetConstants.DinoGameWidget.url) { 33 ZStack { 34 Image(redactionReasons.isEmpty ? background : backgroundPlaceholder) 35 .resizable() 36 .unredacted() 37 VStack(alignment: .leading, spacing: 0) { 38 Spacer() 39 .frame(minWidth: 0, maxWidth: .infinity) 40 HStack { 41 Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_TITLE") 42 .foregroundColor(Color("widget_text_color")) 43 .fontWeight(.semibold) 44 .font(.subheadline) 45 .lineLimit(1) 46 Spacer() 47 } 48 .padding([.leading, .bottom], 16) 49 } 50 } 51 } 52 .widgetURL(WidgetConstants.DinoGameWidget.url) 53 .accessibility( 54 label: Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_A11Y_LABEL")) 55 } 56 } 57