-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service tab in settings use SwiftUI (#311)
* feat: add service tab screen use SwiftUI * feat: add service list move function * fix: Removed a file change * fix: service list order issue and UI change * style: format code * fix: change service tab frame size * feat: update the style of service list * style: auto update Localizable.xcstrings * perf: remove unused variables * fix: service list index of bounds issue and tap issue * fix: serviceTypes count is greater than services count, cause crash * perf: adjust service rowHeight to 30 * perf: hide scrollIndicators * fix: reset service list selection * feat: optimize tab selection window transition * fix: window frame not reset issue * fix: onTap conflict with onMove in service tab * fix: remove tap event print --------- Co-authored-by: tisfeng <[email protected]>
- Loading branch information
Showing
12 changed files
with
415 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Easydict/App/Assets.xcassets/service_cell_highlight.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "1.000", | ||
"green" : "0.847", | ||
"red" : "0.706" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0.251", | ||
"green" : "0.251", | ||
"red" : "0.251" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"sourceLanguage" : "en", | ||
"strings" : { | ||
"" : { | ||
|
||
}, | ||
"about" : { | ||
"comment" : "about", | ||
"localizations" : { | ||
|
23 changes: 23 additions & 0 deletions
23
Easydict/Feature/Utility/Swift/Binding/Binding+DidSet.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Binding+DidSet.swift | ||
// Easydict | ||
// | ||
// Created by phlpsong on 2024/1/6. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// Ref https://stackoverflow.com/a/62871938 | ||
// Toggle onChange not trigger issue | ||
extension Binding { | ||
func didSet(execute: @escaping (Value) -> Void) -> Binding { | ||
Binding( | ||
get: { self.wrappedValue }, | ||
set: { | ||
self.wrappedValue = $0 | ||
execute($0) | ||
} | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Easydict/Feature/Utility/Swift/Notification/Notification+Name.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Notification+Name.swift | ||
// Easydict | ||
// | ||
// Created by phlpsong on 2024/1/7. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Notification.Name { | ||
static let serviceHasUpdated = Notification.Name(EZServiceHasUpdatedNotification) | ||
} | ||
|
||
@objc public extension NSNotification { | ||
static let serviceHasUpdated = Notification.Name.serviceHasUpdated | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// ServiceItemView.swift | ||
// Easydict | ||
// | ||
// Created by phlpsong on 2024/1/6. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(macOS 13.0, *) | ||
struct ServiceItemView: View { | ||
@Binding var service: QueryService | ||
|
||
var toggleValueChanged: (Bool) -> Void | ||
|
||
var body: some View { | ||
HStack { | ||
Image(nsImage: NSImage(named: service.serviceType().rawValue) ?? NSImage()) | ||
.resizable() | ||
.frame(maxWidth: 18.0, maxHeight: 18.0) | ||
|
||
Text(service.name()) | ||
|
||
Toggle(isOn: $service.enabled.didSet(execute: { value in | ||
toggleValueChanged(value) | ||
})) {} | ||
.toggleStyle(.switch) | ||
.controlSize(.small) | ||
} | ||
.padding(4.0) | ||
} | ||
} | ||
|
||
@available(macOS 13, *) | ||
#Preview { | ||
let service = EZLocalStorage.shared().allServices(.mini).first ?? QueryService() | ||
return ServiceItemView(service: .constant(service)) { val in | ||
print("toggle value changed: \(val)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.