8000 Sort bug with content inset by ppamorim · Pull Request #2 · ppamorim/PanModal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sort bug with content inse 8000 t #2

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

Merged
merged 1 commit into from
Sep 24, 2021
Merged
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
48 changes: 25 additions & 23 deletions PanModal/Controller/PanModalPresentationController.swift
8000
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ open class PanModalPresentationController: UIPresentationController {
Determine anchored Y postion based on the `anchorModalToLongForm` flag
*/
private var anchoredYPosition: CGFloat {
let defaultTopOffset = presentable?.topOffset ?? 0
let defaultTopOffset: CGFloat = presentable?.topOffset ?? 0
return anchorModalToLongForm ? longFormYPosition : defaultTopOffset
}

/**
Configuration object for PanModalPresentationController
*/
private var presentable: PanModalPresentable? {
return presentedViewController as? PanModalPresentable
presentedViewController as? PanModalPresentable
}

// MARK: - Views
Expand Down Expand Up @@ -284,7 +284,7 @@ public extension PanModalPresentationController {
*/
func performUpdates(_ updates: () -> Void) {

guard let scrollView = presentable?.panScrollable
guard let scrollView: UIScrollView = presentable?.panScrollable
else { return }

// Pause scroll observer
Expand Down Expand Up @@ -581,7 +581,7 @@ private extension PanModalPresentationController {
func respond(to panGestureRecognizer: UIPanGestureRecognizer) {
presentable?.willRespond(to: panGestureRecognizer)

var yDisplacement = panGestureRecognizer.translation(in: presentedView).y
var yDisplacement: CGFloat = panGestureRecognizer.translation(in: presentedView).y

/**
If the presentedView is not anchored to long form, reduce the rate of movement
Expand Down Expand Up @@ -621,8 +621,8 @@ private extension PanModalPresentationController {

guard
isPresentedViewAnchored,
let scrollView = presentable?.panScrollable,
scrollView.contentOffset.y > 0
let scrollView: UIScrollView = presentable?.panScrollable,
scrollView.contentOffset.y > -scrollView.contentInset.top
else {
return false
}
Expand All @@ -636,15 +636,15 @@ private extension PanModalPresentationController {
emb 8000 edded scrollView's panGestureRecognizer.
*/
func shouldPrioritize(panGestureRecognizer: UIPanGestureRecognizer) -> Bool {
return panGestureRecognizer.state == .began &&
panGestureRecognizer.state == .began &&
presentable?.shouldPrioritize(panModalGestureRecognizer: panGestureRecognizer) == true
}

/**
Check if the given velocity is within the sensitivity range
*/
func isVelocityWithinSensitivityRange(_ velocity: CGFloat) -> Bool {
return (abs(velocity) - (1000 * (1 - Constants.snapMovementSensitivity))) > 0
(abs(velocity) - (1000 * (1 - Constants.snapMovementSensitivity))) > 0
}

func snap(toYPosition yPos: CGFloat) {
Expand All @@ -661,16 +661,17 @@ private extension PanModalPresentationController {
*/
func adjust(toYPosition yPos: CGFloat, updateDragIndicatorView: Bool = false) {
presentedView.frame.origin.y = max(yPos, anchoredYPosition)

if updateDragIndicatorView {
dragIndicatorView.frame.origin.y = presentedView.frame.origin.y - Constants.indicatorYOffset
dragIndicatorView.frame.origin.y = presentedView.frame.origin.y - Constants.indicatorYOffset
}

guard presentedView.frame.origin.y > shortFormYPosition else {
backgroundView.dimState = .max
return
}

let yDisplacementFromShortForm = presentedView.frame.origin.y - shortFormYPosition
let yDisplacementFromShortForm: CGFloat = presentedView.frame.origin.y - shortFormYPosition

/**
Once presentedView is translated below shortForm, calculate yPos relative to bottom of screen
Expand All @@ -687,7 +688,7 @@ private extension PanModalPresentationController {
- values: array of floats we would like to compare against
*/
func nearest(to number: CGFloat, inValues values: [CGFloat]) -> CGFloat {
guard let nearestVal = values.min(by: { abs(number - $0) < abs(number - $1) })
guard let nearestVal: CGFloat = values.min(by: { abs(number - $0) < abs(number - $1) })
else { return number }
return nearestVal
}
Expand Down Expand Up @@ -731,7 +732,7 @@ private extension PanModalPresentationController {
!presentedViewController.isBeingPresented
else { return }

if !isPresentedViewAnchored && scrollView.contentOffset.y > 0 {
if !isPresentedViewAnchored && scrollView.contentOffset.y > -scrollView.contentInset.top {

/**
Hold the scrollView in place if we're actively scrolling and not handling top bounce
Expand All @@ -740,7 +741,7 @@ private extension PanModalPresentationController {

} else if scrollView.isScrolling || isPresentedViewAnimating {

if isPresentedViewAnchored {
if isPresentedViewAnchored {
/**
While we're scrolling upwards on the scrollView,
store the last content offset position
Expand All @@ -754,7 +755,8 @@ private extension PanModalPresentationController {
}

} else if presentedViewController.view.isKind(of: UIScrollView.self)
&& !isPresentedViewAnimating && scrollView.contentOffset.y <= 0 {
&& !isPresentedViewAnimating
&& scrollView.contentOffset.y <= -scrollView.contentInset.top {

/**
In the case where we drag down quickly on the scroll view and let go,
Expand All @@ -770,16 +772,16 @@ private extension PanModalPresentationController {
Halts the scroll of a given scroll view & anchors it at the `scrollViewYOffset`
*/
func haltScrolling(_ scrollView: UIScrollView) {
scrollView.setContentOffset(CGPoint(x: 0, y: scrollViewYOffset), animated: false)
scrollView.setContentOffset(CGPoint(x: 0, y: scrollViewYOffset - scrollView.contentInset.top), animated: false)
scrollView.showsVerticalScrollIndicator = false
}

/**
As the user scrolls, track & save the scroll view y offset.
This helps halt scrolling when we want to hold the scroll view in place.
*/
func trackScrolling(_ scrollView: UIScrollView) {
scrollViewYOffset = max(scrollView.contentOffset.y, 0)
scrollViewYOffset = max(scrollView.contentOffset.y, 0.0)
scrollView.showsVerticalScrollIndicator = true
}

Expand Down Expand Up @@ -832,15 +834,15 @@ extension PanModalPresentationController: UIGestureRecognizerDelegate {
Do not require any other gesture recognizers to fail
*/
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return false
false
}

/**
Allow simultaneous gesture recognizers only when the other gesture recognizer's view
is the pan scrollable view
*/
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return otherGestureRecognizer.view == presentable?.panScrollable
otherGestureRecognizer.view == presentable?.panScrollable
}
}

Expand Down Expand Up @@ -869,10 +871,10 @@ private extension PanModalPresentationController {
view.layer.masksToBounds = true

if #available(iOS 11.0, *) {
view.layer.maskedCorners = maskedCorners
if #available(iOS 13.0, *) {
view.layer.cornerCurve = .continuous
}
view.layer.maskedCorners = maskedCorners
if #available(iOS 13.0, *) {
view.layer.cornerCurve = .continuous
}
}

}
Expand Down
12 changes: 6 additions & 6 deletions PanModal/View/DimmedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DimmedView: UIView {
Represents the possible states of the dimmed view.
max, off or a percentage of dimAlpha.
*/
enum DimState {
public enum DimState {
case max
case off
case percent(CGFloat)
Expand All @@ -28,14 +28,14 @@ public class DimmedView: UIView {
/**
The state of the dimmed view
*/
var dimState: DimState = .off {
var dimState: DimState = DimState.off {
didSet {
switch dimState {
case .max:
case DimState.max:
alpha = 1.0
case .off:
case DimState.off:
6D40 alpha = 0.0
case .percent(let percentage):
case DimState.percent(let percentage):
alpha = max(0.0, min(1.0, percentage))
}
}
Expand All @@ -50,7 +50,7 @@ public class DimmedView: UIView {
Tap gesture recognizer
*/
private lazy var tapGesture: UIGestureRecognizer = {
return UITapGestureRecognizer(target: self, action: #selector(didTapView))
UITapGestureRecognizer(target: self, action: #selector(didTapView))
}()

// MARK: - Initializers
Expand Down
12 changes: 12 additions & 0 deletions PanModalDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
0F2A2C682239C15D003BDB2F /* UIViewController+PanModalPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74C072A9220BA82A00124CE1 /* UIViewController+PanModalPresenter.swift */; };
0F2A2C692239C162003BDB2F /* DimmedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC13906E216D9458007A3E64 /* DimmedView.swift */; };
0F2A2C6A2239C165003BDB2F /* PanContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94795C9C21F03368008045A0 /* PanContainerView.swift */; };
4889982926FD3E81000E7394 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4889982826FD3E81000E7394 /* TableViewController.swift */; };
743CABB02225FC9F00634A5A /* UserGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743CABAF2225FC9F00634A5A /* UserGroupViewController.swift */; };
743CABB22225FD1100634A5A /* UserGroupHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743CABB12225FD1100634A5A /* UserGroupHeaderView.swift */; };
743CABB42225FE7700634A5A /* UserGroupMemberPresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743CABB32225FE7700634A5A /* UserGroupMemberPresentable.swift */; };
Expand Down Expand Up @@ -93,6 +94,7 @@
0F2A2C512239C119003BDB2F /* PanModal.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PanModal.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0F2A2C532239C119003BDB2F /* PanModal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PanModal.h; sourceTree = "<group>"; };
0F2A2C542239C119003BDB2F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4889982826FD3E81000E7394 /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
743CABAF2225FC9F00634A5A /* UserGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserGroupViewController.swift; sourceTree = "<group>"; };
743CABB12225FD1100634A5A /* UserGroupHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserGroupHeaderView.swift; sourceTree = "<group>"; };
743CABB32225FE7700634A5A /* UserGroupMemberPresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserGroupMemberPresentable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -167,6 +169,14 @@
path = PanModal;
sourceTree = "<group>";
};
4889982726FD3E68000E7394 /* Table View */ = {
isa = PBXGroup;
children = (
4889982826FD3E81000E7394 /* TableViewController.swift */,
);
path = "Table View";
sourceTree = "<group>";
};
743CABAE2225FC4A00634A5A /* User Groups */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -328,6 +338,7 @@
DC139079216D9AAA007A3E64 /* View Controllers */ = {
isa = PBXGroup;
children = (
4889982726FD3E68000E7394 /* Table View */,
944EBA2B227BB7D900C4C97B /* Basic */,
944EBA2C227BB7E100C4C97B /* Full Screen */,
DC3B2EBB222A5882000C8A4A /* Alert */,
Expand Down Expand Up @@ -572,6 +583,7 @@
74C072A5220BA76D00124CE1 /* PanModalHeight.swift in Sources */,
94795C9B21F0335D008045A0 /* PanModalPresentationDelegate.swift in Sources */,
943904F32226484F00859537 /* UserGroupStackedViewController.swift in Sources */,
4889982926FD3E81000E7394 /* TableViewController.swift in Sources */,
74C072AA220BA82A00124CE1 /* UIViewController+PanModalPresenter.swift in Sources */,
943904ED2226366700859537 /* AlertViewController.swift in Sources */,
743CABB22225FD1100634A5A /* UserGroupHeaderView.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions Sample/SampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private extension SampleViewController {
enum RowType: Int, CaseIterable {
case basic
case fullScreen
case tableView
case alert
case transientAlert
case userGroups
Expand All @@ -79,6 +80,7 @@ private extension SampleViewController {
switch self {
case .basic: return Basic()
case .fullScreen: return FullScreen()
case .tableView: return TableView()
case .alert: return Alert()
case .transientAlert: return TransientAlert()
case .userGroups: return UserGroup()
Expand All @@ -96,6 +98,11 @@ private extension SampleViewController {
let string: String = "Full Screen"
let rowVC: PanModalPresentable.LayoutType = FullScreenNavController()
}

struct TableView: RowPresentable {
let string: String = "Table View"
let rowVC: PanModalPresentable.LayoutType = TableViewController()
}

struct Alert: RowPresentable {
let string: String = "Alert"
Expand Down
55 changes: 55 additions & 0 deletions Sample/View Controllers/Table View/TableViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// TableViewController.swift
// PanModalDemo
//
// Created by Pedro Paulo de Amorim on 24/09/2021.
// Copyright © 2021 Detail. All rights reserved.
//

import Foundation
import UIKit

class TableViewController: UITableViewController, PanModalPresentable {

private let members = (0..<100).map { "Item \($0)" }

override func viewDidLoad() {
super.viewDidLoad()

setupTableView()
}

// MARK: - View Configurations

func setupTableView() {

tableView.contentInset = UIEdgeInsets(top: 44.0, left: 0.0, bottom: 0.0, right: 0.0)
tableView.separatorStyle = .none
tableView.backgroundColor = #colorLiteral(red: 0.1019607843, green: 0.1137254902, blue: 0.1294117647, alpha: 1)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}



override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return members.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? UITableViewCell
else { return UITableViewCell() }

cell.textLabel?.text = members[indexPath.row]
return cell
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60.0
}

var panScrollable: UIScrollView? {
return tableView
}

}
0