Skip to content

Commit

Permalink
[Catalog] Adding feedback menu option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
galiak11 authored and material-automation committed Jun 5, 2020
1 parent b9e978c commit ff5e5cf
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 36 deletions.
24 changes: 13 additions & 11 deletions catalog/MDCCatalog/MDCCatalogWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -137,3 +135,7 @@ class MDCTouchView: UIView {
isUserInteractionEnabled = false
}
}

protocol MDCFeedback {
func showFeedbackDialog()
}
89 changes: 64 additions & 25 deletions catalog/MDCCatalog/MDCMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -26,23 +27,46 @@ 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
self.accessibilityHint = accessibilityHint
}
}

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() {
Expand All @@ -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]
Expand All @@ -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)
}
}
}

4 changes: 4 additions & 0 deletions catalog/MDCDragons/MDCCatalogWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@

import UIKit

protocol MDCFeedback {
func showFeedbackDialog()
}

class MDCCatalogWindow: UIWindow {}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

#import <UIKit/UIKit.h>

#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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff5e5cf

Please sign in to comment.