-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
477 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// ModalCenterPosition.swift | ||
// Presentr | ||
// | ||
// Created by Daniel Lozano on 7/6/16. | ||
// Copyright © 2016 danielozano. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
Describes the presented presented view controller's center position. It is meant to be non-specific, but we can use the 'calculatePoint' method when we want to calculate the exact point by passing in the 'containerBounds' rect that only the presentation controller should be aware of. | ||
- Center: Center of the screen. | ||
- TopCenter: Center of the top half of the screen. | ||
- BottomCenter: Center of the bottom half of the screen. | ||
- Custom: A custom center position using a CGPoint which represents the center point of the presented view controller. | ||
- Custom: A custom center position to be calculated, using a CGPoint which represents the origin of the presented view controller. | ||
*/ | ||
public enum ModalCenterPosition { | ||
|
||
case Center | ||
case TopCenter | ||
case BottomCenter | ||
case Custom(centerPoint: CGPoint) | ||
case CustomOrigin(origin: CGPoint) | ||
|
||
/** | ||
Calculates the exact position for the presented view controller center. | ||
- parameter containerBounds: The container bounds the controller is being presented in. | ||
- returns: CGPoint representing the presented view controller's center point. | ||
*/ | ||
func calculatePoint(containerBounds: CGRect) -> CGPoint?{ | ||
switch self { | ||
case .Center: | ||
return CGPointMake(containerBounds.width / 2, containerBounds.height / 2) | ||
case .TopCenter: | ||
return CGPointMake(containerBounds.width / 2, containerBounds.height * (1 / 4) - 1) | ||
case .BottomCenter: | ||
return CGPointMake(containerBounds.width / 2, containerBounds.height * (3 / 4)) | ||
case .Custom(let point): | ||
return point | ||
case .CustomOrigin(_): | ||
return nil | ||
} | ||
} | ||
|
||
func calculateOrigin() -> CGPoint?{ | ||
switch self { | ||
case .CustomOrigin(let origin): | ||
return origin | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// ModalSize.swift | ||
// Presentr | ||
// | ||
// Created by Daniel Lozano on 7/6/16. | ||
// Copyright © 2016 danielozano. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
Descibes a presented modal's size dimension (width or height). It is meant to be non-specific, but the exact position can be calculated by calling the 'calculate' methods, passing in the 'parentSize' which only the Presentation Controller should be aware of. | ||
- Default: Default size. Will use Presentr's default margins to calculate size of presented controller. This is the size the .Popup presentation type uses. | ||
- Half: Half of the screen. | ||
- Full: Full screen. | ||
- Custom: Custom fixed size. | ||
*/ | ||
public enum ModalSize { | ||
|
||
case Default | ||
case Half | ||
case Full | ||
case Custom(size: Float) | ||
|
||
/** | ||
Calculates the exact width value for the presented view controller. | ||
- parameter parentSize: The presenting view controller's size. Provided by the presentation controller. | ||
- returns: Exact float width value. | ||
*/ | ||
func calculateWidth(parentSize: CGSize) -> Float{ | ||
switch self { | ||
case .Default: | ||
return floorf(Float(parentSize.width) - (PresentrConstants.Values.defaultSideMargin * 2.0)) | ||
case .Half: | ||
return floorf(Float(parentSize.width) / 2.0) | ||
case .Full: | ||
return Float(parentSize.width) | ||
case .Custom(let size): | ||
return size | ||
} | ||
} | ||
|
||
/** | ||
Calculates the exact height value for the presented view controller. | ||
- parameter parentSize: The presenting view controller's size. Provided by the presentation controller. | ||
- returns: Exact float height value. | ||
*/ | ||
func calculateHeight(parentSize: CGSize) -> Float{ | ||
switch self { | ||
case .Default: | ||
return floorf(Float(parentSize.height) * PresentrConstants.Values.defaultHeightPercentage) | ||
case .Half: | ||
return floorf(Float(parentSize.height) / 2.0) | ||
case .Full: | ||
return Float(parentSize.height) | ||
case .Custom(let size): | ||
return size | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// PresentationType.swift | ||
// Presentr | ||
// | ||
// Created by Daniel Lozano on 7/6/16. | ||
// Copyright © 2016 danielozano. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/** | ||
Basic Presentr type. Its job is to describe the 'type' of presentation. The type describes the size and position of the presented view controller. | ||
- Alert: This is a small 270 x 180 alert which is the same size as the default iOS alert. | ||
- Popup: This is a average/default size 'popup' modal. | ||
- TopHalf: This takes up half of the screen, on the top side. | ||
- BottomHalf: This takes up half of the screen, on the bottom side. | ||
- Custom: Provide a custom width, height and center position. | ||
*/ | ||
public enum PresentationType { | ||
|
||
case Alert | ||
case Popup | ||
case TopHalf | ||
case BottomHalf | ||
case Custom(width: ModalSize, height: ModalSize, center: ModalCenterPosition) | ||
|
||
/** | ||
Describes the sizing for each Presentr type. It is meant to be non device/width specific, except for the .Custom case. | ||
- returns: A tuple containing two 'ModalSize' enums, describing its width and height. | ||
*/ | ||
func size() -> (width: ModalSize, height: ModalSize) { | ||
switch self { | ||
case .Alert: | ||
return (.Custom(size: 270), .Custom(size: 180)) | ||
case .Popup: | ||
return (.Default, .Default) | ||
case .TopHalf, .BottomHalf: | ||
return (.Full, .Half) | ||
case .Custom(let width, let height, _): | ||
return (width, height) | ||
} | ||
} | ||
|
||
/** | ||
Describes the position for each Presentr type. It is meant to be non device/width specific, except for the .Custom case. | ||
- returns: Returns a 'ModalCenterPosition' enum describing the center point for the presented modal. | ||
*/ | ||
func position() -> ModalCenterPosition { | ||
switch self { | ||
case .Alert, .Popup: | ||
return .Center | ||
case .TopHalf: | ||
return .TopCenter | ||
case .BottomHalf: | ||
return .BottomCenter | ||
case .Custom(_, _, let center): | ||
return center | ||
} | ||
} | ||
|
||
/** | ||
Associates each Presentr type with a default transition type, in case one is not provided to the Presentr object. | ||
- returns: Return a 'TransitionType' which describes a system provided or custom transition animation. | ||
*/ | ||
func defaultTransitionType() -> TransitionType{ | ||
switch self { | ||
case .TopHalf: | ||
return .CoverVerticalFromTop | ||
default: | ||
return .CoverVertical | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// Presentr+Equatable.swift | ||
// Presentr | ||
// | ||
// Created by Daniel Lozano on 7/6/16. | ||
// Copyright © 2016 danielozano. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension PresentationType: Equatable { } | ||
public func ==(lhs: PresentationType, rhs: PresentationType) -> Bool{ | ||
switch (lhs, rhs){ | ||
case (let .Custom(lhsWidth, lhsHeight, lhsCenter), let .Custom(rhsWidth, rhsHeight, rhsCenter)): | ||
return lhsWidth == rhsWidth && lhsHeight == rhsHeight && lhsCenter == rhsCenter | ||
case (.Alert, .Alert): | ||
return true | ||
case (.Popup, .Popup): | ||
return true | ||
case (.TopHalf, .TopHalf): | ||
return true | ||
case (.BottomHalf, .BottomHalf): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
extension ModalSize: Equatable { } | ||
public func ==(lhs: ModalSize, rhs: ModalSize) -> Bool{ | ||
switch (lhs, rhs){ | ||
case (let .Custom(lhsSize), let .Custom(rhsSize)): | ||
return lhsSize == rhsSize | ||
case (.Default, .Default): | ||
return true | ||
case (.Half, .Half): | ||
return true | ||
case (.Full, .Full): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
extension ModalCenterPosition: Equatable { } | ||
public func ==(lhs: ModalCenterPosition, rhs: ModalCenterPosition) -> Bool{ | ||
switch (lhs, rhs){ | ||
case (let .Custom(lhsCenterPoint), let .Custom(rhsCenterPoint)): | ||
return lhsCenterPoint.x == rhsCenterPoint.x && lhsCenterPoint.y == rhsCenterPoint.y | ||
case (.Center, .Center): | ||
return true | ||
case (.TopCenter, .TopCenter): | ||
return true | ||
case (.BottomCenter, .BottomCenter): | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
Oops, something went wrong.