Skip to content

Commit

Permalink
Use if else instead of switch for geomchange state
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Oct 23, 2024
1 parent b0cd656 commit bf79b72
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"location" : "https://github.com/sentryco/SplitViewKit",
"state" : {
"branch" : "main",
"revision" : "4a161f02bf0b47de844777f07ea7527fb1db0d87"
"revision" : "b0cd656c167a9a0289cf7225e5ddf67d9195ee07"
}
}
],
Expand Down
57 changes: 30 additions & 27 deletions Sources/SplitViewKit/util/GeometryChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,40 @@ import SwiftUI
// - Fixme: ⚠️️ move to columWidth file?
// - Fixme: ⚠️️ we might have to account for all cases, lets see if reordering the cases works first
func geometryChange(isLandscape: Bool, sizeClass: UserInterfaceSizeClass?, winWidth: CGFloat, closure: (_ winWidth: CGFloat) -> some View) -> some View {
switch true {
case isLandscape, sizeClass == .compact:
Swift.print("👉 isLandscape, compact")
return closure(winWidth)
case isLandscape, sizeClass == .regular, isNarrow(isLandscape: isLandscape, winWidth: winWidth):
Swift.print("👉 isLandscape, regular, isNarrow")
return closure(winWidth)
case isLandscape, sizeClass == .regular, !isNarrow(isLandscape: isLandscape, winWidth: winWidth):
Swift.print("👉 isLandscape, regular, fullscreen")
return closure(winWidth)
default:
Swift.print("👉 default")
return closure(winWidth) // else regular, not narrow, not landscape
if isLandscape { // - Fixme: ⚠️️ Add doc
if sizeClass == .compact { // this fixes things going into compact. but not 70% to regular
return closure(winWidth) // ⚠️️ This is the same as the other, but it refreshes the view, and recalculates columnwidths etc, which is what we need
} else { // if sizeClass == .regular
if isNarrow(isLandscape: isLandscape, winWidth: winWidth) {
return closure(winWidth) // ⚠️️ This is the same as the other, but it refreshes the view, and recalculates columnwidths etc, which is what we need
} else {
return closure(winWidth) // ⚠️️ This is the same as the other, but it refreshes the view, and recalculates columnwidths etc, which is what we need
}
}
} else {
return closure(winWidth) // ⚠️️ We can't load the same variable, or else it will not refresh. so we reference it again like this to referesh. seems strange but it is what it is, there might be another solution to this stange behaviour, more exploration could be ideal
}
}

// let _ = geometry.size.width > geometry.size.height // ⚠️️ For some reason we have to have this here, elaborate?: I thinkn its just because we have to reference geomtryreader to activate some internal mechanism etc
// switch true {
// case isLandscape, sizeClass == .compact:
// Swift.print("👉 isLandscape, compact")
// return closure(winWidth)
// case isLandscape, sizeClass == .regular, isNarrow(isLandscape: isLandscape, winWidth: winWidth):
// Swift.print("👉 isLandscape, regular, isNarrow")
// return closure(winWidth)
// case isLandscape, sizeClass == .regular, !isNarrow(isLandscape: isLandscape, winWidth: winWidth):
// Swift.print("👉 isLandscape, regular, fullscreen")
// return closure(winWidth)
// default:
// Swift.print("👉 default")
// return closure(winWidth) // else regular, not narrow, not landscape
// }


// let _ = geometry.size.width > geometry.size.height // ⚠️️ For some reason we have to have this here, elaborate?: I thinkn its just because we have to reference geomtryreader to activate some internal mechanism etc
// - Fixme: ⚠️️ maybe if we load new view on size change?
// if isLandscape { // - Fixme: ⚠️️ Add doc
// if sizeClass == .compact { // this fixes things going into compact. but not 70% to regular
// navigationSplitView(winWidth: geometry.size.width) // ⚠️️ This is the same as the other, but it refreshes the view, and recalculates columnwidths etc, which is what we need
// } else { // if sizeClass == .regular
// if columnWidth.isNarrow(isLandscape: isLandscape, winWidth: geometry.size.width) {
// navigationSplitView(winWidth: geometry.size.width) // ⚠️️ This is the same as the other, but it refreshes the view, and recalculates columnwidths etc, which is what we need
// } else {
// navigationSplitView(winWidth: geometry.size.width) // ⚠️️ This is the same as the other, but it refreshes the view, and recalculates columnwidths etc, which is what we need
// }
// }
// } else {
// navigationSplitView(winWidth: geometry.size.width) // ⚠️️ We can't load the same variable, or else it will not refresh. so we reference it again like this to referesh. seems strange but it is what it is, there might be another solution to this stange behaviour, more exploration could be ideal
// }
//


//internal struct GeometryChange: Equatable {
Expand Down

0 comments on commit bf79b72

Please sign in to comment.