Skip to content

Commit

Permalink
1.4版本基本OK
Browse files Browse the repository at this point in the history
  • Loading branch information
豆子 authored and 豆子 committed Apr 15, 2023
1 parent 054ef1f commit c7fadf8
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 39 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions Love Browser/Extentions/Color+Extentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

Expand Down
3 changes: 2 additions & 1 deletion Love Browser/Love_BrowserApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,7 +35,7 @@ struct Love_BrowserApp: App {
if showWaitView {
WaitView()
} else {
ContentView()
ContentView(segmentModels: urlSessionManager.results)
.environment(\.managedObjectContext, CoreDataManager.shared.persistentContainer.viewContext)
}

Expand Down
3 changes: 2 additions & 1 deletion Love Browser/Managers/URLSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class URLSessionManager: ObservableObject {

results.insert(SegmentModel(label: "Home", items: [], isSelected: true), at: 0)
self.results = results

// 存储数据

print("data is ok")
}

Expand Down
6 changes: 5 additions & 1 deletion Love Browser/Views/BottomBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -125,8 +126,11 @@ struct BottomBar: View {
.fullScreenCover(isPresented: $openTabs) {

} content: {

TabsView {
openNewTabs()
} clickCurrentTab: { isHome in
clickCurrentTab(isHome)
}.environmentObject(tabManagerModel)

}
Expand Down
42 changes: 27 additions & 15 deletions Love Browser/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<HomeViewModel> {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {

Expand Down Expand Up @@ -179,6 +194,9 @@ struct ContentView: View {
showSearchIcon = true
tabManagerModel.addTab()

}, clickCurrentTab: { isHome in

isSearch = !isHome
}, clickHistoryCell: { url in

currentModel.isDesktop = false
Expand Down Expand Up @@ -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()
}
}


Expand Down
2 changes: 1 addition & 1 deletion Love Browser/Views/HomePageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct HomePageView: View {
// 隐藏键盘
clickCancleButton()
}
.padding(.top, 20)
.padding(.top, 5)

}
.opacity(tvViewModel.count != 0 ? 0 : 1)
Expand Down
51 changes: 31 additions & 20 deletions Love Browser/Views/SegmentedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,41 @@ 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 {

ScrollView(.horizontal, showsIndicators: false) {

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)

Expand All @@ -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
}
}

Expand Down
2 changes: 2 additions & 0 deletions Love Browser/Views/TabsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -77,6 +78,7 @@ struct TabsView: View {
)
.onTapGesture {
tabManagerModel.selectTab(targetModel: homeViewModel)
clickCurrentTab(homeViewModel.webViewModel.title == "" ? true : false)
presentationMode.wrappedValue.dismiss()
}

Expand Down

0 comments on commit c7fadf8

Please sign in to comment.