Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modal presentation on top of the drawer. #56

Merged
merged 2 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ extension PresentationController {
self.currentDrawerCornerRadius = 0
}

self.targetDrawerState = endingState

AnimationSupport.clientCleanupViews(presentingDrawerAnimationActions: presentingAnimationActions,
presentedDrawerAnimationActions: presentedAnimationActions,
endingPosition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,15 @@ extension PresentationController {

switch panGesture.state {
case .began:
lastDrawerState = GeometryEvaluator.drawerState(for: currentDrawerY,
drawerPartialHeight: drawerPartialHeight,
containerViewHeight: containerViewHeight,
configuration: configuration,
clampToNearest: true)
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you're no longer setting lastDrawerState here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary to update it during the course of the pan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastDrawerState is not really consumed by anything until this PR, by the way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be, for the benefit of along-side animations performed by the presenting and/or presented view controllers.

Copy link
Contributor Author

@andersio andersio Apr 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking into this, changed is actually updating the targetDrawerState (renamed from lastDrawerState).


case .changed:
lastDrawerState = GeometryEvaluator.drawerState(for: currentDrawerY,
drawerPartialHeight: drawerPartialHeight,
containerViewHeight: containerViewHeight,
configuration: configuration,
clampToNearest: true)
currentDrawerY += panGesture.translation(in: view).y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

targetDrawerState = currentDrawerState
currentDrawerCornerRadius = cornerRadius(at: currentDrawerState)
panGesture.setTranslation(.zero, in: view)

case .ended:
case .ended, .cancelled:
let drawerSpeedY = panGesture.velocity(in: view).y / containerViewHeight
let endingState = GeometryEvaluator.nextStateFrom(currentState: currentDrawerState,
speedY: drawerSpeedY,
Expand All @@ -48,9 +40,6 @@ extension PresentationController {
configuration: configuration)
animateTransition(to: endingState)

case .cancelled:
animateTransition(to: lastDrawerState)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, likewise, I don't understand the reason for removing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancelled is treated as completed now, and picks the next state based on current drawer state plus velocity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if the user starts dragging the drawer up then changes his mind, the drawer continues up anyway? That doesn't sound right to me.


default:
break
}
Expand Down
13 changes: 10 additions & 3 deletions DrawerKit/DrawerKit/Internal API/PresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ final class PresentationController: UIPresentationController {
var drawerFullExpansionTapGR: UITapGestureRecognizer?
var drawerDismissalTapGR: UITapGestureRecognizer?
var drawerDragGR: UIPanGestureRecognizer?
var lastDrawerState: DrawerState = .collapsed

/// The target state of the drawer. If no presentation animation is in
/// progress, the value should be equivalent to `currentDrawerState`.
var targetDrawerState: DrawerState

init(presentingVC: UIViewController?,
presentingDrawerAnimationActions: DrawerAnimationActions,
Expand All @@ -24,6 +27,11 @@ final class PresentationController: UIPresentationController {
self.handleView = (configuration.handleViewConfiguration != nil ? UIView() : nil)
self.presentingDrawerAnimationActions = presentingDrawerAnimationActions
self.presentedDrawerAnimationActions = presentedDrawerAnimationActions

// NOTE: Set the current drawer state to the target state of the initial
// presentation animation.
self.targetDrawerState = configuration.supportsPartialExpansion ? .partiallyExpanded : .fullyExpanded

super.init(presentedViewController: presentedVC, presenting: presentingVC)
}
}
Expand All @@ -33,9 +41,8 @@ extension PresentationController {
var frame: CGRect = .zero
frame.size = size(forChildContentContainer: presentedViewController,
withParentContainerSize: containerViewSize)
let state: DrawerState = (supportsPartialExpansion ? .partiallyExpanded : .fullyExpanded)
let drawerFullY = configuration.fullExpansionBehaviour.drawerFullY
frame.origin.y = GeometryEvaluator.drawerPositionY(for: state,
frame.origin.y = GeometryEvaluator.drawerPositionY(for: targetDrawerState,
drawerPartialHeight: drawerPartialHeight,
containerViewHeight: containerViewHeight,
drawerFullY: drawerFullY)
Expand Down
4 changes: 4 additions & 0 deletions DrawerKitDemo/DrawerKitDemo/PresentedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class PresentedViewController: UIViewController {
}
}
}

@IBAction func unwindFromModal(with segue: UIStoryboardSegue) {
print("Unwound from the modal.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to be removed at some point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It is the Storyboard unwind point for dismissing the modal in the demo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the print statement.

}
}

extension PresentedViewController: UIScrollViewDelegate {
Expand Down
49 changes: 47 additions & 2 deletions DrawerKitDemo/DrawerKitDemo/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="uBw-Sr-LpF">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="uBw-Sr-LpF">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -130,19 +131,27 @@
<outlet property="delegate" destination="9a9-ft-1GT" id="Ta0-1G-Esp"/>
</connections>
</scrollView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="detailDisclosure" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ztp-Cf-a4s">
<rect key="frame" x="235" y="32" width="22" height="22"/>
<connections>
<segue destination="ILn-GS-avA" kind="presentation" id="Dds-Br-1fx"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.98065741760000003" green="1" blue="0.90980392160000001" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<constraints>
<constraint firstItem="69I-et-UOX" firstAttribute="top" secondItem="Jth-UI-73K" secondAttribute="bottom" constant="10" id="5I8-eE-iaZ"/>
<constraint firstItem="69I-et-UOX" firstAttribute="centerX" secondItem="tAJ-xI-Qxr" secondAttribute="centerX" id="95D-ht-lrm"/>
<constraint firstItem="Ojr-aM-v38" firstAttribute="top" secondItem="dEa-Pl-yQz" secondAttribute="bottom" constant="20" id="Dgd-aQ-agb"/>
<constraint firstItem="dEa-Pl-yQz" firstAttribute="top" secondItem="69I-et-UOX" secondAttribute="bottom" constant="100" id="Eai-cn-LDj"/>
<constraint firstItem="Ztp-Cf-a4s" firstAttribute="leading" secondItem="Jth-UI-73K" secondAttribute="trailing" constant="8" id="Pr8-hl-LaR"/>
<constraint firstItem="dEa-Pl-yQz" firstAttribute="leading" secondItem="tAJ-xI-Qxr" secondAttribute="leading" id="Vcw-46-NLg"/>
<constraint firstItem="Jth-UI-73K" firstAttribute="top" secondItem="tAJ-xI-Qxr" secondAttribute="top" constant="28" id="aH2-1L-AcL"/>
<constraint firstItem="Ojr-aM-v38" firstAttribute="leading" secondItem="tAJ-xI-Qxr" secondAttribute="leadingMargin" constant="10" id="cWU-AN-kgF"/>
<constraint firstItem="qPD-ym-Fa5" firstAttribute="top" secondItem="69I-et-UOX" secondAttribute="bottom" constant="25" id="cpO-2w-akW"/>
<constraint firstAttribute="trailing" secondItem="dEa-Pl-yQz" secondAttribute="trailing" id="gI5-Vo-Tk3"/>
<constraint firstItem="Jth-UI-73K" firstAttribute="centerX" secondItem="tAJ-xI-Qxr" secondAttribute="centerX" id="hN7-u7-BLQ"/>
<constraint firstItem="Ztp-Cf-a4s" firstAttribute="centerY" secondItem="Jth-UI-73K" secondAttribute="centerY" id="m1M-EE-Co9"/>
<constraint firstAttribute="bottomMargin" secondItem="Ojr-aM-v38" secondAttribute="bottom" constant="20" id="r5Q-A1-OUj"/>
<constraint firstItem="qPD-ym-Fa5" firstAttribute="centerX" secondItem="tAJ-xI-Qxr" secondAttribute="centerX" id="sgV-nk-lFF"/>
<constraint firstAttribute="trailingMargin" secondItem="Ojr-aM-v38" secondAttribute="trailing" constant="10" id="tkz-7e-SmV"/>
Expand All @@ -163,6 +172,42 @@
</objects>
<point key="canvasLocation" x="-4889" y="-3600"/>
</scene>
<!--View Controller-->
<scene sceneID="hN9-WT-acc">
<objects>
<viewController modalPresentationStyle="overFullScreen" id="ILn-GS-avA" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="tW2-fX-OIl"/>
<viewControllerLayoutGuide type="bottom" id="R2W-iO-cgi"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="M1z-fN-qgZ">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kp1-y6-ing">
<rect key="frame" x="165.5" y="311.5" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" secondItem="kp1-y6-ing" secondAttribute="height" multiplier="1:1" id="ThG-Ko-duV"/>
<constraint firstAttribute="width" constant="44" id="nPw-ft-jKu"/>
</constraints>
<state key="normal" title="Button" image="close"/>
<connections>
<segue destination="qRR-E6-YWn" kind="unwind" unwindAction="unwindFromModalWith:" id="WaZ-5b-Pw8"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kp1-y6-ing" firstAttribute="centerX" secondItem="M1z-fN-qgZ" secondAttribute="centerX" id="0cZ-EC-Emq"/>
<constraint firstItem="kp1-y6-ing" firstAttribute="centerY" secondItem="M1z-fN-qgZ" secondAttribute="centerY" id="etG-er-ypt"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pVR-K0-1GK" userLabel="First Responder" sceneMemberID="firstResponder"/>
<exit id="qRR-E6-YWn" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="-4071.1999999999998" y="-3600.4497751124441"/>
</scene>
</scenes>
<resources>
<image name="Saturn" width="992" height="1010"/>
Expand Down