Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
The handling observable function
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Nov 10, 2023
1 parent c77a203 commit e88d4fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Sources/Brave/Frontend/Browser/PageZoom/PageZoomHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class PageZoomHandler: ObservableObject {
static let propertyName = "viewScale"
@Published var currentValue: Double = 1.0

required init(tab: Tab, isPrivateBrowsing: Bool) {
self.webView = tab.webView
required init(tab: Tab?, isPrivateBrowsing: Bool) {
self.webView = tab?.webView
self.isPrivateBrowsing = isPrivateBrowsing

// Private Browsing on Safari iOS always defaults to 100%, and isn't persistently saved.
Expand Down
53 changes: 29 additions & 24 deletions Sources/Brave/Frontend/Browser/PageZoom/PageZoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ private struct ZoomView: View {
var maxValue: Double
@Binding var value: Double

var onDecrement: ()
var onReset: ()
var onIncrement: ()
var onDecrement: () -> Void
var onReset: () -> Void
var onIncrement: () -> Void

var body: some View {
HStack(spacing: 0.0) {
Button(action: {
onDecrement
}) {
Button(action: onDecrement) {
Image(systemName: "minus")
.font(.system(.footnote).weight(.medium))
.foregroundColor(value == minValue ? .accentColor : Color(UIColor.braveLabel))
Expand All @@ -47,9 +45,7 @@ private struct ZoomView: View {

Divider()

Button(action: {
onIncrement
}) {
Button(action: onIncrement) {
Image(systemName: "plus")
.font(.system(.footnote).weight(.medium))
.foregroundColor(value == maxValue ? .accentColor : Color(UIColor.braveLabel))
Expand All @@ -64,9 +60,7 @@ private struct ZoomView: View {
}

private var resetZoomButton: some View {
Button(action: {
onReset
}) {
Button(action: onReset) {
Text(NSNumber(value: value), formatter: PageZoomView.percentFormatter)
.font(.system(.footnote).weight(.medium))
.foregroundColor((value == (isPrivateBrowsing ? 1.0 : Preferences.General.defaultPageZoomLevel.value)) ? .accentColor : Color(UIColor.braveLabel))
Expand Down Expand Up @@ -116,9 +110,9 @@ struct PageZoomView: View {
minValue: minValue,
maxValue: maxValue,
value: $zoomHandler.currentValue,
onDecrement: zoomHandler.changeZoomLevel(.decrement),
onReset: zoomHandler.reset(),
onIncrement: zoomHandler.changeZoomLevel(.increment))
onDecrement: decrement,
onReset: reset,
onIncrement: increment)
.frame(maxWidth: .infinity)
Button {
dismiss?()
Expand All @@ -134,14 +128,25 @@ struct PageZoomView: View {
}
.background(Color(UIColor.braveBackground))
}

private func increment() {
zoomHandler.changeZoomLevel(.increment)
}

private func reset() {
zoomHandler.reset()
}

private func decrement() {
zoomHandler.changeZoomLevel(.decrement)
}
}

//
//#if DEBUG
//struct PageZoomView_Previews: PreviewProvider {
// static var previews: some View {
// PageZoomView(zoomHandler: nil)
// .previewLayout(PreviewLayout.sizeThatFits)
// }
//}
//#endif
#if DEBUG
struct PageZoomView_Previews: PreviewProvider {
static var previews: some View {
PageZoomView(zoomHandler: PageZoomHandler(tab: nil, isPrivateBrowsing: false))
.previewLayout(PreviewLayout.sizeThatFits)
}
}
#endif

0 comments on commit e88d4fc

Please sign in to comment.