From ff5e5cfa2257d631f34857d9bca955f45c187780 Mon Sep 17 00:00:00 2001 From: Galia Kaufman Date: Fri, 5 Jun 2020 07:40:50 -0700 Subject: [PATCH] [Catalog] Adding feedback menu option Adding the "Leave Feedback" menu option to open up the feedback dialog - in the catalog's menu. Note some swift format diff to some swift files. PiperOrigin-RevId: 314925966 --- catalog/MDCCatalog/MDCCatalogWindow.swift | 24 ++--- .../MDCCatalog/MDCMenuViewController.swift | 89 +++++++++++++----- catalog/MDCDragons/MDCCatalogWindow.swift | 4 + .../Icons/icons/ic_feedback/src/Info.plist | Bin 0 -> 106 bytes .../src/MaterialIcons+ic_feedback.h | 30 ++++++ .../src/MaterialIcons+ic_feedback.m | 33 +++++++ .../Contents.json | 6 ++ .../ic_feedback.imageset/Contents.json | 23 +++++ .../ic_feedback.imageset/ic_feedback.png | Bin 0 -> 135 bytes .../ic_feedback.imageset/ic_feedback@2x.png | Bin 0 -> 204 bytes .../ic_feedback.imageset/ic_feedback@3x.png | Bin 0 -> 279 bytes 11 files changed, 173 insertions(+), 36 deletions(-) create mode 100644 components/private/Icons/icons/ic_feedback/src/Info.plist create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons+ic_feedback.h create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons+ic_feedback.m create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/Contents.json create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/Contents.json create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback.png create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback@2x.png create mode 100644 components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback@3x.png diff --git a/catalog/MDCCatalog/MDCCatalogWindow.swift b/catalog/MDCCatalog/MDCCatalogWindow.swift index 1a10ac00854..88a92fa6180 100644 --- a/catalog/MDCCatalog/MDCCatalogWindow.swift +++ b/catalog/MDCCatalog/MDCCatalogWindow.swift @@ -13,15 +13,12 @@ // limitations under the License. import UIKit - -import MaterialComponents.MaterialOverlayWindow import MaterialComponents.MaterialDialogs +import MaterialComponents.MaterialOverlayWindow -/** - A custom UIWindow that displays the user's touches for recording video or demos. - - Triple tapping anywhere will toggle the visible touches. - */ +/// A custom UIWindow that displays the user's touches for recording video or demos. +/// +/// Triple tapping anywhere will toggle the visible touches. class MDCCatalogWindow: MDCOverlayWindow { var showTouches = false @@ -103,13 +100,14 @@ class MDCCatalogWindow: MDCOverlayWindow { let view = touchViews[touch.hash] touchViews[touch.hash] = nil - UIView.animate(withDuration: fadeDuration, - animations: { view?.alpha = 0 }, - completion: { _ in view?.removeFromSuperview() }) + UIView.animate( + withDuration: fadeDuration, + animations: { view?.alpha = 0 }, + completion: { _ in view?.removeFromSuperview() }) } } -/** A circular view that represents a user's touch. */ +/// A circular view that represents a user's touch. class MDCTouchView: UIView { fileprivate let touchCircleSize: CGFloat = 80 fileprivate let touchCircleAlpha: CGFloat = 0.25 @@ -137,3 +135,7 @@ class MDCTouchView: UIView { isUserInteractionEnabled = false } } + +protocol MDCFeedback { + func showFeedbackDialog() +} diff --git a/catalog/MDCCatalog/MDCMenuViewController.swift b/catalog/MDCCatalog/MDCMenuViewController.swift index a1637295fda..771eccd92e5 100644 --- a/catalog/MDCCatalog/MDCMenuViewController.swift +++ b/catalog/MDCCatalog/MDCMenuViewController.swift @@ -13,11 +13,12 @@ // limitations under the License. import UIKit +import MaterialComponents.MaterialLibraryInfo import MaterialComponents.MaterialIcons -import MaterialComponents.MaterialIcons_ic_settings import MaterialComponents.MaterialIcons_ic_color_lens +import MaterialComponents.MaterialIcons_ic_feedback import MaterialComponents.MaterialIcons_ic_help_outline -import MaterialComponents.MaterialLibraryInfo +import MaterialComponents.MaterialIcons_ic_settings class MDCMenuViewController: UITableViewController { @@ -26,8 +27,10 @@ class MDCMenuViewController: UITableViewController { let icon: UIImage? let accessibilityLabel: String? let accessibilityHint: String? - init(_ title: String, _ icon: UIImage?, _ accessibilityLabel: String?, - _ accessibilityHint: String?) { + init( + _ title: String, _ icon: UIImage?, _ accessibilityLabel: String?, + _ accessibilityHint: String? + ) { self.title = title self.icon = icon self.accessibilityLabel = accessibilityLabel @@ -35,14 +38,35 @@ class MDCMenuViewController: UITableViewController { } } - private let tableData = - [MDCMenuItem("Settings", MDCIcons.imageFor_ic_settings()?.withRenderingMode(.alwaysTemplate), - nil, "Opens debugging menu."), - MDCMenuItem("Themes", MDCIcons.imageFor_ic_color_lens()?.withRenderingMode(.alwaysTemplate), - nil, "Opens color theme chooser."), - MDCMenuItem("v\(MDCLibraryInfo.versionString)", - MDCIcons.imageFor_ic_help_outline()?.withRenderingMode(.alwaysTemplate), - "Version \(MDCLibraryInfo.versionString)", "Closes this menu.")] + private let feedback: MDCFeedback? = { + // Using "as? MDCFeedback" (as opposed to "as MDCFeedback?") to avoid a build time error that + // occurs when MDCCatalogWindow does not conform to MDCFeedback. + return (UIApplication.shared.delegate as? AppDelegate)?.window as? MDCCatalogWindow + as? MDCFeedback + }() + + private lazy var tableData: [MDCMenuItem] = { + var data = [ + MDCMenuItem( + "Settings", MDCIcons.imageFor_ic_settings()?.withRenderingMode(.alwaysTemplate), + nil, "Opens debugging menu."), + MDCMenuItem( + "Themes", MDCIcons.imageFor_ic_color_lens()?.withRenderingMode(.alwaysTemplate), + nil, "Opens color theme chooser."), + MDCMenuItem( + "v\(MDCLibraryInfo.versionString)", + MDCIcons.imageFor_ic_help_outline()?.withRenderingMode(.alwaysTemplate), + "Version \(MDCLibraryInfo.versionString)", "Closes this menu."), + ] + if feedback != nil { + data.insert( + MDCMenuItem( + "Leave feedback", MDCIcons.imageFor_ic_feedback()?.withRenderingMode(.alwaysTemplate), + nil, "Opens debugging menu."), at: 0) + } + return data + }() + let cellIdentifier = "MenuCell" override func viewDidLoad() { @@ -51,8 +75,10 @@ class MDCMenuViewController: UITableViewController { self.tableView.separatorStyle = .none } - override func tableView(_ tableView: UITableView, - cellForRowAt indexPath: IndexPath) -> UITableViewCell { + override func tableView( + _ tableView: UITableView, + cellForRowAt indexPath: IndexPath + ) -> UITableViewCell { let iconColor = AppTheme.containerScheme.colorScheme.onSurfaceColor.withAlphaComponent(0.61) let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) let cellData = tableData[indexPath.item] @@ -78,21 +104,34 @@ class MDCMenuViewController: UITableViewController { guard let navController = self.presentingViewController as? UINavigationController else { return } - switch indexPath.item { + let action = feedback == nil ? indexPath.item + 1 : indexPath.item + switch action { case 0: - self.dismiss(animated: true, completion: { - if let appDelegate = UIApplication.shared.delegate as? AppDelegate, - let window = appDelegate.window as? MDCCatalogWindow { - window.showDebugSettings() - } - }) + self.dismiss( + animated: true, + completion: { + if let feedback = self.feedback { + feedback.showFeedbackDialog() + } + }) case 1: - self.dismiss(animated: true, completion: { - navController.pushViewController(MDCThemePickerViewController(), animated: true) - }) + self.dismiss( + animated: true, + completion: { + if let appDelegate = UIApplication.shared.delegate as? AppDelegate, + let window = appDelegate.window as? MDCCatalogWindow + { + window.showDebugSettings() + } + }) + case 2: + self.dismiss( + animated: true, + completion: { + navController.pushViewController(MDCThemePickerViewController(), animated: true) + }) default: self.dismiss(animated: true, completion: nil) } } } - diff --git a/catalog/MDCDragons/MDCCatalogWindow.swift b/catalog/MDCDragons/MDCCatalogWindow.swift index a4b8d0d7efa..74394dd5be7 100644 --- a/catalog/MDCDragons/MDCCatalogWindow.swift +++ b/catalog/MDCDragons/MDCCatalogWindow.swift @@ -14,4 +14,8 @@ import UIKit +protocol MDCFeedback { + func showFeedbackDialog() +} + class MDCCatalogWindow: UIWindow {} diff --git a/components/private/Icons/icons/ic_feedback/src/Info.plist b/components/private/Icons/icons/ic_feedback/src/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..f4bd0f571cd5a1021da5bfe746cd2df869f4ddf8 GIT binary patch literal 106 zcmYc)$jK}&F)+Bu$P_OiY0+7SCW~QnOYPtppu-QtCyaipPrMdmz$Cd n + +#import "MaterialIcons.h" + +// This file was automatically generated by running ./scripts/sync_icons.sh +// Do not modify directly. + +@interface MDCIcons (ic_feedback) + +/* + Returns the image for the ic_feedback image contained in + MaterialIcons_ic_feedback.bundle. + */ ++ (nullable UIImage *)imageFor_ic_feedback; + +@end diff --git a/components/private/Icons/icons/ic_feedback/src/MaterialIcons+ic_feedback.m b/components/private/Icons/icons/ic_feedback/src/MaterialIcons+ic_feedback.m new file mode 100644 index 00000000000..d829dc28e29 --- /dev/null +++ b/components/private/Icons/icons/ic_feedback/src/MaterialIcons+ic_feedback.m @@ -0,0 +1,33 @@ +// Copyright 2020-present the Material Components for iOS authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This file was automatically generated by running ./scripts/sync_icons.sh +// Do not modify directly. + +#import "MaterialIcons+ic_feedback.h" + +static NSString *const kBundleName = @"MaterialIcons_ic_feedback"; +static NSString *const kIconName = @"ic_feedback"; + +// Export a nonsense symbol to suppress a libtool warning when this is linked alone in a static lib. +__attribute__((visibility("default"))) char MDCIconsExportToSuppressLibToolWarning_ic_feedback = 0; + +@implementation MDCIcons (ic_feedback) + ++ (nullable UIImage *)imageFor_ic_feedback { + NSBundle *bundle = [self bundleNamed:kBundleName]; + return [UIImage imageNamed:kIconName inBundle:bundle compatibleWithTraitCollection:nil]; +} + +@end diff --git a/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/Contents.json b/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/Contents.json new file mode 100644 index 00000000000..2d92bd53fdb --- /dev/null +++ b/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/Contents.json b/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/Contents.json new file mode 100644 index 00000000000..d750ec32b86 --- /dev/null +++ b/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "ic_feedback.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "ic_feedback@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "ic_feedback@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback.png b/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback.png new file mode 100644 index 0000000000000000000000000000000000000000..3bf18621dea933891a16149dc49a04fab2dd5d34 GIT binary patch literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`Gjex5FlAr*|t5@83}I=(Z1tmpce zrf}_G+QHNrO0OcCIR6C;^9OMYH2f3mi87eg<@OlJl36yB^+M3iwh63%d9JW+F`LtP htQH=-#gJHV4Z|PN)-9VEWJYD@<);T3K0RW}mEqDL` literal 0 HcmV?d00001 diff --git a/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback@2x.png b/components/private/Icons/icons/ic_feedback/src/MaterialIcons_ic_feedback.xcassets/ic_feedback.imageset/ic_feedback@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..e46bfb5fe7dbe30b992dc7ff118e73cbcf0065a8 GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpUt$(}BbAr*{ouQswWJBqko40hs* zSn^mifty2NsZJ9^kb{A$j}%8+%iQz3YZ|`t9rMzx%{|=5e(YrVf`^Cx{4hV3^nI4= z9RsnwX^Zw5JTSNz@so>@iQ_^2eO`qI1||*#`%Mf?CzSaV8f+c`xep>`H-xj52aw1`d<}SkFU0i`}#4f*I%=i;bhJIf9A{PhytC*;OXk;vd$@?2>@Nh BNASq2O$KMCTR-D&n$x6kLY&2MhW_*0AFpLvd%vrnU;ewM`pF4N&q-HG9^cR^>$6Rc zJzw7aHtBQygEL9jBd)*rwlQE^mn=-_ai>q54J!+EX%^9_tl zEF1y~4pVD6fn);%l-s~yY6jt*n8^-S(6EXbLNnMhJhf&xwOxm?Qi;8!`z%B4JGt9O z)L5qrT_`g-@Zib8lg*RapO+VW0y95bTT}v>9+R$ozL);+$7Z1~TzNpBGI+ZBxvX