Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BottomPopup.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "BottomPopup"
s.version = "0.5.0"
s.version = "0.6.0"
s.summary = "BottomPopup provides a popup-like presentation style to any view controller"

s.homepage = "https://github.com/ergunemr/BottomPopup"
Expand Down
32 changes: 21 additions & 11 deletions BottomPopup/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ww0-1o-M9p">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ww0-1o-M9p">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -33,7 +31,7 @@
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="fge-is-2kN">
<rect key="frame" x="16" y="84" width="343" height="343.5"/>
<rect key="frame" x="16" y="64" width="343" height="415"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="TFu-M2-fgA">
<rect key="frame" x="0.0" y="0.0" width="343" height="20.5"/>
Expand Down Expand Up @@ -141,6 +139,16 @@
<rect key="frame" x="0.0" y="312.5" width="345" height="31"/>
<color key="onTintColor" red="0.18039215689999999" green="0.80000000000000004" blue="0.4431372549" alpha="1" colorSpace="calibratedRGB"/>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Dismiss on Tap Outside" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ZFj-GO-V9S">
<rect key="frame" x="0.0" y="353.5" width="343" height="20.5"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gHv-PN-Tnc" userLabel="Disable Tap Gesture Switch">
<rect key="frame" x="0.0" y="384" width="345" height="31"/>
<color key="onTintColor" red="0.18039215689999999" green="0.80000000000000004" blue="0.4431372549" alpha="1" colorSpace="calibratedRGB"/>
</switch>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5o9-TU-tZF">
Expand Down Expand Up @@ -178,6 +186,8 @@
<outlet property="dismissDurationLabel" destination="Kng-dQ-JuL" id="33A-Ih-fRv"/>
<outlet property="dismissDurationSlider" destination="5sS-pc-Uuv" id="3cJ-nb-pvF"/>
<outlet property="dismissInteractivelySwitch" destination="ZjR-OR-KOP" id="FdW-hL-tRa"/>
<outlet property="dismissOnTapLabel" destination="ZFj-GO-V9S" id="Azh-pG-8XG"/>
<outlet property="dismissOnTapSwitch" destination="gHv-PN-Tnc" id="R6O-dY-ile"/>
<outlet property="heightLabel" destination="W4C-5T-K8w" id="gYn-f4-xTx"/>
<outlet property="heightSlider" destination="vo3-pQ-54i" id="dog-Wa-kp8"/>
<outlet property="presentDurationLabel" destination="Wyj-Mz-8SV" id="oL6-0s-oa7"/>
Expand All @@ -199,13 +209,13 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Your View Controller!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4yi-ws-v6P">
<rect key="frame" x="71.5" y="329" width="232" height="29"/>
<rect key="frame" x="71.5" y="319" width="232" height="29"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="24"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Vzz-iz-lZp">
<rect key="frame" x="304" y="40" width="51" height="29"/>
<rect key="frame" x="304" y="20" width="51" height="29"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="14"/>
<state key="normal" title="Dismiss">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down Expand Up @@ -238,7 +248,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Your Navigation Controller!" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Mt-CH-4Qv">
<rect key="frame" x="39" y="351" width="297.5" height="29"/>
<rect key="frame" x="39" y="341" width="297.5" height="29"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Medium" family="Helvetica Neue" pointSize="24"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -284,7 +294,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="ww0-1o-M9p" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="cZQ-xm-n5Y">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand All @@ -302,7 +312,7 @@
<navigationController storyboardIdentifier="customNavController" automaticallyAdjustsScrollViewInsets="NO" id="Uy4-o4-jhz" customClass="ExampleNavigationController" customModule="BottomPopup" customModuleProvider="target" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="7G1-Bf-ysE">
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ open class BottomPopupNavigationController: UINavigationController, BottomPopupA
open func shouldPopupDismissInteractivelty() -> Bool {
return BottomPopupConstants.dismissInteractively
}

open func shouldDimissOnTap() -> Bool {
return BottomPopupConstants.dismissOnTapEnabled
}

