Skip to content

Commit

Permalink
滑动时隐藏bottomView
Browse files Browse the repository at this point in the history
  • Loading branch information
豆子 authored and 豆子 committed Apr 3, 2023
1 parent 009bac3 commit 9fb12d7
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 58 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Love Browser/Views/BottomBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ struct BottomBar: View {
}

}
.frame(height: 30)
.padding(.bottom,10)
.frame(height: 0)
.padding(.bottom,18)
.padding([.horizontal,.top])

}
Expand Down
120 changes: 65 additions & 55 deletions Love Browser/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct ContentView: View {
@State private var showSearchedWords = false
@State private var backgroundImage = "default"
@State private var hideSearchView = false
@State private var hideBottomView = false
@State private var openQRCodeView = false
@State var openWallpaper = false
@State var canBack = false
Expand Down Expand Up @@ -124,69 +125,70 @@ struct ContentView: View {

}


BottomBar(clickHomeButton: {

if isSearch {
if !hideBottomView {
BottomBar(clickHomeButton: {

if isSearch {
text = ""
showBack = false
isSearch = false
showMore = false
showSearchIcon = true
currentModel.webViewModel.webView.backForwardList.perform(Selector(("_removeAllItems")))
pausePlay()
currentModel?.isDesktop = true

} else {

textFieldManger.textField.becomeFirstResponder()
}

}, clickBackButton: {

currentModel?.webViewModel.goBack()

}, clickForwardButton: {

currentModel?.webViewModel.goForward()

}, changeWallpaper: { str in

changeWallpaper(str: str)

}, openTabsView: {

currentModel.updatePreviewImage()

}, saveBookMarkCategory: {

if !currentModel.isDesktop {

if let str = currentModel.webViewModel.title, let link = currentModel.webViewModel.url?.absoluteString {
saveBookMarkCategory(title: str, url: link)
}

}

}, openNewTabs: {
text = ""
showBack = false
isSearch = false
showMore = false
showSearchIcon = true
currentModel.webViewModel.webView.backForwardList.perform(Selector(("_removeAllItems")))
pausePlay()
currentModel?.isDesktop = true
tabManagerModel.addTab()

} else {

textFieldManger.textField.becomeFirstResponder()
}

}, clickBackButton: {

currentModel?.webViewModel.goBack()

}, clickForwardButton: {

currentModel?.webViewModel.goForward()

}, changeWallpaper: { str in

changeWallpaper(str: str)

}, openTabsView: {

currentModel.updatePreviewImage()

}, saveBookMarkCategory: {

if !currentModel.isDesktop {
}, clickHistoryCell: { url in

if let str = currentModel.webViewModel.title, let link = currentModel.webViewModel.url?.absoluteString {
saveBookMarkCategory(title: str, url: link)
}
currentModel.isDesktop = false
isSearch = true
showMore = true
showBack = false
currentModel.updateUrl(url: url)

}

}, openNewTabs: {
text = ""
showBack = false
isSearch = false
showMore = false
showSearchIcon = true
tabManagerModel.addTab()

}, clickHistoryCell: { url in

currentModel.isDesktop = false
isSearch = true
showMore = true
showBack = false
currentModel.updateUrl(url: url)

} ,showHome: isSearch)
} ,showHome: isSearch)
}



}
.environmentObject(appSettings)
.environmentObject(tabManagerModel)
Expand Down Expand Up @@ -223,7 +225,7 @@ struct ContentView: View {


func addHomeWebView(model: HomeViewModel) -> some View {

HomeWebView(model: model,decidePolicy: { url in
text = url

Expand All @@ -239,6 +241,14 @@ struct ContentView: View {
saveSearchHistoryCategory(title: title, url: url)
}

}, didScroll: {

hideBottomView = true

}, didEndScroll: {

hideBottomView = false

}, clickHomePageItem: { url in
if url == "Wallpaper" {
openWallpaper.toggle()
Expand Down
10 changes: 10 additions & 0 deletions Love Browser/Views/HomeWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct HomeWebView: View {

var decidePolicy: (String) -> Void
var didFinish:(String, String) -> Void
var didScroll:() -> Void
var didEndScroll:() -> Void

var clickHomePageItem: (String) -> Void

Expand All @@ -31,6 +33,14 @@ struct HomeWebView: View {

didFinish(title, url)

} didScroll: {

didScroll()

} didEndScroll: {

didEndScroll()

}
.edgesIgnoringSafeArea(.bottom)
.opacity(model.isDesktop ? 0 : 1)
Expand Down
30 changes: 29 additions & 1 deletion Love Browser/Views/WebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct WebView: UIViewRepresentable {

var decidePolicy: (String) -> Void
var didFinish: (String, String) -> Void
var didScroll: () -> Void
var didEndScroll: () -> Void

func makeUIView(context: Context) -> some WKWebView {

Expand Down Expand Up @@ -42,6 +44,14 @@ struct WebView: UIViewRepresentable {

didFinish(title, url)

} didScroll: {

didScroll()

} didEndScroll: {

didEndScroll()

}
}

Expand All @@ -53,10 +63,14 @@ class WebViewCoordinator: NSObject,WKNavigationDelegate, WKUIDelegate, UIScrollV

var decidePolicy: (String) -> Void
var didFinish: (String, String) -> Void
var didScroll: () -> Void
var didEndScroll: () -> Void

init(decidePolicy: @escaping (String) -> Void = {_ in}, didFinish: @escaping (String, String) ->Void = {_, _ in }) {
init(decidePolicy: @escaping (String) -> Void = {_ in}, didFinish: @escaping (String, String) -> Void = {_, _ in }, didScroll:@escaping () -> Void, didEndScroll: @escaping () -> Void) {
self.decidePolicy = decidePolicy
self.didFinish = didFinish
self.didScroll = didScroll
self.didEndScroll = didEndScroll
}

func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
Expand Down Expand Up @@ -107,5 +121,19 @@ class WebViewCoordinator: NSObject,WKNavigationDelegate, WKUIDelegate, UIScrollV

return nil
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.isDragging) {
didScroll()
}
}

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
didEndScroll()
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
didEndScroll()
}

}

0 comments on commit 9fb12d7

Please sign in to comment.