import SwiftUI
enum Testament: String {
case old, new
}
struct ContentView: View {
@State private var selectedTestament: Testament
init() {
let savedTestamentRawValue = UserDefaults.standard.string(forKey: "selectedTestament") ?? Testament.old.rawValue
_selectedTestament = State(initialValue: Testament(rawValue: savedTestamentRawValue) ?? .old)
}
var body: some View {
NavigationView {
VStack {
TabView(selection: $selectedTestament) {
BookListView(selectedTestament: $selectedTestament)
.tabItem {
Label("Old Testament", systemImage: "text.book.closed.fill")
}
.tag(Testament.old)
HomeView()
.tabItem {
Label("Home", systemImage: "house.fill")
}
BookListView(selectedTestament: $selectedTestament)
.tabItem {
Label("New Testament", systemImage: "text.book.closed.fill")
}
.tag(Testament.new)
}
.onChange(of: selectedTestament) { _ in
withAnimation(.easeInOut) {
UserDefaults.standard.set(selectedTestament.rawValue, forKey: "selectedTestament")
}
}
}
.navigationTitle("Beibel Santu")
}
}
}
struct BookListView: View {
@Binding var selectedTestament: Testament
@State private var scrollToTop = false
var body: some View {
VStack {
List {
ForEach(mockBookGroups(), id: \.self){ group in
Section(header: GroupHeader(symbolName: group.symbolName, title: group.title, bookCount: group.books.count)) {
ForEach(group.books, id: \.self) { book in
NavigationLink(destination: ChaptherView(testament: selectedTestament, book: book)) {
Text(book)
}
}
}
}
}
.id(scrollToTop ? UUID() : nil)
.onChange(of: selectedTestament) { _ in
scrollToTop.toggle()
}
}
}
func mockBookGroups() -> [BookGroup] {
switch selectedTestament {
case .old:
return [
BookGroup(title: "Buki di lei", books: ["Genesis", "Eksodo", "Levitiko", "Numbernan", "Deuteronomio"], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di historia", books: ["Josue", "Huesnan", "Ruth", "1 Samuel", "2 Samuel", "1 Reinan", "2 Reinan", "1 Kronikanan", "2 Kronikanan", "Esdras", "Nehemias", "Esther"], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di poesia", books: ["Job", "Salmonan", "Proverbionan", "Eklesiastes", "Kanto di tur kanto"], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di profetanan mayor", books: ["Isaias", "Jeremias", "Lamentashonnan", "Ezekiel", "Daniel"], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di profetanan menor", books: ["Oseas", "Joel", "Amos", "Abdias", "Jonas", "Mikeas", "Nahum", "Habakuk", "Sofonias", "Hageo", "Zakarias", "Malakias"], symbolName: "books.vertical.fill"),
]
case .new:
return [
BookGroup(title: "Buki di evangelio", books: ["Mateo", "Marko", "Lukas", "Juan",], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di echonan", books: ["Echonan",], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di kartanan de e apostelnan", books: ["Romanonan", "1 Korintionan", "2 Korintionan", "Galationan", "Efesionan", "Filipensenan", "Kolosensenan", "1 Tesalonisensenan", "2 Tesalonisensenan", "1 Timoteo", "2 Timoteo", "Tito", "Filemon", "Hebreonan", "Santiago", "1 Pedro", "2 Pedro", "1 Juan", "2 Juan", "3 Juan", "Judas",], symbolName: "books.vertical.fill"),
BookGroup(title: "Buki di revelashon", books: ["Revelashon",], symbolName: "books.vertical.fill"),
]
}
}
}
struct GroupHeader: View {
var symbolName: String?
var title: String
var bookCount: Int
var body: some View {
HStack {
ZStack {
Button(action: {
// Action when the button is tapped
}) {
Text("\(bookCount)")
.font(.title3)
.fontWeight(.bold)
.foregroundColor(Color.white)
.frame(width: 40, height: 24) // Set the width and height of the button
}
}
.background(Color.blue)
.cornerRadius(8) // Adjust the corner radius for a rounded look
if let symbolName = symbolName {
Image(systemName: symbolName)
.foregroundColor(.blue)
.imageScale(.large)
}
Text(" \(title)")
.font(.footnote)
.fontWeight(.medium)
.foregroundColor(Color("myBlue"))
}
}
}
// Update the TextView struct
struct ChapterButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) → some View {
configuration.label
.padding()
.background(
RoundedRectangle(cornerRadius: 8)
.fill(configuration.isPressed ? Color.white : Color.blue))
}
}
//Area Pa Modifika Kapitulo
struct ChaptherView: View {
let testament: Testament
let book: String
var body: some View {
List {
ForEach(chaptersForBook(), id: \.self) { index in
NavigationLink(destination: Text("Chapter \(index) Content")) {
HStack {
Image(systemName: "book.pages")
.foregroundColor(Color("myBlue"))
.font(.system(size: 18))
Text("Kapitulo \(index)")
}
.contentShape(Rectangle()) // Ensure the entire HStack is tappable
}
}
}
.navigationTitle(book) // Use navigationTitle directly
}
private func chaptersForBook() -> ClosedRange<Int> {
switch testament {
case .old:
switch book {
//Buki Di Lei
case "Genesis":
return 1...50
case "Eksodo":
return 1...40
case "Levitiko":
return 1...27
case "Numbernan":
return 1...36
case "Deuteronomio":
return 1...34
//Buki Di Historia
case "Josue":
return 1...24
case "Huesnan":
return 1...21
case "Ruth":
return 1...21
case "1 Samuel":
return 1...31
case "2 Samuel":
return 1...24
case "1 Reinan":
return 1...22
case "2 Reinan":
return 1...25
case "1 Kronikanan":
return 1...29
case "2 Kronikanan":
return 1...36
case "Esdras":
return 1...10
case "Nehemias":
return 1...13
case "Esther":
return 1...10
//Buki Di Poesia
case "Job":
return 1...42
case "Salmonan":
return 1...150
case "Proverbionan":
return 1...31
case "Eklesiastes":
return 1...12
case "Kanto di tur kanto":
return 1...8
//Buki Di Profetanan mayor
case "Isaias":
return 1...66
case "Jeremias":
return 1...52
case "Lamentashonnan":
return 1...5
case "Ezekiel":
return 1...48
case "Daniel":
return 1...12
//Buki Di Profetanan menor
case "Oseas":
return 1...14
case "Joel":
return 1...3
case "Amos":
return 1...9
case "Abdias":
return 1...1
case "Jonas":
return 1...4
case "Mikeas":
return 1...7
case "Nahum":
return 1...3
case "Habakuk":
return 1...3
case "Sofonias":
return 1...3
case "Hageo":
return 1...2
case "Zakarias":
return 1...14
case "Malakias":
return 1...4
// Add cases for other books in the Old Testament...
default:
return 1...1
//End Of Old Testament
}
case .new:
switch book {
//Buki Di Evangelio
case "Mateo":
return 1...28
case "Marko":
return 1...16
case "Lukas":
return 1...24
case "Juan":
return 1...21
//Buki Di Echonan
case "Echonan":
return 1...28
//Buki Di Kartanan Di e Apostelnan
case "Romanonan":
return 1...16
case "1 Korintionan":
return 1...16
case "2 Korintionan":
return 1...13
case "Galationan":
return 1...6
case "Efesionan":
return 1...6
case "Filipensenan":
return 1...4
case "Kolosensenan":
return 1...4
case "1 Tesalonisensenan":
return 1...5
case "2 Tesalonisensenan":
return 1...2
case "1 Timoteo":
return 1...6
case "2 Timoteo":
return 1...4
case "Tito":
return 1...3
case "Filemon":
return 1...1
case "Hebreonan":
return 1...13
case "Santiago":
return 1...5
case "1 Pedro":
return 1...5
case "2 Pedro":
return 1...3
case "1 Juan":
return 1...5
case "2 Juan":
return 1...1
case "3 Juan":
return 1...1
case "Judas":
return 1...1
//Buki Di Revelashon
case "Revelashon":
return 1...22
// Add cases for other books in the New Testament...
default:
return 1...5
//End Of New Testament
}
}
}
}
// Update the struct name to ChapterView
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct BookGroup: Identifiable, Hashable {
let id = UUID()
let title: String
let books: [String]
let symbolName: String?
init(title: String, books: [String], symbolName: String? = nil) {
self.title = title
self.books = books
self.symbolName = symbolName
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
static func == (lhs: BookGroup, rhs: BookGroup) -> Bool {
return lhs.id == rhs.id
}
}
if u can see. when I try to scroll. the title just freeze. and it doest want to animate. please check my code for me.