-
-
Save pd95/c29230a81f2ce23bc35dfbab9b169f2c 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
// | |
// ContentView.swift | |
// VisibleAfterFullTextReview | |
// | |
// Created by Philipp on 28.05.22. | |
// | |
// Based on the question found in the HWS SwiftUI forum | |
// https://www.hackingwithswift.com/forums/swiftui/swiftui-webview-are-we-at-the-bottom-of-the-scrollview/14576 | |
// | |
import SwiftUI | |
struct ContentView: View { | |
@State private var readToEnd = false | |
@State private var scrollViewHeight = CGFloat.infinity | |
@Namespace private var scrollViewNameSpace | |
var body: some View { | |
NavigationView { | |
VStack { | |
ScrollView { | |
Text(eula) | |
Text("hidden tag") | |
.hidden() | |
.background( | |
GeometryReader { proxy in | |
Color.clear | |
.onChange(of: proxy.frame(in: .named(scrollViewNameSpace))) { newFrame in | |
if newFrame.minY < scrollViewHeight { | |
readToEnd = true | |
} | |
} | |
} | |
) | |
.border(Color.red) | |
} | |
.background( | |
GeometryReader { proxy in | |
Color.clear | |
.onChange(of: proxy.size, perform: { newSize in | |
let _ = print("ScrollView: ", newSize) | |
scrollViewHeight = newSize.height | |
}) | |
} | |
) | |
.coordinateSpace(name: scrollViewNameSpace) | |
NavigationLink("Accept", destination: Text("Welcome and Thank you!")) | |
.opacity(readToEnd ? 1 : 0) | |
.animation(.default, value: readToEnd) | |
} | |
.padding(.horizontal) | |
.navigationTitle("EULA") | |
} | |
} | |
let eula = Array(repeating: """ | |
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. | |
""", count: 10).joined(separator: "").trimmingCharacters(in: .whitespacesAndNewlines) | |
} |
Author
pd95
commented
May 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment