More SwiftLint fixes for unit tests and example apps. (#1154)

* ClangFormat changes.

* Added swiftlint to scripts/format_all.`

* Fix scripts/lint_all to work from any directory.

* Fixed swiftlint invocation.

* Remove the checks for force casting (! operator).

* Some fixes.

* More Swift fixes.
This commit is contained in:
Adrian Secord 2017-01-11 13:27:57 -05:00 committed by Will Larche
parent 99d59f3fc6
commit 8bcb19781c
28 changed files with 188 additions and 91 deletions

View File

@ -6,7 +6,9 @@ excluded:
disabled_rules:
- cyclomatic_complexity
- force_cast
- todo
- type_name
line_length: 100

View File

@ -507,7 +507,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${SRCROOT}/../scripts/lint.sh";
shellScript = "${SRCROOT}/../scripts/lint_all";
};
72ACDAA295D1F2087113246F /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;

View File

@ -76,17 +76,21 @@ class AppBarDelegateForwardingExample: UITableViewController {
}
}
override func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
override func scrollViewDidEndDragging(_ scrollView: UIScrollView,
willDecelerate decelerate: Bool) {
let headerView = self.appBar.headerViewController.headerView
if scrollView == headerView.trackingScrollView {
headerView.trackingScrollDidEndDraggingWillDecelerate(decelerate)
}
}
override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
override func scrollViewWillEndDragging(_ scrollView: UIScrollView,
withVelocity velocity: CGPoint,
targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let headerView = self.appBar.headerViewController.headerView
if scrollView == headerView.trackingScrollView {
headerView.trackingScrollWillEndDragging(withVelocity: velocity, targetContentOffset: targetContentOffset)
headerView.trackingScrollWillEndDragging(withVelocity: velocity,
targetContentOffset: targetContentOffset)
}
}

View File

@ -64,8 +64,11 @@ class AppBarEncodingTests: XCTestCase {
XCTAssertEqual(appBar.navigationBar.title,
unarchivedAppBar?.navigationBar.title)
XCTAssertEqual(appBar.navigationBar.titleTextAttributes?[NSForegroundColorAttributeName] as? UIColor,
unarchivedAppBar?.navigationBar.titleTextAttributes?[NSForegroundColorAttributeName] as? UIColor)
let foregroundColor =
appBar.navigationBar.titleTextAttributes?[NSForegroundColorAttributeName]
let unarchivedForegroundColor =
unarchivedAppBar?.navigationBar.titleTextAttributes?[NSForegroundColorAttributeName]
XCTAssertEqual(foregroundColor as? UIColor, unarchivedForegroundColor as? UIColor)
XCTAssertEqual(appBar.navigationBar.titleAlignment,
unarchivedAppBar?.navigationBar.titleAlignment)

View File

@ -17,7 +17,7 @@
import Foundation
import MaterialComponents
class ButtonsStoryboardAndProgrammaticController: UIViewController {
class ButtonsSwiftAndStoryboardController: UIViewController {
class func catalogBreadcrumbs() -> [String] {
return ["Buttons", "Buttons (Swift and Storyboard)"]
@ -63,17 +63,53 @@ class ButtonsStoryboardAndProgrammaticController: UIViewController {
self.view.addSubview(containerView)
NSLayoutConstraint.activate([
NSLayoutConstraint(item: containerView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: containerView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: containerView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: containerView, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 0.5, constant: 0)
NSLayoutConstraint(item: containerView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leading,
multiplier: 1.0,
constant: 0),
NSLayoutConstraint(item: containerView,
attribute: .top,
relatedBy: .equal,
toItem: view,
attribute: .top,
multiplier: 1.0,
constant: 0),
NSLayoutConstraint(item: containerView,
attribute: .bottom,
relatedBy: .equal,
toItem: view,
attribute: .bottom,
multiplier: 1.0,
constant: 0),
NSLayoutConstraint(item: containerView,
attribute: .width,
relatedBy: .equal,
toItem: view,
attribute: .width,
multiplier: 0.5,
constant: 0)
])
containerView.addSubview(innerContainerView)
NSLayoutConstraint.activate([
NSLayoutConstraint(item: innerContainerView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: innerContainerView, attribute: .centerY, relatedBy: .equal, toItem: containerView, attribute: .centerY, multiplier: 1.0, constant: 0)
NSLayoutConstraint(item: innerContainerView,
attribute: .centerX,
relatedBy: .equal,
toItem: containerView,
attribute: .centerX,
multiplier: 1.0,
constant: 0),
NSLayoutConstraint(item: innerContainerView,
attribute: .centerY,
relatedBy: .equal,
toItem: containerView,
attribute: .centerY,
multiplier: 1.0,
constant: 0)
])
raisedButton.setTitle("Programmatic", for: UIControlState())

View File

@ -11,10 +11,10 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Buttons Storyboard And Programmatic Controller-->
<!--Buttons Swift And Storyboard Controller-->
<scene sceneID="4Dd-I6-MBs">
<objects>
<viewController id="rmZ-Mt-scB" customClass="ButtonsStoryboardAndProgrammaticController" customModule="MaterialComponentsCatalog" sceneMemberID="viewController">
<viewController id="rmZ-Mt-scB" customClass="ButtonsSwiftAndStoryboardController" customModule="MaterialComponentsCatalog" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="dkA-v6-Opi"/>
<viewControllerLayoutGuide type="bottom" id="QjK-x9-gr9"/>

View File

@ -55,7 +55,7 @@ class CollectionsSimpleSwiftDemo: MDCCollectionViewController {
// MARK: Catalog by convention
extension CollectionsSimpleSwiftDemo {
class func catalogBreadcrumbs() -> Array<String> {
class func catalogBreadcrumbs() -> [String] {
return [ "Collections", "Simple Swift Demo"]
}
}

View File

@ -20,7 +20,7 @@ static const NSInteger kSectionCount = 10;
static const NSInteger kSectionItemCount = 5;
static NSString *const kReusableIdentifierItem = @"customCell";
@interface CollectionStoryboardExampleCell: UICollectionViewCell
@interface CollectionStoryboardExampleCell : UICollectionViewCell
@property(nonatomic, weak) IBOutlet UILabel *label;
@end

View File

@ -33,9 +33,22 @@ class DialogsLongAlertViewController: UIViewController {
flatButton.addTarget(self, action: #selector(tap), for: .touchUpInside)
self.view.addSubview(flatButton)
NSLayoutConstraint(item:flatButton, attribute:.centerX, relatedBy:.equal, toItem:self.view, attribute:.centerX, multiplier:1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item:flatButton, attribute:.centerY, relatedBy:.equal, toItem:self.view, attribute:.centerY, multiplier:1.0, constant: 0.0).isActive = true
NSLayoutConstraint.activate([
NSLayoutConstraint(item:flatButton,
attribute:.centerX,
relatedBy:.equal,
toItem:self.view,
attribute:.centerX,
multiplier:1.0,
constant: 0.0),
NSLayoutConstraint(item:flatButton,
attribute:.centerY,
relatedBy:.equal,
toItem:self.view,
attribute:.centerY,
multiplier:1.0,
constant: 0.0)
])
}
func tap(_ sender: AnyObject) {
@ -63,7 +76,7 @@ class DialogsLongAlertViewController: UIViewController {
// MARK: Catalog by convention
extension DialogsLongAlertViewController {
class func catalogBreadcrumbs() -> Array<String> {
class func catalogBreadcrumbs() -> [String] {
return [ "Dialogs", "Swift Alert Demo"]
}
class func catalogDescription() -> String {

View File

@ -39,7 +39,7 @@ typedef void (^MDCFeatureHighlightCompletion)(BOOL accepted);
While MDCFeatureHighlightViewController supports changing state while presented, it is not
recommended as the design spec does not specify any patterns for that behavior.
@note Due to a bug in the iOS simulator it is possible that the feature highlight will not render
correctly in the simulator. If you're encountering issues make sure to test on device.
*/

View File

@ -149,8 +149,8 @@ const CGFloat kMDCFeatureHighlightPulseRadiusBloomAmount =
- (void)setDisplayedView:(UIView *)displayedView {
CGSize displayedSize = displayedView.frame.size;
CGFloat viewRadius = (CGFloat)sqrt(pow(displayedSize.width/2, 2) +
pow(displayedSize.height/2, 2));
CGFloat viewRadius =
(CGFloat)sqrt(pow(displayedSize.width / 2, 2) + pow(displayedSize.height / 2, 2));
viewRadius += kMDCFeatureHighlightInnerContentPadding;
_innerRadius = MAX(viewRadius, kMDCFeatureHighlightMinimumInnerRadius);
@ -179,9 +179,7 @@ const CGFloat kMDCFeatureHighlightPulseRadiusBloomAmount =
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseOut]];
[CATransaction setAnimationDuration:duration];
[_displayMaskLayer setCenter:displayMaskCenter
radius:_innerRadius
animated:YES];
[_displayMaskLayer setCenter:displayMaskCenter radius:_innerRadius animated:YES];
[_innerLayer setFillColor:[_innerHighlightColor colorWithAlphaComponent:1].CGColor animated:YES];
[_innerLayer setCenter:_highlightPoint radius:_innerRadius animated:YES];
[_outerLayer setFillColor:_outerHighlightColor.CGColor animated:YES];
@ -206,11 +204,9 @@ const CGFloat kMDCFeatureHighlightPulseRadiusBloomAmount =
functionWithName:kCAMediaTimingFunctionEaseOut]];
CGFloat innerBloomRadius = radius + kMDCFeatureHighlightInnerRadiusBloomAmount;
CGFloat pulseBloomRadius = radius + kMDCFeatureHighlightPulseRadiusBloomAmount;
NSArray *innerKeyframes =
@[ @(radius), @(innerBloomRadius), @(radius) ];
NSArray *innerKeyframes = @[ @(radius), @(innerBloomRadius), @(radius) ];
[_innerLayer animateRadiusOverKeyframes:innerKeyframes keyTimes:keyTimes center:_highlightPoint];
NSArray *pulseKeyframes =
@[ @(radius), @(radius), @(pulseBloomRadius) ];
NSArray *pulseKeyframes = @[ @(radius), @(radius), @(pulseBloomRadius) ];
[_pulseLayer animateRadiusOverKeyframes:pulseKeyframes keyTimes:keyTimes center:_highlightPoint];
[_pulseLayer animateFillColorOverKeyframes:@[ pulseColorStart, pulseColorStart, pulseColorEnd ]
keyTimes:keyTimes];
@ -320,15 +316,15 @@ const CGFloat kMDCFeatureHighlightPulseRadiusBloomAmount =
CGRect textFrames = CGRectUnion(_titleLabel.frame, _bodyLabel.frame);
CGFloat distX = ABS(CGRectGetMidX(textFrames) - _highlightCenter.x) + textFrames.size.width / 2;
CGFloat distY = ABS(CGRectGetMidY(textFrames) - _highlightCenter.y) + textFrames.size.height / 2;
CGFloat minTextRadius = (CGFloat)(sqrt(pow(distX, 2) + pow(distY, 2))
+ kMDCFeatureHighlightTextPadding);
CGFloat minTextRadius =
(CGFloat)(sqrt(pow(distX, 2) + pow(distY, 2)) + kMDCFeatureHighlightTextPadding);
// Calculating the radius required for a circle centered at _highlightCenter that fully encircles
// the inner highlight.
distX = ABS(_highlightCenter.x - _highlightPoint.x);
distY = ABS(_highlightCenter.y - _highlightPoint.y);
CGFloat minInnerHighlightRadius = (CGFloat)(sqrt(pow(distX, 2) + pow(distY, 2)) + _innerRadius
+ kMDCFeatureHighlightInnerPadding);
CGFloat minInnerHighlightRadius = (CGFloat)(sqrt(pow(distX, 2) + pow(distY, 2)) + _innerRadius +
kMDCFeatureHighlightInnerPadding);
// Use the larger of the two radii to ensure everything is encircled.
_outerRadius = MAX(minTextRadius, minInnerHighlightRadius);

View File

@ -60,7 +60,8 @@ class FlexibleHeaderControllerIssue176Tests: XCTestCase {
fhvc.didMove(toParentViewController: parentVc)
XCTAssertEqual(fhvc.headerView.trackingScrollView!.contentOffset.y, -fhvc.headerView.maximumHeight)
XCTAssertEqual(fhvc.headerView.trackingScrollView!.contentOffset.y,
-fhvc.headerView.maximumHeight)
XCTAssertEqual(fhvc.view.bounds.size.height, fhvc.headerView.maximumHeight)
}
}

View File

@ -27,14 +27,19 @@ class ScrollViewContentOffsetSideEffectTests: XCTestCase {
// Calculates the estimated contentOffset given the proposed new contentInsets and current value
// of contentOffset + contentSize.
class func estimatedContentOffsetForScrollView(_ scrollView: UIScrollView, withNewInsets newInsets: UIEdgeInsets) -> CGPoint {
class func estimatedContentOffsetForScrollView(_ scrollView: UIScrollView,
withNewInsets newInsets: UIEdgeInsets) -> CGPoint {
let minimumPossibleYOffset = -newInsets.top
let maximumPossibleYOffset = (scrollView.contentSize.height + newInsets.bottom) - scrollView.bounds.height
let estimatedYOffset = max(minimumPossibleYOffset, min(maximumPossibleYOffset, scrollView.contentOffset.y))
let maximumPossibleYOffset =
(scrollView.contentSize.height + newInsets.bottom) - scrollView.bounds.height
let estimatedYOffset =
max(minimumPossibleYOffset, min(maximumPossibleYOffset, scrollView.contentOffset.y))
let minimumPossibleXOffset = -newInsets.left
let maximumPossibleXOffset = (scrollView.contentSize.width + newInsets.right) - scrollView.bounds.width
let estimatedXOffset = max(minimumPossibleXOffset, min(maximumPossibleXOffset, scrollView.contentOffset.x))
let maximumPossibleXOffset =
(scrollView.contentSize.width + newInsets.right) - scrollView.bounds.width
let estimatedXOffset =
max(minimumPossibleXOffset, min(maximumPossibleXOffset, scrollView.contentOffset.x))
return CGPoint(x: estimatedXOffset, y: estimatedYOffset)
}
@ -42,52 +47,54 @@ class ScrollViewContentOffsetSideEffectTests: XCTestCase {
func testEstimationAddingTopInsets() {
let insets = UIEdgeInsets(top: inset, left: 0, bottom: 0, right: 0)
enumerateHeightRangeWithInsets(UIEdgeInsets(), after: insets) { scrollView, estimatedContentOffset in
XCTAssertEqual(scrollView.contentOffset, estimatedContentOffset)
enumerateHeightRangeWithInsets(UIEdgeInsets(), after: insets) { scrollView, contentOffset in
XCTAssertEqual(scrollView.contentOffset, contentOffset)
}
}
func testEstimationRemovingTopInsets() {
let insets = UIEdgeInsets(top: inset, left: 0, bottom: 0, right: 0)
enumerateHeightRangeWithInsets(insets, after: UIEdgeInsets()) { scrollView, estimatedContentOffset in
XCTAssertEqual(scrollView.contentOffset, estimatedContentOffset)
enumerateHeightRangeWithInsets(insets, after: UIEdgeInsets()) { scrollView, contentOffset in
XCTAssertEqual(scrollView.contentOffset, contentOffset)
}
}
func testEstimationAddingBottomInsets() {
let insets = UIEdgeInsets(top: 0, left: 0, bottom: inset, right: 0)
enumerateHeightRangeWithInsets(UIEdgeInsets(), after: insets) { scrollView, estimatedContentOffset in
XCTAssertEqual(scrollView.contentOffset, estimatedContentOffset)
enumerateHeightRangeWithInsets(UIEdgeInsets(), after: insets) { scrollView, contentOffset in
XCTAssertEqual(scrollView.contentOffset, contentOffset)
}
}
func testEstimationRemovingBottomInsets() {
let insets = UIEdgeInsets(top: 0, left: 0, bottom: inset, right: 0)
enumerateHeightRangeWithInsets(insets, after: UIEdgeInsets()) { scrollView, estimatedContentOffset in
XCTAssertEqual(scrollView.contentOffset, estimatedContentOffset)
enumerateHeightRangeWithInsets(insets, after: UIEdgeInsets()) { scrollView, contentOffset in
XCTAssertEqual(scrollView.contentOffset, contentOffset)
}
}
func testEstimationAddingBothInsets() {
let insets = UIEdgeInsets(top: inset, left: 0, bottom: inset, right: 0)
enumerateHeightRangeWithInsets(UIEdgeInsets(), after: insets) { scrollView, estimatedContentOffset in
XCTAssertEqual(scrollView.contentOffset, estimatedContentOffset)
enumerateHeightRangeWithInsets(UIEdgeInsets(), after: insets) { scrollView, contentOffset in
XCTAssertEqual(scrollView.contentOffset, contentOffset)
}
}
func testEstimationRemovingBothInsets() {
let insets = UIEdgeInsets(top: inset, left: 0, bottom: inset, right: 0)
enumerateHeightRangeWithInsets(insets, after: UIEdgeInsets()) { scrollView, estimatedContentOffset in
XCTAssertEqual(scrollView.contentOffset, estimatedContentOffset)
enumerateHeightRangeWithInsets(insets, after: UIEdgeInsets()) { scrollView, contentOffset in
XCTAssertEqual(scrollView.contentOffset, contentOffset)
}
}
func enumerateHeightRangeWithInsets(_ before: UIEdgeInsets, after: UIEdgeInsets, work: (UIScrollView, CGPoint) -> Void) {
func enumerateHeightRangeWithInsets(_ before: UIEdgeInsets,
after: UIEdgeInsets,
work: (UIScrollView, CGPoint) -> Void) {
for contentHeight in -1...Int(bounds.height * 3) {
let scrollView = UITableView(frame: bounds)

View File

@ -41,7 +41,8 @@ class PageControlSwiftExampleViewController: UIViewController, UIScrollViewDeleg
scrollView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
scrollView.delegate = self
scrollView.isPagingEnabled = true
scrollView.contentSize = CGSize(width: view.bounds.width * CGFloat(pageColors.count), height: view.bounds.height)
scrollView.contentSize = CGSize(width: view.bounds.width * CGFloat(pageColors.count),
height: view.bounds.height)
scrollView.showsHorizontalScrollIndicator = false
view.addSubview(scrollView)
@ -62,7 +63,10 @@ class PageControlSwiftExampleViewController: UIViewController, UIScrollViewDeleg
pageControl.numberOfPages = pageColors.count
let pageControlSize = pageControl.sizeThatFits(view.bounds.size)
pageControl.frame = CGRect(x: 0, y: view.bounds.height - pageControlSize.height, width: view.bounds.width, height: pageControlSize.height)
pageControl.frame = CGRect(x: 0,
y: view.bounds.height - pageControlSize.height,
width: view.bounds.width,
height: pageControlSize.height)
pageControl.addTarget(self, action: #selector(didChangePage), for: .valueChanged)
pageControl.autoresizingMask = [.flexibleTopMargin, .flexibleWidth]
view.addSubview(pageControl)
@ -77,7 +81,8 @@ class PageControlSwiftExampleViewController: UIViewController, UIScrollViewDeleg
let pageLabel: UILabel = page as! UILabel
pageLabel.frame = view.bounds.offsetBy(dx: CGFloat(i) * view.bounds.width, dy: 0)
}
scrollView.contentSize = CGSize(width: view.bounds.width * CGFloat(pages.count), height: view.bounds.height)
scrollView.contentSize = CGSize(width: view.bounds.width * CGFloat(pages.count),
height: view.bounds.height)
var offset = scrollView.contentOffset
offset.x = CGFloat(pageBeforeFrameChange) * view.bounds.width
// This non-anmiated change of offset ensures we keep the same page

View File

@ -24,7 +24,10 @@ private func generateRandomPalettes(_ count: Int) -> [(name: String, palette: MD
var palettes = [(name: String, palette: MDCPalette)]()
for _ in 1...count {
let rgb = [randomFloat(), randomFloat(), randomFloat()]
let name = String(format: "Generated from #%2X%2X%2X", Int(rgb[0] * 255), Int(rgb[1] * 255), Int(rgb[2] * 255))
let name = String(format: "Generated from #%2X%2X%2X",
Int(rgb[0] * 255),
Int(rgb[1] * 255),
Int(rgb[2] * 255))
let color = UIColor.init(red: rgb[0], green: rgb[1], blue: rgb[2], alpha: 1)
palettes.append((name, MDCPalette.init(generatedFrom: color)))
}

View File

@ -52,7 +52,8 @@ class PalettesExampleViewController: UITableViewController {
return ExampleTonesForPalette(palette).count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
@ -66,7 +67,8 @@ class PalettesExampleViewController: UITableViewController {
return cell!
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
override func tableView(_ tableView: UITableView,
titleForHeaderInSection section: Int) -> String? {
return palettes[section].name
}

View File

@ -51,18 +51,18 @@ class ShadowDragSquareExampleViewController: UIViewController {
func longPressedInView(_ sender: UILongPressGestureRecognizer) {
// Elevation of the view is changed to indicate that it has been pressed or released.
// view.center is changed to follow the touch events.
if (sender.state == .began) {
if sender.state == .began {
self.blueView.setElevation(kSelectedCardElevation)
let selfPoint = sender.location(in: self.view)
movingViewOffset.x = selfPoint.x - self.blueView.center.x
movingViewOffset.y = selfPoint.y - self.blueView.center.y
} else if (sender.state == .changed) {
} else if sender.state == .changed {
let selfPoint = sender.location(in: self.view)
let newCenterPoint =
CGPoint(x: selfPoint.x - movingViewOffset.x, y: selfPoint.y - movingViewOffset.y)
self.blueView.center = newCenterPoint
} else if (sender.state == .ended) {
} else if sender.state == .ended {
self.blueView.setElevation(kRestingCardElevation)
movingViewOffset = CGPoint.zero
@ -71,7 +71,7 @@ class ShadowDragSquareExampleViewController: UIViewController {
// MARK: catalog by convention
class func catalogBreadcrumbs() -> Array<String> {
class func catalogBreadcrumbs() -> [String] {
return [ "Shadow", "Shadow Layer"]
}

View File

@ -38,7 +38,8 @@ class TypographyFontListExampleViewController: UITableViewController {
return fonts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
if cell == nil {
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")

View File

@ -22,7 +22,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let flexHeadVC = ShrineFlexibleHeaderContainerViewController()
self.window?.rootViewController = flexHeadVC

View File

@ -105,16 +105,14 @@ class ShrineCollectionViewCell: UICollectionViewCell {
labelPrice.text = price
let urlString = ShrineData.baseURL + imageName
let url = URL(string: urlString)
remoteImageService.fetchImageAndThumbnail(from: url) { (image: UIImage?,
thumbnailImage: UIImage?) -> Void in
remoteImageService.fetchImageAndThumbnail(from: url) { image, thumbnailImage in
DispatchQueue.main.sync(execute: {
self.imageView.image = thumbnailImage
})
}
let avatarURLString = ShrineData.baseURL + avatar
let avatarURL = URL(string: avatarURLString)
remoteImageService.fetchImageAndThumbnail(from: avatarURL) { (image: UIImage?,
thumbnailImage: UIImage?) -> Void in
remoteImageService.fetchImageAndThumbnail(from: avatarURL) { image, thumbnailImage in
DispatchQueue.main.sync(execute: {
self.avatar.image = thumbnailImage
})

View File

@ -27,7 +27,8 @@ class ShrineCollectionViewController: UICollectionViewController {
self.shrineData = ShrineData()
self.shrineData.readJSON()
super.init(collectionViewLayout: layout)
self.collectionView?.register(ShrineCollectionViewCell.self, forCellWithReuseIdentifier: "ShrineCollectionViewCell")
self.collectionView?.register(ShrineCollectionViewCell.self,
forCellWithReuseIdentifier: "ShrineCollectionViewCell")
self.collectionView?.backgroundColor = UIColor(white: 0.97, alpha: 1)
}
@ -46,7 +47,8 @@ class ShrineCollectionViewController: UICollectionViewController {
override func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ShrineCollectionViewCell", for: indexPath) as! ShrineCollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ShrineCollectionViewCell",
for: indexPath) as! ShrineCollectionViewCell
let itemNum: NSInteger = (indexPath as NSIndexPath).row
let title = self.shrineData.titles[itemNum] as! String
@ -83,7 +85,7 @@ class ShrineCollectionViewController: UICollectionViewController {
headerViewController.scrollViewDidScroll(scrollView)
let scrollOffsetY = scrollView.contentOffset.y
let duration = 0.5
if (scrollOffsetY > -240) {
if scrollOffsetY > -240 {
UIView.animate(withDuration: duration, animations: {
self.headerContentView.scrollView.alpha = 0
self.headerContentView.pageControl.alpha = 0
@ -103,7 +105,7 @@ class ShrineCollectionViewController: UICollectionViewController {
func sizeHeaderView() {
let headerView = headerViewController.headerView
let bounds = UIScreen.main.bounds
if (bounds.size.width < bounds.size.height) {
if bounds.size.width < bounds.size.height {
headerView.maximumHeight = 440
headerView.minimumHeight = 72
} else {
@ -112,7 +114,8 @@ class ShrineCollectionViewController: UICollectionViewController {
}
}
override func willAnimateRotation(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
override func willAnimateRotation(to toInterfaceOrientation: UIInterfaceOrientation,
duration: TimeInterval) {
sizeHeaderView()
collectionView?.collectionViewLayout.invalidateLayout()
}

View File

@ -32,7 +32,8 @@ class ShrineData {
var json: NSDictionary!
do {
let data = try? Data(contentsOf: URL(fileURLWithPath: filePath!))
json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions()) as? NSDictionary
let option = JSONSerialization.ReadingOptions()
json = try JSONSerialization.jsonObject(with: data!, options: options) as? NSDictionary
} catch _ {
print("Couldn't get JSON data")
}

View File

@ -44,8 +44,7 @@ class ShrineDetailView: UIScrollView {
self.addSubview(imageView)
let urlString: String = ShrineData.baseURL + imageName
let url = URL(string: urlString)
remoteImageService.fetchImageAndThumbnail(from: url) { (image: UIImage?,
_) -> Void in
remoteImageService.fetchImageAndThumbnail(from: url) { (image: UIImage?, _) -> Void in
DispatchQueue.main.async(execute: {
self.imageView.image = image
self.imageView.setNeedsDisplay()
@ -62,7 +61,7 @@ class ShrineDetailView: UIScrollView {
let attrString = NSMutableAttributedString(string: title)
attrString.addAttribute(NSParagraphStyleAttributeName,
value:paragraphStyle,
range:NSMakeRange(0, attrString.length))
range: NSRange(location: 0, length:attrString.length))
label.attributedText = attrString
label.sizeToFit()
label.frame = CGRect(x: labelPadding,
@ -79,7 +78,7 @@ class ShrineDetailView: UIScrollView {
let descAttrString = NSMutableAttributedString(string: desc)
descAttrString.addAttribute(NSParagraphStyleAttributeName,
value:descParagraphStyle,
range:NSMakeRange(0, descAttrString.length))
range:NSRange(location: 0, length: descAttrString.length))
labelDesc.attributedText = descAttrString
labelDesc.frame = CGRect(x: labelPadding,
y: 360, width: self.frame.size.width - 2 * labelPadding, height: 160)
@ -137,9 +136,9 @@ class ShrineDetailViewController: UIViewController {
override func viewWillLayoutSubviews() {
floatingButton.frame = CGRect(x: view.frame.width - floatingButton.frame.width - fabPadding,
y: view.frame.height - floatingButton.frame.height - fabPadding,
width: floatingButton.frame.width,
height: floatingButton.frame.height)
y: view.frame.height - floatingButton.frame.height - fabPadding,
width: floatingButton.frame.width,
height: floatingButton.frame.height)
}
func dismissDetails() {

View File

@ -22,7 +22,10 @@ class ShrineFlexibleHeaderContainerViewController: MDCFlexibleHeaderContainerVie
init() {
let layout = UICollectionViewFlowLayout()
let sectionInset: CGFloat = 10.0
layout.sectionInset = UIEdgeInsets(top: sectionInset, left: sectionInset, bottom: sectionInset, right: sectionInset)
layout.sectionInset = UIEdgeInsets(top: sectionInset,
left: sectionInset,
bottom: sectionInset,
right: sectionInset)
let collectionVC = ShrineCollectionViewController(collectionViewLayout: layout)
super.init(contentViewController: collectionVC)

View File

@ -98,8 +98,7 @@ class ShrineHeaderContentView: UIView, UIScrollViewDelegate {
imageView.autoresizingMask = .flexibleHeight
(page as AnyObject).addSubview(imageView)
let url = URL(string: ShrineData.baseURL + imageName)
remoteImageService.fetchImageAndThumbnail(from: url) { (image: UIImage?,
_) -> Void in
remoteImageService.fetchImageAndThumbnail(from: url) { (image: UIImage?, _) -> Void in
DispatchQueue.main.async(execute: {
imageView.image = image
imageView.setNeedsDisplay()

View File

@ -19,3 +19,4 @@ readonly ROOT_DIR="$SCRIPTS_DIR/.."
readonly OBJC_SOURCES=$(find "$ROOT_DIR"/components \( -name '*.h' -or -name '*.m' \))
clang-format -style=file -i $OBJC_SOURCES
swiftlint autocorrect

View File

@ -1,5 +0,0 @@
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

24
scripts/lint_all Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
#
# Copyright 2016-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.
readonly SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly ROOT_DIR="$SCRIPTS_DIR/.."
if which swiftlint >/dev/null; then
swiftlint lint --path "$ROOT_DIR" --quiet
else
echo "warning: run scripts/install_contributor_tools to enable SwiftLint warnings."
fi