Commit 3113d815 by Daniel Dahan

development: added MenuController project and updated Snackbar project to SnackbarController

parent e4e0ffd7
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
location = "group:Programmatic/NavigationController/NavigationController.xcodeproj"> location = "group:Programmatic/NavigationController/NavigationController.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Programmatic/Snackbar/Snackbar.xcodeproj"> location = "group:Programmatic/SnackbarController/SnackbarController.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/MenuController/MenuController.xcodeproj">
</FileRef> </FileRef>
</Group> </Group>
<Group <Group
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "self:Snackbar.xcodeproj"> location = "self:MenuController.xcodeproj">
</FileRef> </FileRef>
</Workspace> </Workspace>
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationDidFinishLaunching(_ application: UIApplication) {
window = UIWindow(frame: Device.bounds)
window!.rootViewController = AppMenuController(rootViewController: RootViewController())
window!.makeKeyAndVisible()
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class AppMenuController: MenuController {
/// Menu diameter.
private let baseSize = CGSize(width: 56, height: 56)
/// Menu bottom inset.
private let bottomInset: CGFloat = 24
/// Menu right inset.
private let rightInset: CGFloat = 24
/// Reference if the menu is hidden.
private(set) var isMenuHidden = false
open override func prepare() {
super.prepare()
view.backgroundColor = Color.black
prepareMenu()
}
open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
closeMenu()
}
open override func openMenu(completion: ((UIView) -> Void)? = nil) {
super.openMenu(completion: completion)
menu.views.first?.animate(animation: Animation.rotate(angle: 45))
}
open override func closeMenu(completion: ((UIView) -> Void)? = nil) {
super.closeMenu(completion: completion)
menu.views.first?.animate(animation: Animation.rotate(angle: 0))
}
/// Shows the menu.
func showMenu() {
guard isMenuHidden else {
return
}
isMenuHidden = false
menu.animate(animation: Animation.animationGroup(animations: [
Animation.rotate(rotation: 3),
Animation.translateY(translation: 0)
]))
}
/// Hides the menu.
func hideMenu() {
guard !isMenuHidden else {
return
}
isMenuHidden = true
menu.animate(animation: Animation.animationGroup(animations: [
Animation.rotate(rotation: 3),
Animation.translateY(translation: 150)
]))
}
/// Prepares the menuView.
private func prepareMenu() {
menu.isHidden = true
menu.baseSize = baseSize
view.layout(menu)
.size(baseSize)
.bottom(bottomInset)
.right(rightInset)
hideMenu()
Animation.delay(time: 0.5) { [weak self] in
self?.menu.isHidden = false
}
}
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import Material
class RootViewController: UIViewController {
/// A reference to the addButton.
internal var addButton: FabButton!
/// A reference to the audioLibraryMenuItem.
internal var audioLibraryMenuItem: MenuItem!
/// A reference to the reminderMenuItem.
internal var reminderMenuItem: MenuItem!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.grey.lighten5
prepareAddButton()
prepareAudioLibraryButton()
prepareBellButton()
}
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
guard let mc = menuController as? AppMenuController else {
return
}
prepareMenuController()
Animation.delay(time: 1) { [mc = mc] in
mc.showMenu()
}
Animation.delay(time: 5) { [mc = mc] in
mc.hideMenu()
}
}
open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
guard let mc = menuController as? AppMenuController else {
return
}
mc.hideMenu()
}
/// Handle the menu toggle event.
internal func handleToggleMenu(button: Button) {
guard let mc = menuController as? AppMenuController else {
return
}
if mc.menu.isOpened {
mc.closeMenu { (view) in
(view as? MenuItem)?.hideTitleLabel()
}
} else {
mc.openMenu { (view) in
(view as? MenuItem)?.showTitleLabel()
}
}
}
/// Prepares the addButton.
private func prepareAddButton() {
addButton = FabButton(image: Icon.cm.add, tintColor: Color.white)
addButton.backgroundColor = Color.blue.base
}
/// Prepares the audioLibraryButton.
private func prepareAudioLibraryButton() {
audioLibraryMenuItem = MenuItem()
audioLibraryMenuItem.button.image = Icon.cm.audioLibrary
audioLibraryMenuItem.button.backgroundColor = Color.blue.base
audioLibraryMenuItem.title = "Audio Library"
}
/// Prepares the bellButton.
private func prepareBellButton() {
reminderMenuItem = MenuItem()
reminderMenuItem.button.image = Icon.cm.bell
reminderMenuItem.button.backgroundColor = Color.blue.base
reminderMenuItem.title = "Reminders"
}
/// Prepares the menuController.
private func prepareMenuController() {
guard let mc = menuController as? AppMenuController else {
return
}
mc.menu.delegate = self
mc.menu.views = [addButton, reminderMenuItem, audioLibraryMenuItem]
addToggleHandler(button: addButton)
}
/// Adds the menuController toggle handlers.
private func addToggleHandler(button: Button) {
button.removeTarget(self, action: #selector(handleToggleMenu), for: .touchUpInside)
button.addTarget(self, action: #selector(handleToggleMenu), for: .touchUpInside)
}
}
/// MenuDelegate.
extension RootViewController: MenuDelegate {
func menu(menu: Menu, tappedAt point: CGPoint, isOutside: Bool) {
guard isOutside else {
return
}
guard let mc = menuController as? AppMenuController else {
return
}
mc.closeMenu { (view) in
(view as? MenuItem)?.hideTitleLabel()
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:SnackbarController.xcodeproj">
</FileRef>
</Workspace>
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
...@@ -38,30 +38,26 @@ class RootViewController: UIViewController { ...@@ -38,30 +38,26 @@ class RootViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = Color.lightBlue.base view.backgroundColor = Color.lightBlue.base
prepareUndoButton()
} }
override func viewWillAppear(_ animated: Bool) { open override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewDidAppear(animated)
guard let mc = menuController as? AppMenuController else {
return
}
prepareSnackbar() prepareMenuController()
animateSnackbar()
} mc.showMenu()
private func prepareUndoButton() {
undoButton = FlatButton(title: "Undo", titleColor: Color.yellow.base)
undoButton.pulseColor = Color.white
}
private func prepareSnackbar() {
snackbarController?.snackbar.text = "Message saved."
snackbarController?.snackbar.rightViews = [undoButton]
} }
private func animateSnackbar() { open override func viewWillDisappear(_ animated: Bool) {
_ = snackbarController?.animate(snackbar: .visible, delay: 1) super.viewWillDisappear(animated)
_ = snackbarController?.animate(snackbar: .hidden, delay: 4) guard let mc = menuController as? AppMenuController else {
return
}
mc.hideMenu()
} }
} }
...@@ -30,6 +30,25 @@ ...@@ -30,6 +30,25 @@
967A48191D0F425A00B8CEB7 /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967A48181D0F425A00B8CEB7 /* StatusBarController.swift */; }; 967A48191D0F425A00B8CEB7 /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967A48181D0F425A00B8CEB7 /* StatusBarController.swift */; };
96815B381CA07BA20006CBE2 /* MaterialViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */; }; 96815B381CA07BA20006CBE2 /* MaterialViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */; };
968C99471D377849000074FF /* Offset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 968C99461D377849000074FF /* Offset.swift */; }; 968C99471D377849000074FF /* Offset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 968C99461D377849000074FF /* Offset.swift */; };
9697F7B71D8F22A4004741EC /* MenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9697F7B61D8F22A4004741EC /* MenuItem.swift */; };
9697F7BC1D8F2572004741EC /* BasicAnimation.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96E3C39D1D3A1D0C0086A024 /* BasicAnimation.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7BD1D8F2572004741EC /* ContentCard.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96264C111D840B5F00576F37 /* ContentCard.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7BE1D8F2572004741EC /* Checkbox.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96264C0D1D84051900576F37 /* Checkbox.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7BF1D8F2572004741EC /* Divider.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96230AB71D6A520C00AF47DC /* Divider.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C01D8F2572004741EC /* Material+CALayer.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96F1DC871D654FDF0025F925 /* Material+CALayer.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C11D8F2572004741EC /* Material+Array.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96C1C8801D42C62800E6608F /* Material+Array.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C21D8F2572004741EC /* Material+UIWindow.swift in Headers */ = {isa = PBXBuildFile; fileRef = 962864591D53FE3E00690B69 /* Material+UIWindow.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C31D8F2572004741EC /* DynamicFontType.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9628645E1D540AF300690B69 /* DynamicFontType.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C41D8F2572004741EC /* JSON.swift in Headers */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C51D8F2573004741EC /* MenuItem.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9697F7B61D8F22A4004741EC /* MenuItem.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C61D8F2573004741EC /* PageTabBarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 963FBF071D669D14008F8512 /* PageTabBarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C71D8F2573004741EC /* PhotoLibrary.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96EA9A421D4E68F80052C74D /* PhotoLibrary.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C81D8F2573004741EC /* PhotoLibraryController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96EA9A4A1D4E7A430052C74D /* PhotoLibraryController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7C91D8F2573004741EC /* Reminders.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96264BE61D833D2800576F37 /* Reminders.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7CA1D8F2573004741EC /* RemindersController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96264BE81D833D3400576F37 /* RemindersController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7CB1D8F2573004741EC /* Snackbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 963FBEFC1D669510008F8512 /* Snackbar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7CC1D8F2573004741EC /* SnackbarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961EFC571D738FF600E84652 /* SnackbarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9697F7CD1D8F2582004741EC /* Color.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9661222D1D3EC414008BB4CB /* Color.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB7A11CB40DC500C806FE /* BottomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */; }; 96BCB7A11CB40DC500C806FE /* BottomNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */; };
96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */; }; 96BCB7A21CB40DC500C806FE /* BottomTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */; };
96BCB7A31CB40DC500C806FE /* CapturePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */; }; 96BCB7A31CB40DC500C806FE /* CapturePreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */; };
...@@ -226,6 +245,7 @@ ...@@ -226,6 +245,7 @@
967887881C9777CB0037F6C9 /* MaterialViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewTests.swift; sourceTree = "<group>"; }; 967887881C9777CB0037F6C9 /* MaterialViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialViewTests.swift; sourceTree = "<group>"; };
967A48181D0F425A00B8CEB7 /* StatusBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; }; 967A48181D0F425A00B8CEB7 /* StatusBarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
968C99461D377849000074FF /* Offset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Offset.swift; sourceTree = "<group>"; }; 968C99461D377849000074FF /* Offset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Offset.swift; sourceTree = "<group>"; };
9697F7B61D8F22A4004741EC /* MenuItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuItem.swift; sourceTree = "<group>"; };
96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomNavigationController.swift; sourceTree = "<group>"; }; 96BCB7581CB40DC500C806FE /* BottomNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomNavigationController.swift; sourceTree = "<group>"; };
96BCB7591CB40DC500C806FE /* BottomTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomTabBar.swift; sourceTree = "<group>"; }; 96BCB7591CB40DC500C806FE /* BottomTabBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BottomTabBar.swift; sourceTree = "<group>"; };
96BCB75A1CB40DC500C806FE /* CapturePreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreview.swift; sourceTree = "<group>"; }; 96BCB75A1CB40DC500C806FE /* CapturePreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreview.swift; sourceTree = "<group>"; };
...@@ -466,6 +486,7 @@ ...@@ -466,6 +486,7 @@
children = ( children = (
96BCB78E1CB40DC500C806FE /* Menu.swift */, 96BCB78E1CB40DC500C806FE /* Menu.swift */,
96BCB78F1CB40DC500C806FE /* MenuController.swift */, 96BCB78F1CB40DC500C806FE /* MenuController.swift */,
9697F7B61D8F22A4004741EC /* MenuItem.swift */,
); );
name = Menu; name = Menu;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -870,6 +891,23 @@ ...@@ -870,6 +891,23 @@
96E3C3991D3A1CC20086A024 /* StatusBarController.swift in Headers */, 96E3C3991D3A1CC20086A024 /* StatusBarController.swift in Headers */,
96E3C39A1D3A1CC20086A024 /* ErrorTextField.swift in Headers */, 96E3C39A1D3A1CC20086A024 /* ErrorTextField.swift in Headers */,
96E3C39C1D3A1CC20086A024 /* Offset.swift in Headers */, 96E3C39C1D3A1CC20086A024 /* Offset.swift in Headers */,
9697F7BC1D8F2572004741EC /* BasicAnimation.swift in Headers */,
9697F7BD1D8F2572004741EC /* ContentCard.swift in Headers */,
9697F7BE1D8F2572004741EC /* Checkbox.swift in Headers */,
9697F7BF1D8F2572004741EC /* Divider.swift in Headers */,
9697F7C01D8F2572004741EC /* Material+CALayer.swift in Headers */,
9697F7C11D8F2572004741EC /* Material+Array.swift in Headers */,
9697F7C21D8F2572004741EC /* Material+UIWindow.swift in Headers */,
9697F7C31D8F2572004741EC /* DynamicFontType.swift in Headers */,
9697F7C41D8F2572004741EC /* JSON.swift in Headers */,
9697F7C51D8F2573004741EC /* MenuItem.swift in Headers */,
9697F7C61D8F2573004741EC /* PageTabBarController.swift in Headers */,
9697F7C71D8F2573004741EC /* PhotoLibrary.swift in Headers */,
9697F7C81D8F2573004741EC /* PhotoLibraryController.swift in Headers */,
9697F7C91D8F2573004741EC /* Reminders.swift in Headers */,
9697F7CA1D8F2573004741EC /* RemindersController.swift in Headers */,
9697F7CB1D8F2573004741EC /* Snackbar.swift in Headers */,
9697F7CC1D8F2573004741EC /* SnackbarController.swift in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -878,6 +916,7 @@ ...@@ -878,6 +916,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9660162A1CB2F04E00AAB661 /* Material.h in Headers */, 9660162A1CB2F04E00AAB661 /* Material.h in Headers */,
9697F7CD1D8F2582004741EC /* Color.swift in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -1144,6 +1183,7 @@ ...@@ -1144,6 +1183,7 @@
96BCB7AB1CB40DC500C806FE /* ImageCard.swift in Sources */, 96BCB7AB1CB40DC500C806FE /* ImageCard.swift in Sources */,
96BCB7CB1CB40DC500C806FE /* PulseAnimation.swift in Sources */, 96BCB7CB1CB40DC500C806FE /* PulseAnimation.swift in Sources */,
96BCB7AE1CB40DC500C806FE /* Material+UIFont.swift in Sources */, 96BCB7AE1CB40DC500C806FE /* Material+UIFont.swift in Sources */,
9697F7B71D8F22A4004741EC /* MenuItem.swift in Sources */,
96BCB7D91CB40DC500C806FE /* NavigationBar.swift in Sources */, 96BCB7D91CB40DC500C806FE /* NavigationBar.swift in Sources */,
96264C0E1D84051900576F37 /* Checkbox.swift in Sources */, 96264C0E1D84051900576F37 /* Checkbox.swift in Sources */,
); );
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
open class MenuItem: View {
/// A reference to the titleLabel.
open private(set) lazy var titleLabel = UILabel()
/// A reference to the button.
open private(set) lazy var button: FabButton = FabButton()
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
backgroundColor = nil
prepareButton()
prepareTitleLabel()
}
/// A reference to the titleLabel text.
open var title: String? {
get {
return titleLabel.text
}
set(value) {
titleLabel.text = value
hideTitleLabel()
}
}
/// Shows the titleLabel.
open func showTitleLabel() {
let interimSpace = InterimSpacePresetToValue(preset: .interimSpace6)
titleLabel.sizeToFit()
titleLabel.width += 1.5 * interimSpace
titleLabel.height += interimSpace / 2
titleLabel.y = (height - titleLabel.height) / 2
titleLabel.x = -titleLabel.width - interimSpace
titleLabel.alpha = 0
titleLabel.isHidden = false
UIView.animate(withDuration: 0.25, animations: { [weak self] in
guard let s = self else {
return
}
s.titleLabel.alpha = 1
})
}
/// Hides the titleLabel.
open func hideTitleLabel() {
titleLabel.isHidden = true
}
/// Prepares the button.
private func prepareButton() {
layout(button).edges()
}
/// Prepares the titleLabel.
private func prepareTitleLabel() {
titleLabel.font = RobotoFont.regular(with: 14)
titleLabel.textAlignment = .center
titleLabel.backgroundColor = Color.white
titleLabel.depthPreset = button.depthPreset
titleLabel.cornerRadiusPreset = .cornerRadius1
titleLabel.shapePreset = .none
titleLabel.clipsToBounds = true
addSubview(titleLabel)
}
}
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