Skip to content

Commit 173620a

Browse files
committed
Add CustomState use case in Samples app
1 parent 805f610 commit 173620a

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

Examples/Samples/Samples.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
545DBA0321511E6400CA77B8 /* SampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545DBA0221511E6400CA77B8 /* SampleTests.swift */; };
1616
545DBA0E21511E6400CA77B8 /* SampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 545DBA0D21511E6400CA77B8 /* SampleUITests.swift */; };
1717
546341A125C6415100CA0596 /* UseCases.swift in Sources */ = {isa = PBXBuildFile; fileRef = 546341A025C6415100CA0596 /* UseCases.swift */; };
18+
546341AC25C6426500CA0596 /* CustomState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 546341AB25C6426500CA0596 /* CustomState.swift */; };
1819
549D23CB233C7779008EF4D7 /* FloatingPanel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 549D23CA233C7779008EF4D7 /* FloatingPanel.framework */; };
1920
549D23CC233C7779008EF4D7 /* FloatingPanel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 549D23CA233C7779008EF4D7 /* FloatingPanel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2021
54B51116216AFE5F0033A6F3 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B51115216AFE5F0033A6F3 /* Extensions.swift */; };
@@ -67,6 +68,7 @@
6768
545DBA0D21511E6400CA77B8 /* SampleUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleUITests.swift; sourceTree = "<group>"; };
6869
545DBA0F21511E6400CA77B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6970
546341A025C6415100CA0596 /* UseCases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UseCases.swift; sourceTree = "<group>"; };
71+
546341AB25C6426500CA0596 /* CustomState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomState.swift; sourceTree = "<group>"; };
7072
549D23CA233C7779008EF4D7 /* FloatingPanel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = FloatingPanel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7173
54B51115216AFE5F0033A6F3 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
7274
54CDC5D7215BBE23007D205C /* UIComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIComponents.swift; sourceTree = "<group>"; };
@@ -157,6 +159,7 @@
157159
isa = PBXGroup;
158160
children = (
159161
546341A025C6415100CA0596 /* UseCases.swift */,
162+
546341AB25C6426500CA0596 /* CustomState.swift */,
160163
);
161164
path = UseCases;
162165
sourceTree = "<group>";
@@ -316,6 +319,7 @@
316319
files = (
317320
54CDC5D8215BBE23007D205C /* UIComponents.swift in Sources */,
318321
54B51116216AFE5F0033A6F3 /* Extensions.swift in Sources */,
322+
546341AC25C6426500CA0596 /* CustomState.swift in Sources */,
319323
546341A125C6415100CA0596 /* UseCases.swift in Sources */,
320324
545DB9F021511E6300CA77B8 /* ViewController.swift in Sources */,
321325
545DB9EE21511E6300CA77B8 /* AppDelegate.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// CustomStateSample.swift
3+
// Samples
4+
//
5+
// Created by Shin Yamamoto on 2021/01/31.
6+
// Copyright © 2021 scenee. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import FloatingPanel
11+
12+
class FloatingPanelLayoutWithCustomState: FloatingPanelBottomLayout {
13+
private struct AdditionalState {
14+
static let lastQuart: FloatingPanelState = FloatingPanelState(rawValue: "lastQuart", order: 750)
15+
static let firstQuart: FloatingPanelState = FloatingPanelState(rawValue: "firstQuart", order: 250)
16+
}
17+
override var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
18+
return [
19+
.full: FloatingPanelLayoutAnchor(absoluteInset: 0.0, edge: .top, referenceGuide: .safeArea),
20+
AdditionalState.lastQuart: FloatingPanelLayoutAnchor(fractionalInset: 0.75, edge: .bottom, referenceGuide: .safeArea),
21+
.half: FloatingPanelLayoutAnchor(fractionalInset: 0.5, edge: .bottom, referenceGuide: .safeArea),
22+
AdditionalState.firstQuart: FloatingPanelLayoutAnchor(fractionalInset: 0.25, edge: .bottom, referenceGuide: .safeArea),
23+
.tip: FloatingPanelLayoutAnchor(absoluteInset: 20.0, edge: .bottom, referenceGuide: .safeArea),
24+
]
25+
}
26+
}
27+

Examples/Samples/Sources/UseCases/UseCases.swift

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum UseCases: Int, CaseIterable {
5151
case .showTopPositionedPanel: return "Show Top Positioned Panel"
5252
case .showAdaptivePanel: return "Show Adaptive Panel"
5353
case .showAdaptivePanelWithCustomGuide: return "Show Adaptive Panel (Custom Layout Guide)"
54+
case .showCustomStatePanel: return "Show Panel with Custom state"
5455
}
5556
}
5657

@@ -76,6 +77,8 @@ enum UseCases: Int, CaseIterable {
7677
case .showAdaptivePanel,
7778
.showAdaptivePanelWithCustomGuide:
7879
return "ImageViewController"
80+
case .showCustomStatePanel:
81+
return nil
7982
}
8083
}
8184
}

Examples/Samples/Sources/ViewController.swift

+2
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ extension SampleListViewController: FloatingPanelControllerDelegate {
379379
fallthrough
380380
case .showContentInset:
381381
return FloatingPanelBottomLayout()
382+
case .showCustomStatePanel:
383+
return FloatingPanelLayoutWithCustomState()
382384
default:
383385
return (newCollection.verticalSizeClass == .compact) ? FloatingPanelBottomLayout() : self
384386
}

0 commit comments

Comments
 (0)