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

Swipe to dismiss #8

Closed
PauloxD opened this issue Oct 25, 2018 · 33 comments

Comments

Projects
None yet
5 participants
@PauloxD
Copy link

commented Oct 25, 2018

Hi just started using this library, and it is really clean, so well done on that.

Jut wondering how to go about performing a swipe to dismiss style move?

Thanks

@Yonodactyl

This comment has been minimized.

Copy link

commented Oct 25, 2018

Hey @PauloxD

Hope you are doing alright today.
Looking through the source code for the framework, it seems there is a func that can be called to dismiss the panel.

removePanelFromParent(animated: Bool, completion: (() -> Void)?

So once you have established a FloatingPanel variable, you can just call that function a little something like:

fpc.removePanelFromParent(animated: true, completion: nil)

This just performs a weak dismissal of the floatingPanel.

@PauloxD

This comment has been minimized.

Copy link
Author

commented Oct 25, 2018

Firstly, thank you for replying so quickly.

Yeah that makes sense, and I use that upon completing the form that I am using this library for. My issue is identifying that a swipe action has happened on the child controller, or a tap has happened on the parent controller. Does that make sense?

So, normally I would use the scroll delegate or touch delegate to calculate if the movement is a downward gesture.

Once again, thanks for replying

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Oct 26, 2018

@PauloxD, I really appreciate your comments,

a tap has happened on the parent controller.

On this case, this code might be your help.
https://github.com/SCENEE/FloatingPanel/blob/master/Examples/Samples/Sources/ViewController.swift#L127

a swipe action has happened on the child controller
I would use the scroll delegate or touch delegate to calculate if the movement is a downward gesture.

Now this library doesn't case of your use case. But I will investigate it's possible or not😀

You can still use delegate methods of a tracked scroll view in the child controller. Please note that you set a delegate object to a scroll view before tracking it.
https://github.com/SCENEE/FloatingPanel/blob/master/Framework/Sources/FloatingPanelController.swift#L261

@Urkman

This comment has been minimized.

Copy link

commented Oct 28, 2018

I'm also interested in some kind of Swipe to dismiss...
Because I don't want to display the Panel all the time. It should only appear if the user needs it and he should also be able to close it, after he uses it...

Would be grate to a example for this :)

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Oct 28, 2018

Thank you for your interesting. I'm considering how to achieve this use case for v1.2.0.
BTW, I'd like to clear the use case. Here is you expected one?

Detail Panel removable with a interaction

  1. Tap a table view cell in main screen (i.e. Stocks)
  2. Show a detail panel with 2 supported positions(half and full) (i.e. Stock detail)
  3. A user can dismiss the panel with a swipe gesture to the bottom at half positions or a close button at all positions.
@SCENEE

This comment has been minimized.

Copy link
Owner

commented Oct 29, 2018

For you information, here is a workaround.
But i'm planing to add a more clean API for the use case.

class ViewController: UIViewController, FloatingPanelControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        
           fpc = FloatingPanelController()
           fpc.delegate = self
           ...
   }
    func floatingPanel(_ vc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout? {
        return DismissiblePanelLayout()
    }
}

class DismissiblePanelLayout: FloatingPanelLayout {
    var initialPosition: FloatingPanelPosition = .half
    var supportedPositions: Set<FloatingPanelPosition> = [.half, .full, .tip]

    func insetFor(position: FloatingPanelPosition) -> CGFloat? {
        switch position {
        case .full: return 16.0
        case .half: return 216.0
        case .tip: return -88.0 // SEE HERE: Panel will be dismissed at the tip position 
        }
    }
}
@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 1, 2018

@PauloxD, @Urkman

Thank you for your patient. Could you please try 'add-removable-interaction' branch?
You can see a sample of a removable panel("Show Removable Panel") in Samples app.

https://github.com/SCENEE/FloatingPanel/pull/25/files#diff-b733e6931fa8657f8bc9ba741b879955R67

@SCENEE SCENEE closed this in #25 Nov 2, 2018

@Urkman

This comment has been minimized.

Copy link

commented Nov 2, 2018

Hi...

I took a look the the "emovable Panel" Example...
But for me "Swipe to Dismiss" is not working :(
I just can close it using the Close Button

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 3, 2018

Hmmm, Could you tell me your environment?

@Urkman

This comment has been minimized.

Copy link

commented Nov 3, 2018

Just Xcode 10.1 and iPhone XS Max in Simulator...

simulator screen shot - iphone xs max - 2018-11-03 at 07 46 16

@Urkman

This comment has been minimized.

Copy link

commented Nov 3, 2018

I did some more tests... And sometime it works, but most of time not :(
It works better, when I first swipe up and then swipe down to dismiss...

And for me it never works, when I "drag" the handle...

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 4, 2018

Thank you for your investigation. I'm going to investigate why it's unstable so I reopen this issue.

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 4, 2018

@Urkman,
I think I fix this issue on 'fix-removal-interaction' branch. Could you try it?
Thank you for your cooperation.

@Urkman

This comment has been minimized.

Copy link

commented Nov 4, 2018

Still not working for me :(
I try to grab the handle an pull it down. But it always slides back up...

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 4, 2018

I got it. The above implementation removed a floating panel just on swiping down with over a velocity. So I add a floating panel's coordinate Y condition to remove it and update the branch.
Now the new "Removable Pane" should behave as you like.

@Urkman

This comment has been minimized.

Copy link

commented Nov 5, 2018

Great... I will test it as soon i‘m in the office

@Urkman

This comment has been minimized.

Copy link

commented Nov 5, 2018

Works great :)

Thanks...

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 5, 2018

Thanks, too 👍

@SCENEE SCENEE closed this Nov 5, 2018

@Urkman

This comment has been minimized.

Copy link

commented Nov 5, 2018

Two more :(

1.) Orientation change not handled properly with "Removable panel"
2.) After "Swipe to dismiss" Panel is not removed.

Reproducible in Sample:

Working:
1.) click to show "Removable panel"
2.) Click Close Button
3.) Change Orientation
4.) Everything is fine (No panel shown)

Problem "Orientation Change":
1.) click to show "Removable panel"
2.) Change Orientation
3.) See, that Panel is not shown correctly
4.) Change Orientation back
5.) Panel is only show in lower third of the screen
6.) Try to swipe panel up to "half.
7.) Panel is dismissed

Problem "Panel not removed after Swipe to dismiss"
1.) click to show "Removable panel"
2.) swipe to dismiss panel
3.) Panel is dismissed
4.) Change Orientation
5.) Panel is show again :(

I hope my descriptions can help you to find the problem...

Thanks again for your great work. I will definitely use this in my next project :)

@Urkman

This comment has been minimized.

Copy link

commented Nov 5, 2018

And one more question...

Is there a delegate, that is called, when a panel is dismissed?

@Urkman

This comment has been minimized.

Copy link

commented Nov 6, 2018

I found the delegate "floatingPanelDidEndRemove"...
With this I can remove the Controller from it's parent :)
Problem "Panel not removed after Swipe to dismiss" can be handled with this :)

Leaves the "Orientation Change" Problem open...

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 7, 2018

Thanks, @Urkman! I know your comments now. I reopen again.

@SCENEE SCENEE reopened this Nov 7, 2018

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 7, 2018

I could find some additional bugs on orientation change. Thanks a lot.
I hope I would fix the above problem on PR #37. Could you please try PR #37 (fix-orientation-change-on-removal branch)?

Note: On fix-orientation-change-on-removal branch, you don't need to remove a floating panel from a parent VC in "floatingPanelDidEndRemove". FloatingPanelController owns it.

@Urkman

This comment has been minimized.

Copy link

commented Nov 7, 2018

Lock better, when I use fixed panel hights... BUT...

