Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pd95
Created May 28, 2022 09:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pd95/c29230a81f2ce23bc35dfbab9b169f2c to your computer and use it in GitHub Desktop.
Save pd95/c29230a81f2ce23bc35dfbab9b169f2c to your computer and use it in GitHub Desktop.
//
// 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)
}
@pd95
Copy link
Author

pd95 commented May 28, 2022

Scroll to end of EULA before showing "Accept"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment