Commit 40654a35 authored by Elvin Hu's avatar Elvin Hu Committed by Commit Bot

[iOS][WidgetKit] Add main file and widget files.

Bug: 1138715, 1141522, 1141524, 1141523
Change-Id: I3f483577c27383be01f5150b72ad1d323d097f41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2471577
Commit-Queue: Javier Flores <javierrobles@chromium.org>
Commit-Queue: Elvin Hu <elvinhu@chromium.org>
Reviewed-by: default avatarJavier Flores <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822688}
parent 76137180
......@@ -35,7 +35,13 @@ compile_entitlements("entitlements") {
}
ios_appex_bundle("widget_kit_extension") {
sources = []
sources = [
"dino_game_widget.swift",
"main.swift",
"quick_actions_widget.swift",
"search_widget.swift",
"widget_constants.swift",
]
deps = [
":system_strings",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
import SwiftUI
import WidgetKit
struct DinoGameWidget: Widget {
let kind: String = "DinoGame_Widget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
DinoGameWidgetEntryView(entry: entry)
}
.configurationDisplayName(
Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_DISPLAY_NAME")
)
.description(Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_DESCRIPTION"))
.supportedFamilies([.systemSmall])
}
}
struct DinoGameWidgetEntryView: View {
let background = "widget_dino_background"
let backgroundPlaceholder = "widget_dino_background_placeholder"
var entry: Provider.Entry
@Environment(\.redactionReasons) var redactionReasons
var body: some View {
ZStack {
Image(redactionReasons.isEmpty ? background : backgroundPlaceholder)
.resizable()
.unredacted()
VStack(alignment: .leading, spacing: 0) {
Spacer()
.frame(minWidth: 0, maxWidth: .infinity)
HStack {
Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_TITLE")
.foregroundColor(Color("widget_text_color"))
.fontWeight(.semibold)
.font(.subheadline)
.lineLimit(1)
Spacer()
}
.padding([.leading, .bottom], 16)
}
}
.widgetURL(WidgetConstants.DinoGameWidget.url)
.accessibility(label: Text("IDS_IOS_WIDGET_KIT_EXTENSION_GAME_A11Y_LABEL"))
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
import SwiftUI
import WidgetKit
struct Provider: TimelineProvider {
typealias Entry = SimpleEntry
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry(date: Date())
}
func getSnapshot(
in context: Context,
completion: @escaping (SimpleEntry) -> Void
) {
let entry = SimpleEntry(date: Date())
completion(entry)
}
func getTimeline(
in context: Context,
completion: @escaping (Timeline<Entry>) -> Void
) {
let entry = SimpleEntry(date: Date())
let timeline = Timeline(entries: [entry], policy: .never)
completion(timeline)
}
}
struct SimpleEntry: TimelineEntry {
let date: Date
}
@main
struct ChromeWidgets: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
QuickActionsWidget()
SearchWidget()
DinoGameWidget()
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
import SwiftUI
import WidgetKit
struct QuickActionsWidget: Widget {
let kind: String = "QuickActionsWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
QuickActionsWidgetEntryView(entry: entry)
}
.configurationDisplayName(
Text("IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_DISPLAY_NAME")
)
.description(Text("IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_DESCRIPTION"))
.supportedFamilies([.systemMedium])
}
}
struct QuickActionsWidgetEntryView: View {
var entry: Provider.Entry
@Environment(\.redactionReasons) var redactionReasons
private let searchAreaHeight: CGFloat = 92
private let separatorHeight: CGFloat = 32
private let incognitoA11yLabel =
"IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_INCOGNITO_A11Y_LABEL"
private let voiceSearchA11yLabel =
"IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_VOICE_SEARCH_A11Y_LABEL"
private let qrA11yLabel =
"IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_QR_SCAN_A11Y_LABEL"
var body: some View {
VStack(spacing: 0) {
ZStack {
Color("widget_background_color")
.unredacted()
VStack {
Spacer()
Link(destination: WidgetConstants.QuickActionsWidget.searchUrl) {
ZStack {
RoundedRectangle(cornerRadius: 26)
.frame(height: 52)
.foregroundColor(Color("widget_search_bar_color"))
HStack(spacing: 12) {
Image("widget_chrome_logo")
.clipShape(Circle())
// Without .clipShape(Circle()), in the redacted/placeholder
// state the Widget shows an rectangle placeholder instead of
// a circular one.
.padding(.leading, 8)
.unredacted()
Text("IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_TITLE")
.font(.subheadline)
.foregroundColor(Color("widget_text_color"))
Spacer()
}
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding([.leading, .trailing], 11)
}
.accessibility(
label:
Text(
"IDS_IOS_WIDGET_KIT_EXTENSION_QUICK_ACTIONS_SEARCH_A11Y_LABEL"
)
)
Spacer()
}
.frame(height: searchAreaHeight)
}
ZStack {
Rectangle()
.foregroundColor(Color("widget_actions_row_background_color"))
.frame(minWidth: 0, maxWidth: .infinity)
HStack() {
// Show interactive buttons if the widget is fully loaded, and show
// the custom placeholder otherwise.
if (redactionReasons.isEmpty) {
Link(destination: WidgetConstants.QuickActionsWidget.incognitoUrl) {
Image("widget_incognito_icon")
.frame(minWidth: 0, maxWidth: .infinity)
}
.accessibility(label: Text(incognitoA11yLabel))
Separator(height: separatorHeight)
Link(
destination: WidgetConstants.QuickActionsWidget.voiceSearchUrl
) {
Image("widget_voice_search_icon")
.frame(minWidth: 0, maxWidth: .infinity)
}
.accessibility(label: Text(voiceSearchA11yLabel))
Separator(height: separatorHeight)
Link(destination: WidgetConstants.QuickActionsWidget.qrCodeUrl) {
Image("widget_qr_icon")
.frame(minWidth: 0, maxWidth: .infinity)
}
.accessibility(label: Text(qrA11yLabel))
} else {
ButtonPlaceholder()
Separator(height: separatorHeight)
ButtonPlaceholder()
Separator(height: separatorHeight)
ButtonPlaceholder()
}
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding([.leading, .trailing], 11)
}
}
}
}
struct Separator: View {
let height: CGFloat
var body: some View {
RoundedRectangle(cornerRadius: 1)
.foregroundColor(Color("widget_separator_color"))
.frame(width: 2, height: height)
}
}
struct ButtonPlaceholder: View {
private let widthOfPlaceholder: CGFloat = 28
var body: some View {
Group {
RoundedRectangle(cornerRadius: 4, style: .continuous)
.frame(width: widthOfPlaceholder, height: widthOfPlaceholder)
.foregroundColor(Color("widget_text_color"))
.opacity(0.3)
}.frame(minWidth: 0, maxWidth: .infinity)
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
import SwiftUI
import WidgetKit
struct SearchWidget: Widget {
let kind: String = "Search_Widget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
SearchWidgetEntryView(entry: entry)
}
.configurationDisplayName(
Text("IDS_IOS_WIDGET_KIT_EXTENSION_SEARCH_DISPLAY_NAME")
)
.description(Text("IDS_IOS_WIDGET_KIT_EXTENSION_SEARCH_DESCRIPTION"))
.supportedFamilies([.systemSmall])
}
}
struct SearchWidgetEntryView: View {
var entry: Provider.Entry
var body: some View {
ZStack {
Color("widget_background_color")
.unredacted()
VStack(alignment: .leading, spacing: 0) {
ZStack {
RoundedRectangle(cornerRadius: 26)
.frame(height: 52)
.foregroundColor(Color("widget_search_bar_color"))
HStack(spacing: 0) {
Image("widget_chrome_logo")
.clipShape(Circle())
.padding(.leading, 8)
.unredacted()
Spacer()
}
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding([.leading, .trailing], 11)
.padding(.top, 16)
Spacer()
Text("IDS_IOS_WIDGET_KIT_EXTENSION_SEARCH_TITLE")
.foregroundColor(Color("widget_text_color"))
.fontWeight(.semibold)
.font(.subheadline)
.padding([.leading, .bottom, .trailing], 16)
}
}
.widgetURL(WidgetConstants.SearchWidget.url)
.accessibility(
label: Text("IDS_IOS_WIDGET_KIT_EXTENSION_SEARCH_A11Y_LABEL")
)
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import Foundation
struct WidgetConstants {
struct SearchWidget {
static let url = URL(string: "chromewidgetkit://search-widget/search")!
}
struct QuickActionsWidget {
static let searchUrl =
URL(string: "chromewidgetkit://quick-actions-widget/search")!
static let incognitoUrl =
URL(string: "chromewidgetkit://quick-actions-widget/incognito")!
static let voiceSearchUrl =
URL(string: "chromewidgetkit://quick-actions-widget/voicesearch")!
static let qrCodeUrl =
URL(string: "chromewidgetkit://quick-actions-widget/qrreader")!
}
struct DinoGameWidget {
static let url = URL(string: "chromewidgetkit://dino-game-widget/game")!
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment