Skip to content

Commit f1e6a3d

Browse files
kul3r4jgunaratne
authored andcommitted
Shrine refactor header page into it's own file (#1157)
* Extracts header code into method removing repetition * [AppBar] Header stack view in AppBarController (#1121) Since the header stack view is going to be laid out with auto layout, it should be inited with a CGRectZero. Doing it with self.view.bounds creates a tiny loop since the view is not loaded yet. * [ThumbTrack] Remove extra UIColor categories (#1122) * Pull the functionality of UIColor+MDC into MDCThumbTrack. MDCThumbTrack is now the only class using this behaviour, so three extra files have been removed now that they are no longer necessary. * Fixed colon alignment. * [Ink] Add nonnull to the MDCInkTouchController initializer (#1123) * Specify `nonnull` on the MDCInkTouchController initializer. This is a quick change since the initializer was never returning nil to begin with. * Update Shrine to use the nonnull MDCInkTouchController initializer. * Formatted all Objective-C sources with clang-format. (#1133) * [Scripts] Add scripts for "prepping" and cleaning the library/catalog/demo apps. (#1130) * Changed build_all to echo the xcodebuild command it is executing. * Added a clean_all script. * Added a prep_all script. * Updated README.md with new scripts. * Change Travis CI to use the new `prep_all` script. * Added a script to format Objective-C sources with clang-format. (#1132) * Added comment about Travis CI's 10.1 device bug. (#1135) * Removed the private/Color subspec. (#1128) * [Catalog] Center views in the Buttons (Swift and Storyboard) demo (#1126) * Center the Storyboard button demo. This uses an outer container to set up a view which is 50% the screen width (to allow for the other half of the button demo), and then an inner container to vertically and horizontally center the buttons. * Center the buttons added programatically. * Weakify strongify asynchronously dispatched snackbar view dismissal (#1136) * Update the button’s custom title color when the tint color changes. (#1134) * Add travis_wait prefixes on long-running commands. * Render Snackbar labels correctly for RTL (#1137) * Change the MDCInteractionTest deployment target to 8.0. (#1131) * Turn `inkController` into a lazy var. (#1139) This removes the need for storing it as an optional. * [ProgressView] Backward animation support (#1138) * Add backward progress animation mode support. This allows users to animate the progress view backward if they are giving it progress which is lesser than the current value. * Demonstrate the backward progress animation support. * Update the assets for the progress view. * Change ProgressViewExample with new enum name. * Updated enum names. * Update with new enum names. * Added script to install SwiftLint. (#1143) * Ran scripts/format_all. (#1141) * [Scripts] SwiftLint integration (#1129) * Integrate SwiftLint in the Catalog. * Update the disabled SwiftLint rules. * Reference a local swiftlint.yml symlink. This prevents us from getting warnings about code style violations from the other demos. * Fix SwiftLint violations in the Catalog and Components. * Ignore the `third_party` directory when running the linter. We should not have to deal with warnings in code we may not be able to fix easily. * Integrate SwiftLint into Shrine. Additionally, fix a number of warnings introduced. * Run SwiftLint on Travis. * Enable many of the previously disabled rules and correct them. * Fix control statement violations from SwiftLint. * Update README.md * Ignore "error" from already-installed brew packages. * [FlexibleHeader] - Update tests so as not to have 0 in contentSize (#1146) * Fixed broken links to versions.md. * Added component changes to CHANGELOG.md. * Added API diff, determined new version number is 20.0.0. * Bumped version number to 20.0.0. * Tell `brew install` to stop failing if swiftlint is already installed. * Changed clean script to force-clean Xcode projects. (#1144) * Fix SwiftLint warnings (#1149) * Exclude catalog/third_party from SwiftLint. * Added line length to .swiftlint.yml * Fixed SwiftLint warnings with some minor refactors. * Install SwiftLint via the install_contributor_tools script. (#1145) * Install SwiftLint via the install_contributor_tools script. * Exclude catalog/third_party from SwiftLint. * Added line length to .swiftlint.yml * Fixed SwiftLint warnings with some minor refactors. * Revert "Fixed SwiftLint warnings with some minor refactors." This reverts commit 2c19802. * Revert "Added line length to .swiftlint.yml" This reverts commit 12a6781. * Revert "Exclude catalog/third_party from SwiftLint." This reverts commit 8a00ad8. * [Collections] Added custom Storyboard cell to the Storyboard example. (#1152) * [Feature highlight] Dynamically size inner highlight (#1151) * Use instance based inner radius * Warning re ios sim * Scale outer highlight to encircle inner highlight * Dont scale innerhighlight pulsing with inner highlight size * Reset highlight example supplemental: * Build fix: CGFloat casts missing from MDCFeatureHighlightView.m. * 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. * [Snackbar] Message View Styling. (#1120) * Snackbar Message View Styling. * Small alteration to how colors are generated for the unit tests. * Not styling the snack bar in the init method. * Default styling for background views. * Remove overriding the styling in init. * Looks like swiftlint is already installed by default on travis-ci boxes. Trying this as an experiment. * Trying this? * Cant get unit tests to pass as there’s no window to add the message view to with logic tests. * Fixed Shrine compilation. * [AppBar] - Added Modal Presentation App Bar Example (#1153) * ModalAppBar - Added additional AppBar example to display modal AppBar vc example * ModalAppBar - Added swift modal example * ModalAppBar - Updated naming * ModalAppBar - Updated swift example * ModalAppBar - Indentions and removed setting nil to title property * Moves the initialization of the header page into separate file * Moves the initialization of the header page into separate file
1 parent ebef419 commit f1e6a3d

File tree

4 files changed

+107
-71
lines changed

4 files changed

+107
-71
lines changed

demos/Shrine/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ DEPENDENCIES:
4545

4646
EXTERNAL SOURCES:
4747
MaterialComponents:
48-
:path: "../../"
48+
:path: ../../
4949
RemoteImageServiceForMDCDemos:
50-
:path: "../supplemental"
50+
:path: ../supplemental
5151

5252
SPEC CHECKSUMS:
5353
MaterialComponents: cd8bd56c35bcba349631d762dd5219108324f4e8

demos/Shrine/Shrine.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
6B0C01BA37AC5D6B39F49F16 /* Pods_Shrine.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E79DB3BB3A6DCA8E56C685D /* Pods_Shrine.framework */; };
11+
CBAF7A311E1577380022A08F /* ShrineHeaderPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBAF7A301E1577380022A08F /* ShrineHeaderPage.swift */; };
1112
DE064E731C83D20E00B17776 /* ShrineFlexibleHeaderContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE064E721C83D20E00B17776 /* ShrineFlexibleHeaderContainerViewController.swift */; };
1213
DE34DEBB1C88E90000E04B65 /* ShrineInkOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE34DEBA1C88E90000E04B65 /* ShrineInkOverlay.swift */; };
1314
DE34DEBF1C8A34B100E04B65 /* ShrineHeaderContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE34DEBE1C8A34B100E04B65 /* ShrineHeaderContentView.swift */; };
@@ -27,6 +28,7 @@
2728
1C7F50E40E35B48C29C884F8 /* Pods-Shrine.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Shrine.release.xcconfig"; path = "Pods/Target Support Files/Pods-Shrine/Pods-Shrine.release.xcconfig"; sourceTree = "<group>"; };
2829
2E79DB3BB3A6DCA8E56C685D /* Pods_Shrine.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Shrine.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2930
3D22DA7C0F576B707C1CA5BE /* Pods-Shrine.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Shrine.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Shrine/Pods-Shrine.debug.xcconfig"; sourceTree = "<group>"; };
31+
CBAF7A301E1577380022A08F /* ShrineHeaderPage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShrineHeaderPage.swift; sourceTree = "<group>"; };
3032
DE064E721C83D20E00B17776 /* ShrineFlexibleHeaderContainerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShrineFlexibleHeaderContainerViewController.swift; sourceTree = "<group>"; };
3133
DE34DEBA1C88E90000E04B65 /* ShrineInkOverlay.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShrineInkOverlay.swift; sourceTree = "<group>"; };
3234
DE34DEBE1C8A34B100E04B65 /* ShrineHeaderContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShrineHeaderContentView.swift; sourceTree = "<group>"; };
@@ -109,6 +111,7 @@
109111
DE064E721C83D20E00B17776 /* ShrineFlexibleHeaderContainerViewController.swift */,
110112
DE34DEBE1C8A34B100E04B65 /* ShrineHeaderContentView.swift */,
111113
DE34DEBA1C88E90000E04B65 /* ShrineInkOverlay.swift */,
114+
CBAF7A301E1577380022A08F /* ShrineHeaderPage.swift */,
112115
);
113116
path = Shrine;
114117
sourceTree = "<group>";
@@ -268,6 +271,7 @@
268271
DE5D2A481C81068100C9C650 /* AppDelegate.swift in Sources */,
269272
DE5D2A5C1C810E6600C9C650 /* ShrineCollectionViewController.swift in Sources */,
270273
DE34DEBF1C8A34B100E04B65 /* ShrineHeaderContentView.swift in Sources */,
274+
CBAF7A311E1577380022A08F /* ShrineHeaderPage.swift in Sources */,
271275
DE064E731C83D20E00B17776 /* ShrineFlexibleHeaderContainerViewController.swift in Sources */,
272276
DE6887F31C84FCD40074A8C5 /* ShrineData.swift in Sources */,
273277
DE34DEBB1C88E90000E04B65 /* ShrineInkOverlay.swift in Sources */,

demos/Shrine/Shrine/ShrineHeaderContentView.swift

Lines changed: 5 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,9 @@
1616

1717
import UIKit
1818
import MaterialComponents.MaterialPageControl
19-
import RemoteImageServiceForMDCDemos
2019

2120
class ShrineHeaderContentView: UIView, UIScrollViewDelegate {
2221

23-
let fontAbril = UIFont(name: "AbrilFatface-Regular", size: 36)
24-
let fontHelvetica = UIFont(name: "Helvetica", size: 14)
25-
let textColor = UIColor(red: 10 / 255, green: 49 / 255, blue: 66 / 255, alpha: 1)
26-
let cyanBoxColor = UIColor(red: 0.19, green: 0.94, blue: 0.94, alpha: 1)
27-
let descColor = UIColor(white: 0.54, alpha: 1)
28-
let descString = "Leave the tunnel and the rain is fallin amazing things happen when you wait"
29-
30-
var remoteImageService = RemoteImageService()
31-
3222
var pageControl = MDCPageControl()
3323
var scrollView = UIScrollView()
3424
var logoImageView = UIImageView(image: UIImage(named: "ShrineLogo"))
@@ -87,60 +77,15 @@ class ShrineHeaderContentView: UIView, UIScrollViewDelegate {
8777
for: UIControlEvents.valueChanged)
8878
self.addSubview(pageControl)
8979

90-
addPageContent()
80+
addHeaderPages()
9181
self.addSubview(logoImageView)
9282
self.addSubview(logoTextImageView)
9383
}
9484

95-
func addPage(page: UIView, imageView: UIImageView, label: UILabel, labelDesc: UILabel,
96-
cyanBox: UIView, imageName: String, description: String) {
97-
imageView.contentMode = UIViewContentMode.scaleAspectFill
98-
imageView.autoresizingMask = .flexibleHeight
99-
(page as AnyObject).addSubview(imageView)
100-
let url = URL(string: ShrineData.baseURL + imageName)
101-
remoteImageService.fetchImageAndThumbnail(from: url) { (image: UIImage?, _) -> Void in
102-
DispatchQueue.main.async(execute: {
103-
imageView.image = image
104-
imageView.setNeedsDisplay()
105-
})
106-
}
107-
108-
label.font = fontAbril
109-
label.textColor = textColor
110-
label.lineBreakMode = .byWordWrapping
111-
label.numberOfLines = 2
112-
label.attributedText = attributedString(description, lineHeightMultiple: 0.8)
113-
label.sizeToFit()
114-
(page as AnyObject).addSubview(label)
115-
116-
labelDesc.lineBreakMode = .byWordWrapping
117-
labelDesc.numberOfLines = 3
118-
labelDesc.font = fontHelvetica
119-
labelDesc.textColor = descColor
120-
labelDesc.attributedText = attributedString(descString, lineHeightMultiple: 1.2)
121-
labelDesc.autoresizingMask = .flexibleWidth
122-
(page as AnyObject).addSubview(labelDesc)
123-
124-
cyanBox.backgroundColor = cyanBoxColor
125-
(page as AnyObject).addSubview(cyanBox)
126-
127-
let inkOverlay = ShrineInkOverlay(frame: (page as AnyObject).bounds)
128-
inkOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
129-
(page as AnyObject).addSubview(inkOverlay)
130-
131-
}
132-
133-
func addPageContent() {
134-
let firstPage = pages[0]
135-
let secondPage = pages[1]
136-
let thirdPage = pages[2]
137-
138-
addPage(page: firstPage as! UIView, imageView: imageView, label: label, labelDesc: labelDesc,
139-
cyanBox: cyanBox, imageName: "chair.png", description: "Green \ncomfort chair")
140-
addPage(page: secondPage as! UIView, imageView: imageView2, label: label2, labelDesc: labelDesc2,
141-
cyanBox: cyanBox2, imageName: "backpack.png", description: "Best gift for \nthe traveler")
142-
addPage(page: thirdPage as! UIView, imageView: imageView3, label: label3, labelDesc: labelDesc3,
143-
cyanBox: cyanBox3, imageName: "heels.png", description: "Better \nwearing heels")
85+
func addHeaderPages() {
86+
_ = ShrineHeaderPage(page: pages[0] as! UIView, imageView: imageView, label: label, labelDesc: labelDesc, cyanBox: cyanBox, imageName: "chair.png", description: "Green \ncomfort chair")
87+
_ = ShrineHeaderPage(page: pages[1] as! UIView, imageView: imageView2, label: label2, labelDesc: labelDesc2, cyanBox: cyanBox2, imageName: "backpack.png", description: "Best gift for \nthe traveler")
88+
_ = ShrineHeaderPage(page: pages[2] as! UIView, imageView: imageView3, label: label3, labelDesc: labelDesc3, cyanBox: cyanBox3, imageName: "heels.png", description: "Better \nwearing heels")
14489
}
14590

14691
override func layoutSubviews() {
@@ -191,15 +136,6 @@ class ShrineHeaderContentView: UIView, UIScrollViewDelegate {
191136
imageView3.frame = CGRect(x: -180, y: 40, width: 420, height: self.frame.size.height)
192137
}
193138

194-
func attributedString(_ string: String, lineHeightMultiple: CGFloat) -> NSMutableAttributedString {
195-
let paragraphStyle = NSMutableParagraphStyle()
196-
paragraphStyle.lineHeightMultiple = lineHeightMultiple
197-
let attrString = NSMutableAttributedString(string: string)
198-
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle,
199-
range:NSMakeRange(0, attrString.length))
200-
return attrString
201-
}
202-
203139
func scrollViewDidScroll(_ scrollView: UIScrollView) {
204140
pageControl.scrollViewDidScroll(scrollView)
205141
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2016-present the Material Components for iOS authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import UIKit
18+
import RemoteImageServiceForMDCDemos
19+
20+
struct ShrineHeaderPage {
21+
22+
let textColor = UIColor(red: 10 / 255, green: 49 / 255, blue: 66 / 255, alpha: 1)
23+
let fontAbril = UIFont(name: "AbrilFatface-Regular", size: 36)
24+
let fontHelvetica = UIFont(name: "Helvetica", size: 14)
25+
let cyanBoxColor = UIColor(red: 0.19, green: 0.94, blue: 0.94, alpha: 1)
26+
let descColor = UIColor(white: 0.54, alpha: 1)
27+
let descString = "Leave the tunnel and the rain is fallin amazing things happen when you wait"
28+
29+
var remoteImageService = RemoteImageService()
30+
31+
var page: UIView
32+
var imageView: UIView
33+
var label: UILabel
34+
var labelDesc: UILabel
35+
var cyanBox: UIView
36+
var imageName: String
37+
var description: String
38+
39+
init(page: UIView, imageView: UIImageView, label: UILabel, labelDesc: UILabel,
40+
cyanBox: UIView, imageName: String, description: String) {
41+
self.page = page
42+
self.imageView = imageView
43+
self.label = label
44+
self.labelDesc = labelDesc
45+
self.cyanBox = cyanBox
46+
self.imageName = imageName
47+
self.description = description
48+
49+
imageView.contentMode = UIViewContentMode.scaleAspectFill
50+
imageView.autoresizingMask = .flexibleHeight
51+
(page as AnyObject).addSubview(imageView)
52+
let url = URL(string: ShrineData.baseURL + imageName)
53+
remoteImageService.fetchImageAndThumbnail(from: url) { (image:UIImage?,
54+
thumbnailImage:UIImage?) -> Void in
55+
DispatchQueue.main.async(execute: {
56+
imageView.image = image;
57+
imageView.setNeedsDisplay()
58+
})
59+
}
60+
61+
label.font = fontAbril
62+
label.textColor = textColor
63+
label.lineBreakMode = .byWordWrapping
64+
label.numberOfLines = 2
65+
label.attributedText = attributedString(description, lineHeightMultiple: 0.8)
66+
label.sizeToFit();
67+
(page as AnyObject).addSubview(label)
68+
69+
labelDesc.lineBreakMode = .byWordWrapping
70+
labelDesc.numberOfLines = 3
71+
labelDesc.font = fontHelvetica
72+
labelDesc.textColor = descColor
73+
labelDesc.attributedText = attributedString(descString, lineHeightMultiple: 1.2)
74+
labelDesc.autoresizingMask = .flexibleWidth
75+
(page as AnyObject).addSubview(labelDesc)
76+
77+
cyanBox.backgroundColor = cyanBoxColor
78+
(page as AnyObject).addSubview(cyanBox)
79+
80+
let inkOverlay = ShrineInkOverlay(frame: (page as AnyObject).bounds)
81+
inkOverlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
82+
(page as AnyObject).addSubview(inkOverlay)
83+
84+
}
85+
86+
func attributedString(_ string: String, lineHeightMultiple: CGFloat) -> NSMutableAttributedString {
87+
let paragraphStyle = NSMutableParagraphStyle()
88+
paragraphStyle.lineHeightMultiple = lineHeightMultiple
89+
let attrString = NSMutableAttributedString(string: string)
90+
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle,
91+
range:NSMakeRange(0, attrString.length))
92+
return attrString
93+
}
94+
95+
96+
}

0 commit comments

Comments
 (0)