'I don't know what to put in the view placeholder
I keep getting an error to insert "proxy: /GeometryProxy/" even when "proxy" is a state variable. I have the code for the preview below. I don't know what to put in the placeholder and I am confused. I have included my full code to review. Please look below.
struct MathematicallyMainController_Previews: PreviewProvider {
static var previews: some View {
MathematicallyMainController(proxy: // what do i put here?)
}
}
My full code:
This is where the problem with the 'var' is happening.
struct MathematicallyMainController: View {
@StateObject var tabBarModel = TabBarViewModel()
@Environment(\.colorScheme) var colorScheme
@State var selectedIndex = 0
@State var isSelectedA = false
@State var isSelectedB = false
@State var isSelectedC = false
@State var isSelectedD = false
@State var isSelectedE = false
@State var proxy: GeometryProxy
var body: some View {
ZStack {
let bottomEdge = proxy.safeAreaInsets.bottom
switch selectedIndex {
case 0:
HomeViewController()
case 1:
BrowseView()
case 2:
RewardsView()
case 3:
EssentialsView()
case 4:
SchoolModeView()
default:
HomeViewController()
}
ZStack {
RoundedRectangle(cornerRadius: 15)
.fill(.regularMaterial)
.colorScheme(colorScheme == .dark ? .dark : .light)
HStack(alignment: .center) {
Button {
selectedIndex = 0
} label: {
if selectedIndex == 0 {
ZStack {
Circle()
.blur(radius: 20)
.foregroundColor(.blue)
.frame(width: 60)
.padding([.leading, .trailing], 5)
Image(systemName: "house.fill")
.font(.title)
.foregroundColor(colorScheme == .dark ? .black : .white)
.padding([.leading, .trailing], 5)
}
} else {
Image(systemName: "house.fill")
.font(.title)
.foregroundColor(colorScheme == .dark ? .white : .black)
}
}
Button {
selectedIndex = 1
} label: {
if selectedIndex == 1 {
ZStack {
Circle()
.blur(radius: 20)
.foregroundColor(.indigo)
.frame(width: 60)
.padding(.leading, 15)
Image(systemName: "rectangle.stack.fill")
.font(.title)
.foregroundColor(colorScheme == .dark ? .black : .white)
.padding(.leading, 15)
}
} else {
Image(systemName: "rectangle.stack.fill")
.font(.title)
.foregroundColor(colorScheme == .dark ? .white : .black)
.padding(.leading, 15)
}
}
Button {
selectedIndex = 2
} label: {
if selectedIndex == 2 {
ZStack {
Circle()
.blur(radius: 20)
.foregroundColor(.orange)
.frame(width: 60)
.padding([.trailing, .leading], 15)
Image(systemName: "circle.dotted")
.font(.title)
.foregroundColor(colorScheme == .dark ? .black : .white)
.padding([.trailing, .leading], 15)
}
} else {
Image(systemName: "circle.dotted")
.font(.title)
.foregroundColor(colorScheme == .dark ? .white : .black)
.padding(.trailing, 15)
.padding(.leading, 15)
}
}
Button {
selectedIndex = 3
} label: {
if selectedIndex == 3 {
ZStack {
Circle()
.blur(radius: 20)
.foregroundColor(.green)
.frame(width: 60)
.padding(.trailing, 15)
Image(systemName: "doc.text.image")
.font(.title)
.foregroundColor(colorScheme == .dark ? .black : .white)
.padding(.trailing, 15)
}
} else {
Image(systemName: "doc.text.image")
.font(.title)
.foregroundColor(colorScheme == .dark ? .white : .black)
.padding(.trailing, 15)
}
}
Button {
selectedIndex = 4
} label: {
if selectedIndex == 4 {
ZStack {
Circle()
.blur(radius: 20)
.foregroundColor(.purple)
.frame(width: 60)
.padding([.leading, .trailing], 5)
Image(systemName: "graduationcap.fill")
.font(.title)
.foregroundColor(colorScheme == .dark ? .black : .white)
.padding([.leading, .trailing], 5)
}
} else {
Image(systemName: "graduationcap.fill")
.font(.title)
.foregroundColor(colorScheme == .dark ? .white : .black)
}
}
}
.colorScheme(colorScheme == .dark ? .dark : .light)
.padding(.horizontal)
}
.frame(height: 60)
.shadow(color: .primary, radius: -10)
.shadow(color: .black, radius: 10)
.padding([.horizontal])
.padding(.bottom)
.frame(maxHeight: .infinity, alignment: .bottom)
.modifier(OffsetModifier())
.environmentObject(tabBarModel)
.offset(y: tabBarModel.tabState == .floating ? 0 : bottomEdge)
}
}
}
This is my ViewModifier I have included to create the scrolling animation.
struct OffsetModifier: ViewModifier {
@EnvironmentObject var model: TabBarViewModel
func body(content: Content) -> some View {
content
.overlay(
GeometryReader { proxy -> Color in
let minY = proxy.frame(in: .global).minY
DispatchQueue.main.async {
let durationOffset: CGFloat = 35
if minY < model.offset {
if model.offset < 0 && -minY > (model.lastStoredOffset + durationOffset) {
withAnimation(.easeOut.speed(1)) {
model.tabState = .floating
}
model.lastStoredOffset = -model.offset
}
}
if minY > model.offset && -minY < (model.lastStoredOffset + durationOffset) {
withAnimation(.easeOut.speed(1)) {
model.tabState = .expanded
}
model.lastStoredOffset = -model.offset
}
model.offset = minY
}
return Color.clear
}
,alignment: .top
)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
