Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aheze committed Jun 6, 2022
1 parent eafd1bf commit bdf8f92
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
Binary file added Assets/SelfSizing.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Example/SplitSheetExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class ViewController: UIViewController {
/// Add the sheet.
embed(splitSheetController, inside: view)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

/// Show the sheet programmatically.
splitSheetController.show(true)
}
}

class MainViewController: UIViewController {
Expand Down
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A lightweight, fully interactive split-screen sheet.
- Gestures are fully interruptible.
- Won't affect buttons and gestures nested in subviews.
- Supports sizing detents (hidden, shown, expanded).
- Fully compatible with Auto Layout and self-sizing.
- Super simple, no dependencies, ~300 lines of code.
- Replicates iOS 15's sheet detents while supporting iOS 9+.

Expand Down Expand Up @@ -66,17 +67,15 @@ import SplitSheet
import UIKit

class ViewController: UIViewController {

/// Works with any view controller.
let mainViewController = MainViewController()
let sheetViewController = SheetViewController()
lazy var splitSheetController = SplitSheetController(
mainViewController: mainViewController,
sheetViewController: sheetViewController
)

override var childForStatusBarStyle: UIViewController? {
return splitSheetController
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -103,10 +102,41 @@ class ViewController: UIViewController {

/// Add the sheet.
embed(splitSheetController, inside: view)

splitSheetController.show(true)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

/// Show the sheet programmatically.
splitSheetController.show(true)
}

/// Propagate the splitSheetController's custom status bar to this view controller.
override var childForStatusBarStyle: UIViewController? {
return splitSheetController
}
}
```

### Self-Sizing and Detents
It's simple — if your sheet view controller's intrinsic size is larger than the `minimumSheetHeight`, a "large" detent will be added.

```swift
class SheetViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .systemTeal
view.heightAnchor.constraint(equalToConstant: 800).isActive = true
}
}
```

<img src="Assets/SelfSizing.gif" width="250" alt="Hidden, shown, and expanded modes.">


### Author
Popovers is made by [aheze](https://github.com/aheze).

Expand Down
3 changes: 1 addition & 2 deletions Sources/SplitSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ extension SplitSheetController: UIScrollViewDelegate {
let detents = [hiddenDetent, shownDetent, expandedDetent]
let predictedContentOffset = targetContentOffset.pointee.y /// Use the system-predicted target content to take care of flicking with the finger.

print("distanceToShown: \(distanceToShown)")
switch velocity.y {
/// When the velocity is negative (scrolled down.)
case ..<0:
Expand Down Expand Up @@ -309,7 +308,7 @@ extension SplitSheetController: UIScrollViewDelegate {
targetContentOffset.pointee.y = 0 /// Hide if near the bottom.
}
}

/// When the offset is 0, the sheet is hidden. Otherwise, it's shown.
updateShowing(targetContentOffset.pointee.y != 0)
}
Expand Down

0 comments on commit bdf8f92

Please sign in to comment.