I want the panel to take exactly half the space of the screen.
So I use this to calculate the hight in my layout files:

For portrait:
let hight = max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height) / 2

For landscape:
let hight = min(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)

And then I get a crash on changing orientation from landscape to portrait:

2018-11-07 13:00:02.643397+0100 name[2353:535426] Assertion failed: Invalid insets: file /path/Pods/FloatingPanel/Framework/Sources/FloatingPanelLayout.swift, line 288

@Urkman

This comment has been minimized.

Copy link

commented Nov 7, 2018

To be more exact here:
func insetFor(position: FloatingPanelPosition) -> CGFloat? { switch position { case .full: return 16.0 case .half: return 380 default: return nil } }

With this in my Portrait Layout File the crashes on my iPhone XS Max on location change from landscape to portrait

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 8, 2018

A crash happened by an assertion failure to your layout because it's invalid for landscape.

But it's confusing because it's a wrong time for this library to raise the assertion failed. It should be raised on changing orientation from portrait to landscape. This issue was fixed on 6e85afa.

If you configure an appropriate a layout for landscape, it can work. support-your-landscape-layout section can help you.

@Urkman

This comment has been minimized.

Copy link

commented Nov 8, 2018

Sorry, I don't get it :(
Why should my Layout for Landscape be invalid?

It opens fine in Landscape and it open fine in Portrait(other Layout)...
The problem raises on orientation change.

If I remove these asserts:
assert(middleY > topY, "Invalid insets") assert(bottomY > topY, "Invalid insets")

everything is fine and working correctly :)

On orientation change the middleY and bottomY values get negative for a moment and then it crashes... After the orientation change is finished all values are fine again.
middleY: -55.0 - tip: 16.0 bottomY: -55.0 - tip: 16.0

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 9, 2018

Why should my Layout for Landscape be invalid?

Hmmm...🤔, this is because a floating panel is displayed on iPhone XS Max as the below screen shot by func insetFor(position: FloatingPanelPosition) -> CGFloat? { switch position { case .full: return 16.0 case .half: return 380 default: return nil } }, if their assertions are removed.
simulator screen shot - iphone xs max - 2018-11-09 at 09 00 36

I guess your layout also defines var supportedPositions: Set<FloatingPanelPosition> { return [.full, .half] }.
Then the layout introduces topY: 104.0 and middleY: 0.0 / bottomY: 0.0 on iPhone XS Max.

topY = 88pt(nav bar) + 16pt = 104pt
middleY = 414pt(height) - 380pt + 34.0pt(safe area bottom) = 0pt
bottomY = 414pt(height) - 380pt + 34.0pt(safe area bottom) = 0pt

EDIT:
Now we discuss orientation change issue. we continue this discussion but I merge PR #37 to fix some other issues. Thanks

@Urkman

This comment has been minimized.

Copy link

commented Nov 15, 2018

I try to make a small example to show the orientation change problem...

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 15, 2018

Thanks, @Urkman. Could you please open a new issue?
I'd like to discuss the orientation problem in it. because I think the problem is different from this issue.

@trungnguyen1791

This comment has been minimized.

Copy link

commented Nov 15, 2018

@SCENEE I'm facing an issue that i can't swipe to show delete action on tableview in FloatingPanel.
When i disable this line flc.track(scrollView: vc.tableView), the swipe gesture on tableview works again. But without it i can't swipe to close panel.

For your information:.

  • using version 1.2.0.
  • you can disable this line case let contentVC as DebugTableViewController: mainPanelVC.track(scrollView: contentVC.tableView)
    and add
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
    to reproduce the issue
@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 16, 2018

Thanks, @trungnguyen1791! I will take care of it.

@SCENEE

This comment has been minimized.

Copy link
Owner

commented Nov 17, 2018

The original issue has already resolved on v1.2.0.
I would like to track the issue reported by @trungnguyen1791 on PR #56. So I close this.

@SCENEE SCENEE closed this Nov 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.