diff --git a/Love Browser.xcodeproj/project.xcworkspace/xcuserdata/drolmen.xcuserdatad/UserInterfaceState.xcuserstate b/Love Browser.xcodeproj/project.xcworkspace/xcuserdata/drolmen.xcuserdatad/UserInterfaceState.xcuserstate index c2b72c2..78f5e3e 100644 Binary files a/Love Browser.xcodeproj/project.xcworkspace/xcuserdata/drolmen.xcuserdatad/UserInterfaceState.xcuserstate and b/Love Browser.xcodeproj/project.xcworkspace/xcuserdata/drolmen.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Love Browser/Extentions/Color+Extentions.swift b/Love Browser/Extentions/Color+Extentions.swift index bed78c0..ccde981 100644 --- a/Love Browser/Extentions/Color+Extentions.swift +++ b/Love Browser/Extentions/Color+Extentions.swift @@ -16,6 +16,7 @@ public extension Color { static let lb_history = Color.init(0xF4F4F4) static let lb_section = Color.init(0x666666) static let lb_segment = Color.init(0x969799) + static let lb_segment_selected = Color.init(0x323233) } diff --git a/Love Browser/Love_BrowserApp.swift b/Love Browser/Love_BrowserApp.swift index a86d14c..54e4658 100644 --- a/Love Browser/Love_BrowserApp.swift +++ b/Love Browser/Love_BrowserApp.swift @@ -17,6 +17,7 @@ struct Love_BrowserApp: App { @Environment(\.scenePhase) private var scenePhase private let adCoordinator = AdCoordinator() + private let urlSessionManager = URLSessionManager() @State private var firstOpen = true @State private var showWaitView = true @@ -34,7 +35,7 @@ struct Love_BrowserApp: App { if showWaitView { WaitView() } else { - ContentView() + ContentView(segmentModels: urlSessionManager.results) .environment(\.managedObjectContext, CoreDataManager.shared.persistentContainer.viewContext) } diff --git a/Love Browser/Managers/URLSessionManager.swift b/Love Browser/Managers/URLSessionManager.swift index 695a131..ac38e5e 100644 --- a/Love Browser/Managers/URLSessionManager.swift +++ b/Love Browser/Managers/URLSessionManager.swift @@ -33,7 +33,8 @@ class URLSessionManager: ObservableObject { results.insert(SegmentModel(label: "Home", items: [], isSelected: true), at: 0) self.results = results - + // 存储数据 + print("data is ok") } diff --git a/Love Browser/Views/BottomBar.swift b/Love Browser/Views/BottomBar.swift index faf9240..fcf4dec 100644 --- a/Love Browser/Views/BottomBar.swift +++ b/Love Browser/Views/BottomBar.swift @@ -17,6 +17,7 @@ struct BottomBar: View { var openTabsView:() -> Void // open tabs 标签页 var saveBookMarkCategory:() -> Void var openNewTabs:() -> Void + var clickCurrentTab:(Bool) -> Void var clickHistoryCell:(String) -> Void var showHome = false @@ -52,7 +53,7 @@ struct BottomBar: View { } label: { - Image(tabManagerModel.canBack ? (appSettings.darkModeSettings ? "back_black" : "back_white") : (appSettings.darkModeSettings ? "back_grey" : "back_white")) + Image(showHome ? (appSettings.darkModeSettings ? "back_black" : "back_white") : (appSettings.darkModeSettings ? "back_grey" : "back_white")) .renderingMode(.original) .resizable() .aspectRatio(contentMode: .fit) @@ -125,8 +126,11 @@ struct BottomBar: View { .fullScreenCover(isPresented: $openTabs) { } content: { + TabsView { openNewTabs() + } clickCurrentTab: { isHome in + clickCurrentTab(isHome) }.environmentObject(tabManagerModel) } diff --git a/Love Browser/Views/ContentView.swift b/Love Browser/Views/ContentView.swift index 8aa9c60..8778caa 100644 --- a/Love Browser/Views/ContentView.swift +++ b/Love Browser/Views/ContentView.swift @@ -14,6 +14,7 @@ struct ContentView: View { @State private var text = "" @State private var tvViewModel: [ListModel] = [] + @State var segmentModels: [SegmentModel] @State private var showMore = false @State private var showSearchIcon = true @State private var showBack = false @@ -30,7 +31,6 @@ struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @ObservedObject var keyboardHeightHelper = KeyboardHeightHelper() @ObservedObject var textFieldManger = TextFieldManger() - @ObservedObject var urlSessionManager = URLSessionManager() @StateObject var appSettings = AppSetting() var homeViewModelList : Array { @@ -104,11 +104,17 @@ struct ContentView: View { .padding(.top, 10) } - SegmentedView(array: []) { model in - - tvViewModel = model + SegmentedView(segmentModels: segmentModels, array: []) { model in + + tvViewModel = model.items ?? [] + + if model.label == "Home" { + + clickHomeButton() + textFieldManger.textField.resignFirstResponder() + } } - .frame(height: isSearch ? 0 : 44) + .frame(height: isSearch ? 0 : 47) .opacity(isSearch ? 0 : 1) ZStack { @@ -142,12 +148,21 @@ struct ContentView: View { if !hideBottomView { BottomBar(clickHomeButton: { - - clickHomeButton() + if isSearch { + clickHomeButton() + } else { + textFieldManger.textField.becomeFirstResponder() + } }, clickBackButton: { - currentModel?.webViewModel.goBack() + if currentModel.webViewModel.webView.backForwardList.backList.count == 0 || currentModel.webViewModel.webView.backForwardList.backList.first?.url.absoluteString == "about:blank" { + + clickHomeButton() + + } else { + currentModel?.webViewModel.goBack() + } }, clickForwardButton: { @@ -179,6 +194,9 @@ struct ContentView: View { showSearchIcon = true tabManagerModel.addTab() + }, clickCurrentTab: { isHome in + + isSearch = !isHome }, clickHistoryCell: { url in currentModel.isDesktop = false @@ -230,21 +248,15 @@ struct ContentView: View { } func clickHomeButton() { - if isSearch { text = "" showBack = false isSearch = false showMore = false showSearchIcon = true - currentModel.webViewModel.webView.backForwardList.perform(Selector(("_removeAllItems"))) currentModel.webViewModel.webView.load(URLRequest(url: URL(string: "about:blank")!)) + currentModel.webViewModel.webView.backForwardList.perform(Selector(("_removeAllItems"))) pausePlay() currentModel?.isDesktop = true - - } else { - - textFieldManger.textField.becomeFirstResponder() - } } diff --git a/Love Browser/Views/HomePageView.swift b/Love Browser/Views/HomePageView.swift index ed11e44..43c0ebf 100644 --- a/Love Browser/Views/HomePageView.swift +++ b/Love Browser/Views/HomePageView.swift @@ -135,7 +135,7 @@ struct HomePageView: View { // 隐藏键盘 clickCancleButton() } - .padding(.top, 20) + .padding(.top, 5) } .opacity(tvViewModel.count != 0 ? 0 : 1) diff --git a/Love Browser/Views/SegmentedView.swift b/Love Browser/Views/SegmentedView.swift index d07a456..05da522 100644 --- a/Love Browser/Views/SegmentedView.swift +++ b/Love Browser/Views/SegmentedView.swift @@ -9,10 +9,11 @@ import SwiftUI struct SegmentedView: View { - @ObservedObject var urlSessionManager = URLSessionManager() + @EnvironmentObject var appSettings: AppSetting + @State var segmentModels: [SegmentModel] @State var array: [SegmentModel] - var clickSegmentItem: ([ListModel]) -> Void + var clickSegmentItem: (SegmentModel) -> Void var body: some View { @@ -20,28 +21,29 @@ struct SegmentedView: View { HStack { - ForEach($urlSessionManager.results, id: \.label) { $model in + ForEach($segmentModels, id: \.label) { $model in Button { - changeLinearGradient() - model.isSelected = true - clickSegmentItem(model.items ?? []) + + changeLinearGradient(label: model.label) + clickSegmentItem(model) } label: { - + VStack { Text(model.label) - .foregroundColor(Color.lb_segment) + .foregroundColor(model.isSelected ?? false ? (appSettings.darkModeSettings ? Color.lb_segment_selected : Color.white) : (appSettings.darkModeSettings ? Color.lb_segment : Color(white: 0.8))) .font(.system(size: 16)) - LinearGradient(colors: [Color.blue], startPoint: UnitPoint(x: 0, y: 0), endPoint: UnitPoint(x: 30, y: 0)) - .frame(height: 3) + + Rectangle() + .foregroundColor(Color.blue) + .frame(height: (3.0)) .opacity(model.isSelected ?? false ? 1 : 0) .padding(.top, -2) - - } } +// .background(Color.red) .buttonStyle(BorderlessButtonStyle()) .padding(.leading, 10) @@ -50,21 +52,30 @@ struct SegmentedView: View { } } - .padding(.top, 10) + .padding(.top, 8) .padding(.leading, 20) .padding(.trailing, 20) } - func changeLinearGradient() { - - for model in urlSessionManager.results { + func changeLinearGradient(label: String) { + + array.removeAll() + + for model in segmentModels { + var result = model - result.isSelected = false - self.array.append(result) + + if result.label == label { + + result.isSelected = true + } else { + result.isSelected = false + } + + array.append(result) } - - urlSessionManager.results = array + segmentModels = array } } diff --git a/Love Browser/Views/TabsView.swift b/Love Browser/Views/TabsView.swift index 6be00b6..ba6f0b3 100644 --- a/Love Browser/Views/TabsView.swift +++ b/Love Browser/Views/TabsView.swift @@ -16,6 +16,7 @@ struct TabsView: View { @State private var offset = CGSize.zero var openNewTabs:() -> Void + var clickCurrentTab:(Bool) -> Void let gridWidth = (UIScreen.main.bounds.width - 45) / 2 @@ -77,6 +78,7 @@ struct TabsView: View { ) .onTapGesture { tabManagerModel.selectTab(targetModel: homeViewModel) + clickCurrentTab(homeViewModel.webViewModel.title == "" ? true : false) presentationMode.wrappedValue.dismiss() }