Skip to content

Commit

Permalink
Single mode for all views #60: Move settings view from a sheet presen…
Browse files Browse the repository at this point in the history
…tation.
  • Loading branch information
filimo committed Jan 18, 2020
1 parent db168e0 commit ba4266c
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 36 deletions.
50 changes: 44 additions & 6 deletions ReaderTranslator.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
// SettingsView.swift
// ReaderTranslator
//
// Created by Viktor Kushnerov on 9/12/19.
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
// Created by Viktor Kushnerov on 18/1/20.
// Copyright © 2020 Viktor Kushnerov. All rights reserved.
//

import SwiftUI

struct SettingsView: View {
@ObservedObject var viewStore = ViewsStore.shared //TextField uses ViewsStore via enum AvailableView

@State var isShow = false
@ObservedObject var viewStore = ViewsStore.shared

var body: some View {
Button(action: { self.isShow = true }, label: { Text("Settings") })
.sheet(isPresented: $isShow) {
Group {
if viewStore.showSettings {
VStack {
ForEach(AvailableView.resiableViews, id: \.self) { view in
HStack {
Expand All @@ -24,20 +22,26 @@ struct SettingsView: View {
value: view.order,
formatter: NumberFormatter.localInt
).frame(width: 20)
Text(view.text)
Spacer()
Text(view.text).frame(width: 150, alignment: .leading)
TextField(
"",
value: view.width ,
value: view.width,
formatter: NumberFormatter.localCGFloat
).frame(width: 50)
}
.frame(width: 200)
}

Button(action: { self.isShow = false }, label: { Text("Close") }).padding()
}.padding()
Button(
action: { self.viewStore.showSettings = false },
label: { Text("Close") }
)
}
.padding()
.background(Color(NSColor.windowBackgroundColor))
.modifier(RoundedEdge(width: 2, color: .black, cornerRadius: 10))
.shadow(radius: 10)
}
}
}
}

Expand All @@ -46,4 +50,3 @@ struct SettingsView_Previews: PreviewProvider {
SettingsView()
}
}

4 changes: 2 additions & 2 deletions ReaderTranslator/Extentions/CGFloat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import Foundation


extension CGFloat {
//extension CGFloat {
// var localString: String {
// let formatter = NumberFormatter()
// formatter.string(from: NSNumber(value: self))
// }
}
//}
18 changes: 18 additions & 0 deletions ReaderTranslator/Modifiers/ButtonModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ButtonModifier.swift
// ReaderTranslator
//
// Created by Viktor Kushnerov on 18/1/20.
// Copyright © 2020 Viktor Kushnerov. All rights reserved.
//

import SwiftUI

struct ButtonModifier: ViewModifier {
func body(content: Content) -> some View {
content
.aspectRatio(contentMode: .fit)
.fixedSize(horizontal: true, vertical: false)
.padding([.top, .bottom], 8)
}
}
23 changes: 23 additions & 0 deletions ReaderTranslator/Modifiers/RoundedEdge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// RoundedEdge.swift
// ReaderTranslator
//
// Created by Viktor Kushnerov on 18/1/20.
// Copyright © 2020 Viktor Kushnerov. All rights reserved.
//

import SwiftUI

struct RoundedEdge: ViewModifier {
let width: CGFloat
let color: Color
let cornerRadius: CGFloat

func body(content: Content) -> some View {
content
.cornerRadius(cornerRadius - width)
.padding(width)
.background(color)
.cornerRadius(cornerRadius)
}
}
2 changes: 2 additions & 0 deletions ReaderTranslator/Stores/ViewsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ final class ViewsStore: ObservableObject {
@Published(key: "enabledViews") var enabledViews: Set<AvailableView> = [.reverso, .gTranslator]
@Published(key: "viewWidth") var viewWidth: [AvailableView: CGFloat] = [:]
@Published(key: "viewOrder") var viewOrder: [AvailableView: Int] = [:]

@Published var showSettings = false
}
11 changes: 8 additions & 3 deletions ReaderTranslator/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import SwiftUI

struct ContentView: View {
@ObservedObject var viewStore = ViewsStore.shared

init() {
#if os(macOS)
NSApplication.shared.servicesProvider = ServiceProvider()
Expand All @@ -16,9 +18,12 @@ struct ContentView: View {
}

var body: some View {
VStack(alignment: .leading) {
ReaderView()
StatusBarView()
ZStack {
VStack(alignment: .leading) {
ReaderView().blur(radius: viewStore.showSettings ? 1 : 0)
StatusBarView()
}
SettingsView()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ReaderTranslator/Views/StatusBarView/StatusBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct StatusBarView: View {
// gTranslatorNavbarView
speechHandler
playbackRateView
SettingsView()
StatusBarView_SettingsView()
StatusBarView_Sync()
}.padding(.trailing, 20)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// SettingsView.swift
// ReaderTranslator
//
// Created by Viktor Kushnerov on 9/12/19.
// Copyright © 2019 Viktor Kushnerov. All rights reserved.
//

import SwiftUI

struct StatusBarView_SettingsView: View {
// @ObservedObject var viewStore = ViewsStore.shared //TextField uses ViewsStore via enum AvailableView

var body: some View {
Button(action: { ViewsStore.shared.showSettings = true }, label: { Text("Settings") })
}
}

struct StatusBarView_SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView()
}
}

2 changes: 1 addition & 1 deletion ReaderTranslatorMac/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.8.12</string>
<string>1.8.13</string>
<key>CFBundleVersion</key>
<string>1800</string>
<key>LSApplicationCategoryType</key>
Expand Down
9 changes: 0 additions & 9 deletions ReaderTranslatorPlayer/Views/ViewModes/BookmarksView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ struct BookmarksView: View {
@ObservedObject var store = Store.shared
@ObservedObject var bookmarksStore = BookmarksStore.shared

struct ButtonModifier: ViewModifier {
func body(content: Content) -> some View {
content
.aspectRatio(contentMode: .fit)
.fixedSize(horizontal: true, vertical: false)
.padding([.top, .bottom], 8)
}
}

var body: some View {
VStack {
ScrollView {
Expand Down

0 comments on commit ba4266c

Please sign in to comment.