List {
//I Want This Button To Appear When User Over Scroll To Top
Button(action:{}, label: {
Text("Archive")
})
ForEach(0..<5) { item in
ChatButton()
}
.listRowInsets(EdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowPlatterColor(.clear)
Rectangle()
.frame(width: Sizes.width - 8, height: Sizes.h2)
.foregroundColor(Color("Background"))
.listRowInsets(EdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowPlatterColor(.clear)
CenteredTextButton(text: "Durumlar", textColor: Color("White"), isLink: true, destinationKey: "statuses", buttonAction: {})
.listRowInsets(EdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowPlatterColor(.clear)
}
我找到了这样的解决方案,但我不知道这是最好的方法。
struct ChatsView: View {
@State private var showArchived = false
@State private var navigationTitle = "Sohbet"
@State private var scrollAmount: CGPoint = CGPoint(x: 0, y: 0)
var body: some View {
NavigationView {
ScrollView {
VStack {
if(showArchived) {
CenteredIconButton(icon: "ArchiveIcon", text: "Arşivlenmiş", textColor: Color("White"), backgroundColor: Color("Background"))
.transition(.move(edge: .top))
.animation(.easeIn)
}
ForEach(0..<5) { item in
ChatButton()
}
.listRowInsets(EdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowPlatterColor(.clear)
Rectangle()
.frame(width: Sizes.width - 8, height: Sizes.h2)
.foregroundColor(Color("Background"))
.listRowInsets(EdgeInsets.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowPlatterColor(.clear)
NavigationLink(destination: StatusesView()) {
VStack(spacing: 0) {
Image("Statuses")
.resizable()
.frame(width: Sizes.h18, height: Sizes.h18)
Text("Durumlar")
.font(.system(size: Sizes.h16))
.foregroundColor(Color("White60"))
}
.frame(width: Sizes.width, height: Sizes.h42)
.background(Color("Background"))
.cornerRadius(Sizes.h10)
}
.buttonStyle(VerticalIconButtonStyle())
}
.background(GeometryReader { geometry in
Color.clear
.preference(key: ScrollOffsetPreferenceKey.self, value: geometry.frame(in: .named("scroll")).origin)
})
.onPreferenceChange(ScrollOffsetPreferenceKey.self) { value in
scrollAmount = value
if value.y > 50 {
showArchived = true
} else if value.y < 0 {
showArchived = false
}
}
}
.coordinateSpace(name: "scroll")
.toolbar {
ToolbarItem(placement: .topBarLeading) {
CircularButton(icon: "SettingsIcon",destinationKey: "settings", isLink: true)
}
ToolbarItem(placement: .topBarTrailing) {
CircularButton(icon: "NewChatIcon", destinationKey: "contacts", isLink: true)
}
}
.navigationTitle("Sohbet")
}
}
}