open func getPopupHeight() -> CGFloat {
return BottomPopupConstants.kDefaultHeight
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BottomPopupPresentationController: UIPresentationController {
fileprivate var dimmingView: UIView!
fileprivate let popupHeight: CGFloat
fileprivate let dimmingViewAlpha: CGFloat
fileprivate let dismissOnTapEnabled: Bool

override var frameOfPresentedViewInContainerView: CGRect {
get {
Expand All @@ -31,9 +32,10 @@ class BottomPopupPresentationController: UIPresentationController {
})
}

init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, usingHeight height: CGFloat, andDimmingViewAlpha dimmingAlpha: CGFloat) {
init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, usingHeight height: CGFloat, andDimmingViewAlpha dimmingAlpha: CGFloat, dismissOnTapEnabled: Bool = true) {
self.popupHeight = height
self.dimmingViewAlpha = dimmingAlpha
self.dismissOnTapEnabled = dismissOnTapEnabled
super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
setupDimmingView()
}
Expand All @@ -52,6 +54,7 @@ class BottomPopupPresentationController: UIPresentationController {
}

@objc fileprivate func handleTap(_ tap: UITapGestureRecognizer) {
guard dismissOnTapEnabled == true else { return }
presentedViewController.dismiss(animated: true, completion: nil)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class BottomPopupTransitionHandler: NSObject, UIViewControllerTransitioningDeleg

//MARK: Specific animators
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return BottomPopupPresentationController(presentedViewController: presented, presenting: presenting, usingHeight: popupViewController.getPopupHeight(), andDimmingViewAlpha: popupViewController.getDimmingViewAlpha())
return BottomPopupPresentationController(presentedViewController: presented,
presenting: presenting,
usingHeight: popupViewController.getPopupHeight(),
andDimmingViewAlpha: popupViewController.getDimmingViewAlpha(),
dismissOnTapEnabled: popupViewController.shouldDimissOnTap())
}

func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
Expand Down
2 changes: 2 additions & 0 deletions BottomPopup/BottomPopupController/BottomPopupUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public protocol BottomPopupAttributesDelegate: class {
func getPopupPresentDuration() -> Double
func getPopupDismissDuration() -> Double
func shouldPopupDismissInteractivelty() -> Bool
func shouldDimissOnTap() -> Bool
func getDimmingViewAlpha() -> CGFloat
}

Expand All @@ -43,5 +44,6 @@ public struct BottomPopupConstants {
static let kDefaultPresentDuration = 0.5
static let kDefaultDismissDuration = 0.5
static let dismissInteractively = true
static let dismissOnTapEnabled = true
static let kDimmingViewDefaultAlphaValue: CGFloat = 0.5
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ open class BottomPopupViewController: UIViewController, BottomPopupAttributesDel
open func shouldPopupDismissInteractivelty() -> Bool {
return BottomPopupConstants.dismissInteractively
}

open func shouldDimissOnTap() -> Bool {
return BottomPopupConstants.dismissOnTapEnabled
}

open func getPopupHeight() -> CGFloat {
return BottomPopupConstants.kDefaultHeight
Expand Down
5 changes: 5 additions & 0 deletions BottomPopup/ExampleNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ExampleNavigationController: BottomPopupNavigationController {
var presentDuration: Double?
var dismissDuration: Double?
var shouldDismissInteractivelty: Bool?
var shouldDismissOnTap: Bool?

override func getPopupHeight() -> CGFloat {
return height ?? CGFloat(300)
Expand All @@ -35,4 +36,8 @@ class ExampleNavigationController: BottomPopupNavigationController {
override func shouldPopupDismissInteractivelty() -> Bool {
return shouldDismissInteractivelty ?? true
}

override func shouldDimissOnTap() -> Bool {
return shouldDismissOnTap ?? true
}
}
5 changes: 5 additions & 0 deletions BottomPopup/ExamplePopupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ExamplePopupViewController: BottomPopupViewController {
var presentDuration: Double?
var dismissDuration: Double?
var shouldDismissInteractivelty: Bool?
var shouldDismissOnTap: Bool?

@IBAction func dismissButtonTapped(_ sender: UIButton) {
dismiss(animated: true, completion: nil)
Expand Down Expand Up @@ -42,4 +43,8 @@ class ExamplePopupViewController: BottomPopupViewController {
override func shouldPopupDismissInteractivelty() -> Bool {
return shouldDismissInteractivelty ?? true
}

override func shouldDimissOnTap() -> Bool {
return shouldDismissOnTap ?? true
}
}
4 changes: 4 additions & 0 deletions BottomPopup/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class ViewController: UIViewController {
@IBOutlet weak var presentDurationSlider: UISlider!
@IBOutlet weak var dismissDurationSlider: UISlider!
@IBOutlet weak var dismissInteractivelySwitch: UISwitch!
@IBOutlet weak var dismissOnTapSwitch: UISwitch!

@IBOutlet weak var heightLabel: UILabel!
@IBOutlet weak var topCornerRadiusLabel: UILabel!
@IBOutlet weak var presentDurationLabel: UILabel!
@IBOutlet weak var dismissDurationLabel: UILabel!
@IBOutlet weak var dismissOnTapLabel: UILabel!

var height: CGFloat = 300 {
didSet {
Expand Down Expand Up @@ -85,6 +87,7 @@ class ViewController: UIViewController {
popupVC.presentDuration = presentDuration
popupVC.dismissDuration = dismissDuration
popupVC.shouldDismissInteractivelty = dismissInteractivelySwitch.isOn
popupVC.shouldDismissOnTap = dismissOnTapSwitch.isOn
popupVC.popupDelegate = self
present(popupVC, animated: true, completion: nil)
}
Expand All @@ -96,6 +99,7 @@ class ViewController: UIViewController {
popupNavController.presentDuration = presentDuration
popupNavController.dismissDuration = dismissDuration
popupNavController.shouldDismissInteractivelty = dismissInteractivelySwitch.isOn
popupNavController.shouldDismissOnTap = dismissOnTapSwitch.isOn
present(popupNavController, animated: true, completion: nil)
}
}
Expand Down