diff --git a/AnchoredBottomSheet.podspec b/AnchoredBottomSheet.podspec index 843fe8e..4e454f7 100644 --- a/AnchoredBottomSheet.podspec +++ b/AnchoredBottomSheet.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'AnchoredBottomSheet' - s.version = '1.2.4' + s.version = '1.3.0' s.summary = 'iOS Maps like bottom sheet with configurable anchors and reusable pannable View' s.description = <<-DESC diff --git a/Example/AnchoredBottomSheet/ExampleTableViewDataSource.swift b/Example/AnchoredBottomSheet/ExampleTableViewDataSource.swift index 2d2355a..c5fbee8 100644 --- a/Example/AnchoredBottomSheet/ExampleTableViewDataSource.swift +++ b/Example/AnchoredBottomSheet/ExampleTableViewDataSource.swift @@ -23,7 +23,7 @@ class ExampleTableViewDataSource: NSObject { extension ExampleTableViewDataSource: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 20 + return 5 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { diff --git a/Example/AnchoredBottomSheet/ViewController.swift b/Example/AnchoredBottomSheet/ViewController.swift index 0eec3e9..f93685c 100644 --- a/Example/AnchoredBottomSheet/ViewController.swift +++ b/Example/AnchoredBottomSheet/ViewController.swift @@ -44,7 +44,7 @@ class ViewController: UIViewController { fileprivate func presentModal(at index: Int) { switch index { case 0: - presentModalWithStackView() + presentWithContentHeight() case 1: presentModalWithTableView() case 2: @@ -54,29 +54,11 @@ class ViewController: UIViewController { } } - private func presentModalWithStackView() { - let button1 = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 60)) - button1.backgroundColor = .green - - let button2 = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 60)) - button2.backgroundColor = .red - - let button3 = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 60)) - button3.backgroundColor = .yellow - - - let stackView = UIStackView() - stackView.axis = .vertical - stackView.spacing = 5 - stackView.distribution = .fillEqually - stackView.addArrangedSubview(button1) - stackView.addArrangedSubview(button2) - stackView.addArrangedSubview(button3) - - let configuration = BottomSheetViewConfiguration(contentView: stackView, + private func presentWithContentHeight() { + let configuration = BottomSheetViewConfiguration(contentView: data.tableView, parentViewController: self, - defaultPosition: .middle(), - positions: [.middle(), .top()], + defaultPosition: .byContent, + positions: [.byContent], isPullIndicatorNeeded: true, closeButtonIcon: UIImage(named: "icon16Close"), isDismissAllowed: true) @@ -112,26 +94,32 @@ class ViewController: UIViewController { extension ViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) presentModal(at: indexPath.row) } } extension ViewController: UITableViewDataSource { + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 80 + } + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 5 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath) + cell.textLabel?.numberOfLines = 0 switch indexPath.row { case 0: - cell.textLabel?.text = "Present with stackView" + cell.textLabel?.text = "Present tableView with it's content height" return cell case 1: - cell.textLabel?.text = "Present with tableView" + cell.textLabel?.text = "Present tableView with middle,\ntop and bottom anchors" return cell case 2: - cell.textLabel?.text = "Push \"split screen\"" + cell.textLabel?.text = "Push \"split screen\" with\naccessible background" return cell default: return UITableViewCell() diff --git a/Example/Podfile.lock b/Example/Podfile.lock index cae1541..67b26c1 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - AnchoredBottomSheet (1.2.0) + - AnchoredBottomSheet (1.3.0) DEPENDENCIES: - AnchoredBottomSheet (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - AnchoredBottomSheet: 67b3c0f44ed4e508c0bf66308c2c48f3c13973df + AnchoredBottomSheet: 61c3b5e7b7b448f24899ba2e1fcba6762cbc0b94 PODFILE CHECKSUM: 9d2fa57cad45113c77064b354f9582a45331dfbf diff --git a/Example/Pods/Local Podspecs/AnchoredBottomSheet.podspec.json b/Example/Pods/Local Podspecs/AnchoredBottomSheet.podspec.json index 72802ea..6c78a72 100644 --- a/Example/Pods/Local Podspecs/AnchoredBottomSheet.podspec.json +++ b/Example/Pods/Local Podspecs/AnchoredBottomSheet.podspec.json @@ -1,6 +1,6 @@ { "name": "AnchoredBottomSheet", - "version": "1.2.0", + "version": "1.3.0", "summary": "iOS Maps like bottom sheet with configurable anchors and reusable pannable View", "description": "This small library tries to achieve this goals:\n1. Provide an easy to use interface to create popup like controller with configurable anchor points\n2. Provide a reusable view that can be used without a popup for some UI cases (split screen for example). Used that way the BottomSheetView will handle it's own pan gesture", "homepage": "https://github.com/havebeenfitz/AnchoredBottomSheet", @@ -13,7 +13,7 @@ }, "source": { "git": "https://github.com/havebeenfitz/AnchoredBottomSheet.git", - "tag": "1.2.0" + "tag": "1.3.0" }, "platforms": { "ios": "10.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index cae1541..67b26c1 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -1,5 +1,5 @@ PODS: - - AnchoredBottomSheet (1.2.0) + - AnchoredBottomSheet (1.3.0) DEPENDENCIES: - AnchoredBottomSheet (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - AnchoredBottomSheet: 67b3c0f44ed4e508c0bf66308c2c48f3c13973df + AnchoredBottomSheet: 61c3b5e7b7b448f24899ba2e1fcba6762cbc0b94 PODFILE CHECKSUM: 9d2fa57cad45113c77064b354f9582a45331dfbf diff --git a/Example/Pods/Target Support Files/AnchoredBottomSheet/AnchoredBottomSheet-Info.plist b/Example/Pods/Target Support Files/AnchoredBottomSheet/AnchoredBottomSheet-Info.plist index 2a9158a..b6b2813 100644 --- a/Example/Pods/Target Support Files/AnchoredBottomSheet/AnchoredBottomSheet-Info.plist +++ b/Example/Pods/Target Support Files/AnchoredBottomSheet/AnchoredBottomSheet-Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.0 + 1.3.0 CFBundleSignature ???? CFBundleVersion diff --git a/README.md b/README.md index 703ad46..78d57ec 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,11 @@ ⚠️ SnapKit is no longer a dependency since 1.2.0 -## About +🎉 ByContent anchor mode is available since 1.3.0. BottomSheetView resizes itself to match the subviews content height as long as it's smaller than screen height - +## About +![Demo](https://user-images.githubusercontent.com/31866271/117659897-2ac1db80-b1a5-11eb-903e-bdd562fd8c38.gif) This is iOS Maps like anchored bottom sheet with configurable anchors and reusable `BottomSheetView`, that can be used inside provided modal controller or without it. @@ -40,6 +41,7 @@ Supported anchors: 2. Middle 3. Bottom 4. Fixed +5. By content Each anchor has associated value, which will override default height for this anchor. By content mode is not yet implemented, feel free to open a pull request. diff --git a/Sources/AnchoredBottomSheet/BottomSheetView.swift b/Sources/AnchoredBottomSheet/BottomSheetView.swift index 1221d8f..7a3f134 100644 --- a/Sources/AnchoredBottomSheet/BottomSheetView.swift +++ b/Sources/AnchoredBottomSheet/BottomSheetView.swift @@ -53,6 +53,10 @@ public class BottomSheetView: UIView { private var closeButton: UIButton? + private var maxSheetHeight: CGFloat { + UIScreen.main.bounds.height - UIApplication.shared.statusBarFrame.height + } + public init(configuration: BottomSheetViewConfiguration) { self.contentView = configuration.contentView self.parentViewController = configuration.parentViewController @@ -98,12 +102,17 @@ public class BottomSheetView: UIView { case .byContent: if let scrollView = contentView as? UIScrollView { let finalRect = scrollView.contentSize - byContentPositionHeight = finalRect.height + 70 + byContentPositionHeight = min(finalRect.height + 70, maxSheetHeight) } else { - let finalRect: CGRect = contentView.subviews.reduce(into: .zero) { rect, subview in - rect = rect.union(subview.frame) + if let scrollView = contentView as? UIScrollView { + let finalRect = scrollView.contentSize + byContentPositionHeight = min(finalRect.height + 70, maxSheetHeight) + } else { + let finalRect: CGRect = contentView.subviews.reduce(into: .zero) { rect, subview in + rect = rect.union(subview.frame) + } + byContentPositionHeight = finalRect.height } - byContentPositionHeight = finalRect.height } } }