mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-21 23:22:08 +02:00
Make sliding modal presentable spannable
This commit is contained in:
@@ -22,7 +22,7 @@ protocol SlidingModalContainerViewDelegate: class {
|
||||
}
|
||||
|
||||
/// `SlidingModalContainerView` is a custom UIView used as a `UIViewControllerContextTransitioning.containerView` subview to embed a `SlidingModalPresentable` during presentation.
|
||||
final class SlidingModalContainerView: UIView, Themable, NibLoadable {
|
||||
class SlidingModalContainerView: UIView, Themable, NibLoadable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
@@ -72,7 +72,7 @@ final class SlidingModalContainerView: UIView, Themable, NibLoadable {
|
||||
// MARK: - Setup
|
||||
|
||||
static func instantiate() -> SlidingModalContainerView {
|
||||
return SlidingModalContainerView.loadFromNib()
|
||||
return self.loadFromNib()
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
@@ -29,14 +29,16 @@ final class SlidingModalPresentationAnimator: NSObject {
|
||||
// MARK: - Properties
|
||||
|
||||
private let isPresenting: Bool
|
||||
private let isSpanning: Bool
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
/// Instantiate a SlidingModalPresentationAnimator object.
|
||||
///
|
||||
/// - Parameter isPresenting: true to animate presentation or false to animate dismissal
|
||||
required public init(isPresenting: Bool) {
|
||||
required public init(isPresenting: Bool, isSpanning: Bool) {
|
||||
self.isPresenting = isPresenting
|
||||
self.isSpanning = isSpanning
|
||||
super.init()
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ final class SlidingModalPresentationAnimator: NSObject {
|
||||
|
||||
let containerView = transitionContext.containerView
|
||||
|
||||
let slidingModalContainerView = SlidingModalContainerView.instantiate()
|
||||
let slidingModalContainerView = isSpanning ? SpanningSlidingModalContainerView.instantiate() : SlidingModalContainerView.instantiate()
|
||||
slidingModalContainerView.alpha = 0
|
||||
slidingModalContainerView.updateDimmingViewAlpha(0.0)
|
||||
|
||||
|
||||
@@ -18,17 +18,23 @@ import Foundation
|
||||
|
||||
/// `SlidingModalPresentationDelegate` handle a custom sliding UIViewController transition.
|
||||
public class SlidingModalPresentationDelegate: NSObject {
|
||||
private let isSpanning: Bool
|
||||
|
||||
public init(isSpanning: Bool) {
|
||||
self.isSpanning = isSpanning
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIViewControllerTransitioningDelegate
|
||||
extension SlidingModalPresentationDelegate: UIViewControllerTransitioningDelegate {
|
||||
|
||||
public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
return SlidingModalPresentationAnimator(isPresenting: true)
|
||||
return SlidingModalPresentationAnimator(isPresenting: true, isSpanning: isSpanning)
|
||||
}
|
||||
|
||||
public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
return SlidingModalPresentationAnimator(isPresenting: false)
|
||||
return SlidingModalPresentationAnimator(isPresenting: false, isSpanning: isSpanning)
|
||||
}
|
||||
|
||||
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
|
||||
|
||||
@@ -34,6 +34,9 @@ final class SlidingModalPresenter: NSObject {
|
||||
// swiftlint:enable weak_delegate
|
||||
private weak var presentingViewController: UIViewController?
|
||||
|
||||
/// Is content view spanning the screen width and to the bottom
|
||||
var isSpanning: Bool = false
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
@objc func present(_ viewController: SlidingModalPresentable.ViewControllerType, from presentingViewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
|
||||
@@ -47,7 +50,7 @@ final class SlidingModalPresenter: NSObject {
|
||||
|
||||
viewController.preferredContentSize = CGSize(width: TabletContentSize.preferred.width, height: preferredHeight)
|
||||
} else {
|
||||
let transitionDelegate = SlidingModalPresentationDelegate()
|
||||
let transitionDelegate = SlidingModalPresentationDelegate(isSpanning: isSpanning)
|
||||
|
||||
viewController.modalPresentationStyle = .custom
|
||||
viewController.transitioningDelegate = transitionDelegate
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright 2020 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class SpanningSlidingModalContainerView: SlidingModalContainerView {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
||||
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="SpanningSlidingModalContainerView" customModule="Riot" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<view alpha="0.69999999999999996" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="53q-mu-x6X">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<color key="backgroundColor" white="1" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QWp-44-y8i">
|
||||
<rect key="frame" x="0.0" y="596" width="414" height="300"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" priority="750" constant="300" id="KJn-4o-kRn"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="QWp-44-y8i" secondAttribute="trailing" id="5Va-ZZ-SDE"/>
|
||||
<constraint firstItem="53q-mu-x6X" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="6Vb-zr-n6S"/>
|
||||
<constraint firstAttribute="bottom" secondItem="QWp-44-y8i" secondAttribute="bottom" id="AkC-lw-FrU"/>
|
||||
<constraint firstAttribute="trailing" secondItem="53q-mu-x6X" secondAttribute="trailing" id="EZg-k9-QuF"/>
|
||||
<constraint firstAttribute="bottom" secondItem="53q-mu-x6X" secondAttribute="bottom" id="NoA-lJ-53P"/>
|
||||
<constraint firstItem="QWp-44-y8i" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="joy-hr-PpZ"/>
|
||||
<constraint firstItem="53q-mu-x6X" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="lJ8-Oz-pLZ"/>
|
||||
<constraint firstItem="QWp-44-y8i" firstAttribute="top" relation="greaterThanOrEqual" secondItem="vUN-kp-3ea" secondAttribute="top" constant="50" id="nnr-Lr-vpY"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
|
||||
<connections>
|
||||
<outlet property="contentView" destination="QWp-44-y8i" id="mFc-eZ-nx2"/>
|
||||
<outlet property="contentViewBottomConstraint" destination="AkC-lw-FrU" id="p49-z7-CgK"/>
|
||||
<outlet property="contentViewHeightConstraint" destination="KJn-4o-kRn" id="VUT-sf-ebZ"/>
|
||||
<outlet property="dimmingView" destination="53q-mu-x6X" id="L4V-r2-NUX"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="139" y="143"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
Reference in New Issue
Block a user