Skip to content

Commit 8616bf0

Browse files
committed
app: Refactor panel resize logic
1 parent 85076a5 commit 8616bf0

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

CodeApp/Containers/MainScene.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ private struct MainView: View {
200200
.environmentObject(extensionManager.editorProviderManager)
201201

202202
if isPanelVisible {
203-
PanelView()
204-
.environmentObject(extensionManager.panelManager)
203+
PanelView(
204+
windowHeight: geometry.size.height
205+
)
206+
.environmentObject(extensionManager.panelManager)
205207
}
206208
}
207209
.blur(

CodeApp/Views/PanelView.swift

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,16 @@ struct PanelView: View {
128128
@SceneStorage("panel.height") var panelHeight: Double = DefaultUIState.PANEL_HEIGHT
129129

130130
@State var showSheet = false
131-
@State var keyboardHeight: CGFloat = 0.0
132131

133132
var maxHeight: CGFloat {
134-
UIScreen.main.bounds.height
133+
windowHeight
135134
- UIApplication.shared.getSafeArea(edge: .top)
136135
- UIApplication.shared.getSafeArea(edge: .bottom)
137-
- keyboardHeight
138136
- TOP_BAR_HEIGHT
139137
- EDITOR_MINIMUM_HEIGHT
140138
- BOTTOM_BAR_HEIGHT
141139
}
140+
var windowHeight: CGFloat
142141

143142
func evaluateProposedHeight(proposal: CGFloat) {
144143
if proposal < PANEL_MINIMUM_HEIGHT {
@@ -153,7 +152,7 @@ struct PanelView: View {
153152

154153
var body: some View {
155154
Implementation()
156-
.frame(height: CGFloat(panelHeight))
155+
.frame(height: min(CGFloat(panelHeight), maxHeight))
157156
.background(Color.init(id: "editor.background"))
158157
.gesture(
159158
DragGesture()
@@ -162,31 +161,5 @@ struct PanelView: View {
162161
evaluateProposedHeight(proposal: proposedNewHeight)
163162
}
164163
)
165-
.onReceive(
166-
NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)
167-
) { notification in
168-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
169-
evaluateProposedHeight(proposal: panelHeight)
170-
}
171-
}
172-
.onReceive(
173-
NotificationCenter.default.publisher(
174-
for: UIResponder.keyboardDidChangeFrameNotification),
175-
perform: { notification in
176-
if let keyboardSize =
177-
(notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?
178-
.cgRectValue
179-
{
180-
keyboardHeight = keyboardSize.height
181-
evaluateProposedHeight(proposal: panelHeight)
182-
}
183-
}
184-
)
185-
.onReceive(
186-
NotificationCenter.default.publisher(for: UIResponder.keyboardDidHideNotification),
187-
perform: { _ in
188-
keyboardHeight = 0.0
189-
}
190-
)
191164
}
192165
}

0 commit comments

Comments
 (0)