Dynamic header title
ibohonos opened this issue · comments
Hello!
if dynamic header title, page scroll not work
How fix this?
There is examle:
struct TestView: View {
var body: some View {
NavigationView {
VStack {
List {
NavigationLink(destination: GalleryView()) {
Text("Gallery View")
}
}
}
}
.navigationBarTitle(Text(""), displayMode: .inline)
}
}
struct GalleryView: View {
@State var index: Int = 0
func setupTitle(forPage page: Int) -> String {
switch page {
case 0: return "Extended"
case 1: return "PrePay"
case 2: return "Disabled"
default: return "Extended \(page)"
}
}
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("My Art Collection")
.font(.system(size: 40, weight: .bold))
.padding([.horizontal, .top])
ModelPages(paintings, currentPage: $index, hasControl: false) { i, painting in
PaintingView(painting: painting)
}
Spacer()
}
.navigationBarTitle(Text(setupTitle(forPage: index)), displayMode: .inline)
}
}
private struct PaintingView: View {
var painting: Painting
@State var list = ["One", "Two", "Three", "Four", "Five", "Six", "Seven"]
var body: some View {
VStack {
Image(painting.image)
.resizable()
.scaledToFit()
VStack(alignment: .leading) {
Text(painting.title)
.font(.system(size: 30, weight: .bold))
Text(painting.author)
.foregroundColor(.secondary)
}
List {
ForEach(list, id: \.self) {
Text($0)
}
.onMove { self.list.move(fromOffsets: $0, toOffset: $1) }
}
Button(action: {}) {
HStack {
Spacer()
Text("Buy for $\(painting.price)")
.fontWeight(.semibold)
.foregroundColor(.white)
.padding(.vertical)
Spacer()
}
.background(Color.blue)
.cornerRadius(10)
}
.padding(.top, 30)
Spacer()
}
.padding(.horizontal)
.environment(\.editMode, .constant(.active))
}
}
Hello! Have you solved the problem?