Last active
July 19, 2021 06:38
-
-
Save alextrob/8d0e8a5767e6bed3b3921f7effbf32d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftUI | |
extension ScrollView { | |
/// Workaround for large titles flickering on collapse. Not applied for iOS 15+. | |
/// Based on https://stackoverflow.com/a/67270977/99714 but avoids a questionable API by using a concrete type. | |
func largeTitleFlickerWorkaround() -> some View { | |
Group { | |
if #available(iOS 15.0, *) { | |
self | |
} else { | |
GeometryReader { geo in | |
WorkaroundScrollView(axes: axes, showsIndicators: showsIndicators, content: content.padding(geo.safeAreaInsets)) | |
.edgesIgnoringSafeArea(.all) | |
} | |
} | |
} | |
} | |
private struct WorkaroundScrollView<ScrollViewContent: View>: View { | |
let axes: Axis.Set | |
let showsIndicators: Bool | |
let content: ScrollViewContent | |
var body: ScrollView<ScrollViewContent> { | |
ScrollView<ScrollViewContent>(axes, showsIndicators: showsIndicators, content: { content }) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
NavigationView { | |
ScrollView { | |
LazyVGrid(columns: [GridItem(.flexible(), spacing: 16), GridItem(.flexible(), spacing: 16)], alignment: .center, spacing: 32, pinnedViews: []) { | |
ForEach(0..<10) { _ in | |
Text("Hello, world!") | |
} | |
} | |
} | |
.largeTitleFlickerWorkaround() | |
.navigationTitle("Scroll me") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment