Skip to content

Commit

Permalink
Add FloatingPanelController.nearbyPosition (#303)
Browse files Browse the repository at this point in the history
* Added nearbyPosition : always a position of a user's finger.
* debugging nearby position in Maps.app.
* Added test cases move with nearby position.
  • Loading branch information
ramrcram authored and scenee committed Jan 9, 2020
1 parent 3b11cdc commit 9c57089
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Examples/Maps/Maps/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class ViewController: UIViewController, MKMapViewDelegate, UISearchBarDelegate,
let progress = max(0.0, min((tipY - y) / 44.0, 1.0))
self.searchVC.tableView.alpha = progress
}
debugPrint("NearbyPosition : ",vc.nearbyPosition)
}

func floatingPanelWillBeginDragging(_ vc: FloatingPanelController) {
Expand Down
8 changes: 7 additions & 1 deletion Framework/Sources/FloatingPanelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ open class FloatingPanelController: UIViewController {
set { set(contentViewController: newValue) }
get { return _contentViewController }
}


/// The NearbyPosition determines that finger's nearby position.
public var nearbyPosition: FloatingPanelPosition {
let currentY = surfaceView.frame.minY
return floatingPanel.targetPosition(from: currentY, with: .zero)
}

public var contentMode: ContentMode = .static {
didSet {
guard position != .hidden else { return }
Expand Down
16 changes: 16 additions & 0 deletions Framework/Tests/FloatingPanelControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ class FloatingPanelControllerTests: XCTestCase {
XCTAssertEqual(delegate.position, .hidden)
XCTAssertEqual(fpc.surfaceView.frame.minY, fpc.originYOfSurface(for: .hidden))
}

func test_moveWithNearbyPosition() {
let delegate = FloatingPanelTestDelegate()
let fpc = FloatingPanelController(delegate: delegate)
XCTAssertEqual(delegate.position, .hidden)
fpc.showForTest()

XCTAssertEqual(fpc.nearbyPosition, .half)

fpc.hide()
XCTAssertEqual(fpc.nearbyPosition, .tip)

fpc.move(to: .full, animated: false)
XCTAssertEqual(fpc.nearbyPosition, .full)
XCTAssertEqual(fpc.surfaceView.frame.minY, fpc.originYOfSurface(for: .full))
}

func test_originSurfaceY() {
let fpc = FloatingPanelController(delegate: nil)
Expand Down

0 comments on commit 9c57089

Please sign in to comment.