Commit 4fd30c70 by Daniel Dahan

development: divided Device into Application, Device, and Screen to expand their APIs

parent f9d43a00
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
961E6BDF1DDA2A95004E6C93 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BDE1DDA2A95004E6C93 /* Application.swift */; };
961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961E6BE11DDA2AF3004E6C93 /* Screen.swift */; };
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; }; 96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; }; 963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
965E80C81DD4C50600D61E4B /* Motion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76D1CB40DC500C806FE /* Motion.swift */; }; 965E80C81DD4C50600D61E4B /* Motion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB76D1CB40DC500C806FE /* Motion.swift */; };
...@@ -198,6 +200,8 @@ ...@@ -198,6 +200,8 @@
961276621DCD8B1800A7D920 /* CharacterAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterAttribute.swift; sourceTree = "<group>"; }; 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterAttribute.swift; sourceTree = "<group>"; };
961DED451DCC40C500F425B6 /* Editor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Editor.swift; sourceTree = "<group>"; }; 961DED451DCC40C500F425B6 /* Editor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Editor.swift; sourceTree = "<group>"; };
961DED4A1DCC546100F425B6 /* EditorController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorController.swift; sourceTree = "<group>"; }; 961DED4A1DCC546100F425B6 /* EditorController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorController.swift; sourceTree = "<group>"; };
961E6BDE1DDA2A95004E6C93 /* Application.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; };
961E6BE11DDA2AF3004E6C93 /* Screen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = "<group>"; };
961EFC571D738FF600E84652 /* SnackbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnackbarController.swift; sourceTree = "<group>"; }; 961EFC571D738FF600E84652 /* SnackbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnackbarController.swift; sourceTree = "<group>"; };
961F18E71CD93E3E008927C5 /* ErrorTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTextField.swift; sourceTree = "<group>"; }; 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTextField.swift; sourceTree = "<group>"; };
96230AB71D6A520C00AF47DC /* Divider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Divider.swift; sourceTree = "<group>"; }; 96230AB71D6A520C00AF47DC /* Divider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Divider.swift; sourceTree = "<group>"; };
...@@ -357,6 +361,22 @@ ...@@ -357,6 +361,22 @@
name = Editor; name = Editor;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
961E6BDD1DDA2A7E004E6C93 /* Application */ = {
isa = PBXGroup;
children = (
961E6BDE1DDA2A95004E6C93 /* Application.swift */,
);
name = Application;
sourceTree = "<group>";
};
961E6BE01DDA2ADD004E6C93 /* Screen */ = {
isa = PBXGroup;
children = (
961E6BE11DDA2AF3004E6C93 /* Screen.swift */,
);
name = Screen;
sourceTree = "<group>";
};
96230AB61D6A51FD00AF47DC /* Divider */ = { 96230AB61D6A51FD00AF47DC /* Divider */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -543,7 +563,7 @@ ...@@ -543,7 +563,7 @@
96BCB7571CB40DC500C806FE /* iOS */ = { 96BCB7571CB40DC500C806FE /* iOS */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB8091CB4107700C806FE /* Motion */, 961E6BDD1DDA2A7E004E6C93 /* Application */,
96264BE41D833C8400576F37 /* Bar */, 96264BE41D833C8400576F37 /* Bar */,
962DDD081D6FBBD0001C307C /* BottomTabBar */, 962DDD081D6FBBD0001C307C /* BottomTabBar */,
96BCB8031CB40F4B00C806FE /* Button */, 96BCB8031CB40F4B00C806FE /* Button */,
...@@ -562,10 +582,12 @@ ...@@ -562,10 +582,12 @@
96BCB80D1CB410FD00C806FE /* Layer */, 96BCB80D1CB410FD00C806FE /* Layer */,
96BCB8041CB40F6C00C806FE /* Layout */, 96BCB8041CB40F6C00C806FE /* Layout */,
963FBF021D6696D0008F8512 /* Menu */, 963FBF021D6696D0008F8512 /* Menu */,
96BCB8091CB4107700C806FE /* Motion */,
96BCB8011CB40F1700C806FE /* Navigation */, 96BCB8011CB40F1700C806FE /* Navigation */,
962DDD071D6FBBB7001C307C /* Page */, 962DDD071D6FBBB7001C307C /* Page */,
96717B151DBE6B1800DA84DB /* Photos */, 96717B151DBE6B1800DA84DB /* Photos */,
9626CA951DAB5370003E2611 /* Root */, 9626CA951DAB5370003E2611 /* Root */,
961E6BE01DDA2ADD004E6C93 /* Screen */,
963FBF031D6696EF008F8512 /* SearchBar */, 963FBF031D6696EF008F8512 /* SearchBar */,
963FBEFB1D6694E8008F8512 /* Snackbar */, 963FBEFB1D6694E8008F8512 /* Snackbar */,
967A48171D0F424B00B8CEB7 /* StatusBar */, 967A48171D0F424B00B8CEB7 /* StatusBar */,
...@@ -1040,6 +1062,7 @@ ...@@ -1040,6 +1062,7 @@
965E81231DD4D7C800D61E4B /* BottomTabBar.swift in Sources */, 965E81231DD4D7C800D61E4B /* BottomTabBar.swift in Sources */,
965E81241DD4D7C800D61E4B /* Editor.swift in Sources */, 965E81241DD4D7C800D61E4B /* Editor.swift in Sources */,
965E81251DD4D7C800D61E4B /* EditorController.swift in Sources */, 965E81251DD4D7C800D61E4B /* EditorController.swift in Sources */,
961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */,
965E81261DD4D7C800D61E4B /* CharacterAttribute.swift in Sources */, 965E81261DD4D7C800D61E4B /* CharacterAttribute.swift in Sources */,
965E80FF1DD4D5C800D61E4B /* BottomNavigationController.swift in Sources */, 965E80FF1DD4D5C800D61E4B /* BottomNavigationController.swift in Sources */,
965E81001DD4D5C800D61E4B /* Capture.swift in Sources */, 965E81001DD4D5C800D61E4B /* Capture.swift in Sources */,
...@@ -1107,6 +1130,7 @@ ...@@ -1107,6 +1130,7 @@
965E80D41DD4C50600D61E4B /* Divider.swift in Sources */, 965E80D41DD4C50600D61E4B /* Divider.swift in Sources */,
965E80D51DD4C50600D61E4B /* Grid.swift in Sources */, 965E80D51DD4C50600D61E4B /* Grid.swift in Sources */,
965E80D61DD4C50600D61E4B /* HeightPreset.swift in Sources */, 965E80D61DD4C50600D61E4B /* HeightPreset.swift in Sources */,
961E6BDF1DDA2A95004E6C93 /* Application.swift in Sources */,
965E80D71DD4C50600D61E4B /* Icon.swift in Sources */, 965E80D71DD4C50600D61E4B /* Icon.swift in Sources */,
965E80FC1DD4D59500D61E4B /* SearchBarController.swift in Sources */, 965E80FC1DD4D59500D61E4B /* SearchBarController.swift in Sources */,
965E80D81DD4C50600D61E4B /* Layer.swift in Sources */, 965E80D81DD4C50600D61E4B /* Layer.swift in Sources */,
......
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* 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
public struct Application {
/// A Boolean indicating if the device is in Landscape mode.
public static var isLandscape: Bool {
return UIApplication.shared.statusBarOrientation.isLandscape
}
/// A Boolean indicating if the device is in Portrait mode.
public static var isPortrait: Bool {
return !isLandscape
}
/// The current UIInterfaceOrientation value.
public static var orientation: UIInterfaceOrientation {
return UIApplication.shared.statusBarOrientation
}
/// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle {
get {
return UIApplication.shared.statusBarStyle
}
set(value) {
UIApplication.shared.statusBarStyle = value
}
}
/// Retrieves the device status bar hidden state.
public static var isStatusBarHidden: Bool {
get {
return UIApplication.shared.isStatusBarHidden
}
set(value) {
UIApplication.shared.isStatusBarHidden = value
}
}
}
...@@ -140,7 +140,7 @@ open class BottomNavigationController: UITabBarController, UITabBarControllerDel ...@@ -140,7 +140,7 @@ open class BottomNavigationController: UITabBarController, UITabBarControllerDel
*/ */
open func prepare() { open func prepare() {
view.clipsToBounds = true view.clipsToBounds = true
view.contentScaleFactor = Device.scale view.contentScaleFactor = Screen.scale
view.backgroundColor = Color.white view.backgroundColor = Color.white
delegate = self delegate = self
prepareTabBar() prepareTabBar()
......
...@@ -127,7 +127,7 @@ open class BottomTabBar: UITabBar { ...@@ -127,7 +127,7 @@ open class BottomTabBar: UITabBar {
heightPreset = .normal heightPreset = .normal
depthPreset = .depth1 depthPreset = .depth1
dividerAlignment = .top dividerAlignment = .top
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
backgroundColor = .white backgroundColor = .white
let image = UIImage.image(with: .clear, size: CGSize(width: 1, height: 1)) let image = UIImage.image(with: .clear, size: CGSize(width: 1, height: 1))
shadowImage = image shadowImage = image
......
...@@ -240,7 +240,7 @@ open class Button: UIButton, Pulseable { ...@@ -240,7 +240,7 @@ open class Button: UIButton, Pulseable {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
prepareVisualLayer() prepareVisualLayer()
preparePulse() preparePulse()
} }
......
...@@ -118,7 +118,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable { ...@@ -118,7 +118,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
/** /**
A floating point value that defines a ratio between the pixel A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the Device.scale. of the view. By default, this value is set to the Screen.scale.
*/ */
@IBInspectable open var contentsScale: CGFloat { @IBInspectable open var contentsScale: CGFloat {
get { get {
...@@ -286,7 +286,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable { ...@@ -286,7 +286,7 @@ open class CollectionReusableView: UICollectionReusableView, Pulseable {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
pulseAnimation = .none pulseAnimation = .none
prepareVisualLayer() prepareVisualLayer()
preparePulse() preparePulse()
......
...@@ -119,7 +119,7 @@ open class CollectionView: UICollectionView { ...@@ -119,7 +119,7 @@ open class CollectionView: UICollectionView {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
backgroundColor = .clear backgroundColor = .clear
contentEdgeInsets = .zero contentEdgeInsets = .zero
} }
......
...@@ -120,7 +120,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable { ...@@ -120,7 +120,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable {
/** /**
A floating point value that defines a ratio between the pixel A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the Device.scale. of the view. By default, this value is set to the Screen.scale.
*/ */
@IBInspectable @IBInspectable
open var contentsScale: CGFloat { open var contentsScale: CGFloat {
...@@ -293,7 +293,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable { ...@@ -293,7 +293,7 @@ open class CollectionViewCell: UICollectionViewCell, Pulseable {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
prepareVisualLayer() prepareVisualLayer()
preparePulse() preparePulse()
} }
......
...@@ -107,59 +107,4 @@ public struct Device { ...@@ -107,59 +107,4 @@ public struct Device {
public static var userInterfaceIdiom: UIUserInterfaceIdiom { public static var userInterfaceIdiom: UIUserInterfaceIdiom {
return UIDevice.current.userInterfaceIdiom return UIDevice.current.userInterfaceIdiom
} }
/// A Boolean indicating if the device is in Landscape mode.
public static var isLandscape: Bool {
return UIApplication.shared.statusBarOrientation.isLandscape
}
/// A Boolean indicating if the device is in Portrait mode.
public static var isPortrait: Bool {
return !isLandscape
}
/// The current UIInterfaceOrientation value.
public static var orientation: UIInterfaceOrientation {
return UIApplication.shared.statusBarOrientation
}
/// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle {
get {
return UIApplication.shared.statusBarStyle
}
set(value) {
UIApplication.shared.statusBarStyle = value
}
}
/// Retrieves the device status bar hidden state.
public static var isStatusBarHidden: Bool {
get {
return UIApplication.shared.isStatusBarHidden
}
set(value) {
UIApplication.shared.isStatusBarHidden = value
}
}
/// Retrieves the device bounds.
public static var bounds: CGRect {
return UIScreen.main.bounds
}
/// Retrieves the device width.
public static var width: CGFloat {
return bounds.width
}
/// Retrieves the device height.
public static var height: CGFloat {
return bounds.height
}
/// Retrieves the device scale.
public static var scale: CGFloat {
return UIScreen.main.scale
}
} }
...@@ -77,7 +77,7 @@ open class Layer: CAShapeLayer { ...@@ -77,7 +77,7 @@ open class Layer: CAShapeLayer {
/** /**
A floating point value that defines a ratio between the pixel A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size dimensions of the visualLayer's contents property and the size
of the layer. By default, this value is set to the Device.scale. of the layer. By default, this value is set to the Screen.scale.
*/ */
@IBInspectable @IBInspectable
open override var contentsScale: CGFloat { open override var contentsScale: CGFloat {
......
...@@ -86,7 +86,7 @@ extension UIImage { ...@@ -86,7 +86,7 @@ extension UIImage {
let g: UIImage? let g: UIImage?
let t: CGRect = CGRect(x: 0, y: 0, width: w ?? tw, height: h ?? th) let t: CGRect = CGRect(x: 0, y: 0, width: w ?? tw, height: h ?? th)
UIGraphicsBeginImageContextWithOptions(t.size, false, Device.scale) UIGraphicsBeginImageContextWithOptions(t.size, false, Screen.scale)
draw(in: t, blendMode: .normal, alpha: 1) draw(in: t, blendMode: .normal, alpha: 1)
g = UIGraphicsGetImageFromCurrentImageContext() g = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext() UIGraphicsEndImageContext()
...@@ -102,7 +102,7 @@ extension UIImage { ...@@ -102,7 +102,7 @@ extension UIImage {
- Returns: A UIImage that is the color passed in. - Returns: A UIImage that is the color passed in.
*/ */
open func tint(with color: UIColor) -> UIImage? { open func tint(with color: UIColor) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, Device.scale) UIGraphicsBeginImageContextWithOptions(size, false, Screen.scale)
guard let context = UIGraphicsGetCurrentContext() else { guard let context = UIGraphicsGetCurrentContext() else {
return nil return nil
} }
...@@ -284,7 +284,7 @@ extension UIImage { ...@@ -284,7 +284,7 @@ extension UIImage {
open func blur(radius: CGFloat = 0, tintColor: UIColor? = nil, saturationDeltaFactor: CGFloat = 0) -> UIImage? { open func blur(radius: CGFloat = 0, tintColor: UIColor? = nil, saturationDeltaFactor: CGFloat = 0) -> UIImage? {
var effectImage = self var effectImage = self
let screenScale = Device.scale let screenScale = Screen.scale
let imageRect = CGRect(origin: .zero, size: size) let imageRect = CGRect(origin: .zero, size: size)
let hasBlur = radius > CGFloat(FLT_EPSILON) let hasBlur = radius > CGFloat(FLT_EPSILON)
let hasSaturationChange = fabs(saturationDeltaFactor - 1.0) > CGFloat(FLT_EPSILON) let hasSaturationChange = fabs(saturationDeltaFactor - 1.0) > CGFloat(FLT_EPSILON)
......
...@@ -36,7 +36,7 @@ extension UIWindow { ...@@ -36,7 +36,7 @@ extension UIWindow {
- Returns: An optional UIImage. - Returns: An optional UIImage.
*/ */
open func capture() -> UIImage? { open func capture() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(frame.size, isOpaque, Device.scale) UIGraphicsBeginImageContextWithOptions(frame.size, isOpaque, Screen.scale)
layer.render(in: UIGraphicsGetCurrentContext()!) layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext() let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext() UIGraphicsEndImageContext()
......
...@@ -37,7 +37,7 @@ open class NavigationBar: UINavigationBar { ...@@ -37,7 +37,7 @@ open class NavigationBar: UINavigationBar {
} }
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
return CGSize(width: Device.width, height: height) return CGSize(width: Screen.width, height: height)
} }
/// A preset wrapper around contentEdgeInsets. /// A preset wrapper around contentEdgeInsets.
...@@ -295,7 +295,7 @@ open class NavigationBar: UINavigationBar { ...@@ -295,7 +295,7 @@ open class NavigationBar: UINavigationBar {
depthPreset = .depth1 depthPreset = .depth1
interimSpacePreset = .interimSpace3 interimSpacePreset = .interimSpace3
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
backButtonImage = Icon.cm.arrowBack backButtonImage = Icon.cm.arrowBack
let image = UIImage.image(with: .clear, size: CGSize(width: 1, height: 1)) let image = UIImage.image(with: .clear, size: CGSize(width: 1, height: 1))
shadowImage = image shadowImage = image
......
...@@ -34,10 +34,10 @@ extension UINavigationController { ...@@ -34,10 +34,10 @@ extension UINavigationController {
/// Device status bar style. /// Device status bar style.
open var statusBarStyle: UIStatusBarStyle { open var statusBarStyle: UIStatusBarStyle {
get { get {
return Device.statusBarStyle return Application.statusBarStyle
} }
set(value) { set(value) {
Device.statusBarStyle = value Application.statusBarStyle = value
} }
} }
} }
...@@ -118,7 +118,7 @@ open class NavigationController: UINavigationController { ...@@ -118,7 +118,7 @@ open class NavigationController: UINavigationController {
view.clipsToBounds = true view.clipsToBounds = true
view.backgroundColor = .white view.backgroundColor = .white
view.contentScaleFactor = Device.scale view.contentScaleFactor = Screen.scale
// This ensures the panning gesture is available when going back between views. // This ensures the panning gesture is available when going back between views.
if let v = interactivePopGestureRecognizer { if let v = interactivePopGestureRecognizer {
......
...@@ -345,7 +345,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega ...@@ -345,7 +345,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
guard nil != rightView else { guard nil != rightView else {
return false return false
} }
return rightView!.x != Device.width return rightView!.x != Screen.width
} }
/** /**
...@@ -1197,7 +1197,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega ...@@ -1197,7 +1197,7 @@ open class NavigationDrawerController: RootController, UIGestureRecognizerDelega
/// Toggles the statusBar /// Toggles the statusBar
private func toggleStatusBar() { private func toggleStatusBar() {
if isOpened || Device.isLandscape && .phone == Device.userInterfaceIdiom { if isOpened || Application.isLandscape && .phone == Device.userInterfaceIdiom {
hideStatusBar() hideStatusBar()
} else { } else {
showStatusBar() showStatusBar()
......
...@@ -115,7 +115,7 @@ public class NavigationItem: NSObject { ...@@ -115,7 +115,7 @@ public class NavigationItem: NSObject {
/// Prepares the titleLabel. /// Prepares the titleLabel.
private func prepareTitleLabel() { private func prepareTitleLabel() {
titleLabel.textAlignment = .center titleLabel.textAlignment = .center
titleLabel.contentScaleFactor = Device.scale titleLabel.contentScaleFactor = Screen.scale
titleLabel.font = RobotoFont.medium(with: 17) titleLabel.font = RobotoFont.medium(with: 17)
titleLabel.textColor = Color.darkText.primary titleLabel.textColor = Color.darkText.primary
addObserver(self, forKeyPath: "titleLabel.textAlignment", options: [], context: &NavigationItemContext) addObserver(self, forKeyPath: "titleLabel.textAlignment", options: [], context: &NavigationItemContext)
...@@ -124,7 +124,7 @@ public class NavigationItem: NSObject { ...@@ -124,7 +124,7 @@ public class NavigationItem: NSObject {
/// Prepares the detailLabel. /// Prepares the detailLabel.
private func prepareDetailLabel() { private func prepareDetailLabel() {
detailLabel.textAlignment = .center detailLabel.textAlignment = .center
titleLabel.contentScaleFactor = Device.scale titleLabel.contentScaleFactor = Screen.scale
detailLabel.font = RobotoFont.regular(with: 12) detailLabel.font = RobotoFont.regular(with: 12)
detailLabel.textColor = Color.darkText.secondary detailLabel.textColor = Color.darkText.secondary
} }
......
...@@ -67,7 +67,7 @@ open class PhotoLibraryController: UIViewController { ...@@ -67,7 +67,7 @@ open class PhotoLibraryController: UIViewController {
open func prepare() { open func prepare() {
view.clipsToBounds = true view.clipsToBounds = true
view.backgroundColor = .white view.backgroundColor = .white
view.contentScaleFactor = Device.scale view.contentScaleFactor = Screen.scale
preparePhotoLibrary() preparePhotoLibrary()
} }
......
...@@ -34,20 +34,20 @@ open class RootController: UIViewController { ...@@ -34,20 +34,20 @@ open class RootController: UIViewController {
/// Device status bar style. /// Device status bar style.
open var statusBarStyle: UIStatusBarStyle { open var statusBarStyle: UIStatusBarStyle {
get { get {
return Device.statusBarStyle return Application.statusBarStyle
} }
set(value) { set(value) {
Device.statusBarStyle = value Application.statusBarStyle = value
} }
} }
/// Device visibility state. /// Device visibility state.
open var isStatusBarHidden: Bool { open var isStatusBarHidden: Bool {
get { get {
return Device.isStatusBarHidden return Application.isStatusBarHidden
} }
set(value) { set(value) {
Device.isStatusBarHidden = value Application.isStatusBarHidden = value
} }
} }
...@@ -141,7 +141,7 @@ open class RootController: UIViewController { ...@@ -141,7 +141,7 @@ open class RootController: UIViewController {
s.rootViewController = viewController s.rootViewController = viewController
s.rootViewController.view.clipsToBounds = true s.rootViewController.view.clipsToBounds = true
s.rootViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] s.rootViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
s.rootViewController.view.contentScaleFactor = Device.scale s.rootViewController.view.contentScaleFactor = Screen.scale
s.view.sendSubview(toBack: s.rootViewController.view) s.view.sendSubview(toBack: s.rootViewController.view)
completion?(result) completion?(result)
} }
...@@ -164,7 +164,7 @@ open class RootController: UIViewController { ...@@ -164,7 +164,7 @@ open class RootController: UIViewController {
open func prepare() { open func prepare() {
view.clipsToBounds = true view.clipsToBounds = true
view.backgroundColor = .white view.backgroundColor = .white
view.contentScaleFactor = Device.scale view.contentScaleFactor = Screen.scale
prepareRootViewController() prepareRootViewController()
} }
...@@ -191,6 +191,6 @@ open class RootController: UIViewController { ...@@ -191,6 +191,6 @@ open class RootController: UIViewController {
v.didMove(toParentViewController: self) v.didMove(toParentViewController: self)
v.view.clipsToBounds = true v.view.clipsToBounds = true
v.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] v.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
v.view.contentScaleFactor = Device.scale v.view.contentScaleFactor = Screen.scale
} }
} }
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* 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
public struct Screen {
/// Retrieves the device bounds.
public static var bounds: CGRect {
return UIScreen.main.bounds
}
/// Retrieves the device width.
public static var width: CGFloat {
return bounds.width
}
/// Retrieves the device height.
public static var height: CGFloat {
return bounds.height
}
/// Retrieves the device scale.
public static var scale: CGFloat {
return UIScreen.main.scale
}
}
...@@ -194,7 +194,7 @@ open class SearchBar: Bar { ...@@ -194,7 +194,7 @@ open class SearchBar: Bar {
/// Prepares the textField. /// Prepares the textField.
private func prepareTextField() { private func prepareTextField() {
textField.contentScaleFactor = Device.scale textField.contentScaleFactor = Screen.scale
textField.font = RobotoFont.regular(with: 17) textField.font = RobotoFont.regular(with: 17)
textField.backgroundColor = Color.clear textField.backgroundColor = Color.clear
textField.clearButtonMode = .whileEditing textField.clearButtonMode = .whileEditing
......
...@@ -104,7 +104,7 @@ open class Snackbar: Bar { ...@@ -104,7 +104,7 @@ open class Snackbar: Bar {
/// Prepares the textLabel. /// Prepares the textLabel.
private func prepareTextLabel() { private func prepareTextLabel() {
textLabel.contentScaleFactor = Device.scale textLabel.contentScaleFactor = Screen.scale
textLabel.font = RobotoFont.medium(with: 14) textLabel.font = RobotoFont.medium(with: 14)
textLabel.textAlignment = .left textLabel.textAlignment = .left
textLabel.textColor = Color.white textLabel.textColor = Color.white
......
...@@ -66,7 +66,7 @@ open class StatusBarController: RootController { ...@@ -66,7 +66,7 @@ open class StatusBarController: RootController {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
statusBar.width = view.width statusBar.width = view.width
statusBar.zPosition = Device.isLandscape && .phone == Device.userInterfaceIdiom ? 0 : 3000 statusBar.zPosition = Application.isLandscape && .phone == Device.userInterfaceIdiom ? 0 : 3000
rootViewController.view.frame = view.bounds rootViewController.view.frame = view.bounds
} }
......
...@@ -419,7 +419,7 @@ open class Switch: UIControl { ...@@ -419,7 +419,7 @@ open class Switch: UIControl {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
prepareTrack() prepareTrack()
prepareButton() prepareButton()
prepareSwitchState() prepareSwitchState()
......
...@@ -172,7 +172,7 @@ open class TableViewCell: UITableViewCell, Pulseable { ...@@ -172,7 +172,7 @@ open class TableViewCell: UITableViewCell, Pulseable {
open func prepare() { open func prepare() {
selectionStyle = .none selectionStyle = .none
separatorInset = .zero separatorInset = .zero
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
imageView?.isUserInteractionEnabled = false imageView?.isUserInteractionEnabled = false
textLabel?.isUserInteractionEnabled = false textLabel?.isUserInteractionEnabled = false
detailTextLabel?.isUserInteractionEnabled = false detailTextLabel?.isUserInteractionEnabled = false
......
...@@ -395,7 +395,7 @@ open class TextField: UITextField { ...@@ -395,7 +395,7 @@ open class TextField: UITextField {
clipsToBounds = false clipsToBounds = false
borderStyle = .none borderStyle = .none
backgroundColor = nil backgroundColor = nil
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
prepareDivider() prepareDivider()
preparePlaceholderLabel() preparePlaceholderLabel()
......
...@@ -223,7 +223,7 @@ open class TextView: UITextView { ...@@ -223,7 +223,7 @@ open class TextView: UITextView {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
textContainerInset = .zero textContainerInset = .zero
backgroundColor = .white backgroundColor = .white
clipsToBounds = false clipsToBounds = false
......
...@@ -147,7 +147,7 @@ open class Toolbar: Bar { ...@@ -147,7 +147,7 @@ open class Toolbar: Bar {
/// Prepares the titleLabel. /// Prepares the titleLabel.
private func prepareTitleLabel() { private func prepareTitleLabel() {
titleLabel.textAlignment = .center titleLabel.textAlignment = .center
titleLabel.contentScaleFactor = Device.scale titleLabel.contentScaleFactor = Screen.scale
titleLabel.font = RobotoFont.medium(with: 17) titleLabel.font = RobotoFont.medium(with: 17)
titleLabel.textColor = Color.darkText.primary titleLabel.textColor = Color.darkText.primary
addObserver(self, forKeyPath: "titleLabel.textAlignment", options: [], context: &ToolbarContext) addObserver(self, forKeyPath: "titleLabel.textAlignment", options: [], context: &ToolbarContext)
...@@ -156,7 +156,7 @@ open class Toolbar: Bar { ...@@ -156,7 +156,7 @@ open class Toolbar: Bar {
/// Prepares the detailLabel. /// Prepares the detailLabel.
private func prepareDetailLabel() { private func prepareDetailLabel() {
detailLabel.textAlignment = .center detailLabel.textAlignment = .center
detailLabel.contentScaleFactor = Device.scale detailLabel.contentScaleFactor = Screen.scale
detailLabel.font = RobotoFont.regular(with: 12) detailLabel.font = RobotoFont.regular(with: 12)
detailLabel.textColor = Color.darkText.secondary detailLabel.textColor = Color.darkText.secondary
} }
......
...@@ -96,7 +96,7 @@ open class ToolbarController: StatusBarController { ...@@ -96,7 +96,7 @@ open class ToolbarController: StatusBarController {
} }
set(value) { set(value) {
if let v = internalFloatingViewController { if let v = internalFloatingViewController {
v.view.layer.rasterizationScale = Device.scale v.view.layer.rasterizationScale = Screen.scale
v.view.layer.shouldRasterize = true v.view.layer.shouldRasterize = true
delegate?.toolbarControllerWillCloseFloatingViewController?(toolbarController: self) delegate?.toolbarControllerWillCloseFloatingViewController?(toolbarController: self)
internalFloatingViewController = nil internalFloatingViewController = nil
...@@ -134,9 +134,9 @@ open class ToolbarController: StatusBarController { ...@@ -134,9 +134,9 @@ open class ToolbarController: StatusBarController {
v.view.layer.zPosition = 1500 v.view.layer.zPosition = 1500
v.didMove(toParentViewController: self) v.didMove(toParentViewController: self)
v.view.isHidden = false v.view.isHidden = false
v.view.layer.rasterizationScale = Device.scale v.view.layer.rasterizationScale = Screen.scale
v.view.layer.shouldRasterize = true v.view.layer.shouldRasterize = true
view.layer.rasterizationScale = Device.scale view.layer.rasterizationScale = Screen.scale
view.layer.shouldRasterize = true view.layer.shouldRasterize = true
internalFloatingViewController = v internalFloatingViewController = v
isUserInteractionEnabled = false isUserInteractionEnabled = false
......
...@@ -91,7 +91,7 @@ open class View: UIView { ...@@ -91,7 +91,7 @@ open class View: UIView {
/** /**
A floating point value that defines a ratio between the pixel A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the Device.scale. of the view. By default, this value is set to the Screen.scale.
*/ */
@IBInspectable @IBInspectable
open var contentsScale: CGFloat { open var contentsScale: CGFloat {
...@@ -175,7 +175,7 @@ open class View: UIView { ...@@ -175,7 +175,7 @@ open class View: UIView {
when subclassing. when subclassing.
*/ */
open func prepare() { open func prepare() {
contentScaleFactor = Device.scale contentScaleFactor = Screen.scale
backgroundColor = .white backgroundColor = .white
prepareVisualLayer() prepareVisualLayer()
} }
......
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