mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-18 20:36:04 +00:00
Fix edit device name alert for macOS 12
This commit is contained in:
1 parent
ad1ab30b94
commit
7cdfdcd474
2 files changed
+41
-21
No files matched your search
@@ -8,25 +8,16 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import LUI
|
import LUI
|
||||||
|
|
||||||
struct ChangeDeviceNameModifier: ViewModifier {
|
struct ChangeDeviceNameAlertModifier: ViewModifier {
|
||||||
|
@Binding var isPresented: Bool
|
||||||
|
@State var customName = ""
|
||||||
|
|
||||||
let isEnabled: Bool
|
let maxLength = NearbyConnectionManager.maxNameChars
|
||||||
private let maxLength = NearbyConnectionManager.maxNameChars
|
|
||||||
|
|
||||||
@State private var isPresented = false
|
|
||||||
@State private var customName = ""
|
|
||||||
|
|
||||||
func body(content: Content) -> some View {
|
func body(content: Content) -> some View {
|
||||||
|
|
||||||
content
|
content
|
||||||
.onTapGesture {
|
|
||||||
guard isEnabled else { return }
|
|
||||||
|
|
||||||
lightVibration()
|
|
||||||
customName = NearbyConnectionManager.getCustomDeviceName() ?? ""
|
|
||||||
isPresented = true
|
|
||||||
}
|
|
||||||
.alert("ChangeDeviceName", isPresented: $isPresented) {
|
.alert("ChangeDeviceName", isPresented: $isPresented) {
|
||||||
|
|
||||||
TextField("DeviceName", text: $customName)
|
TextField("DeviceName", text: $customName)
|
||||||
.onChange(of: customName) { newValue in
|
.onChange(of: customName) { newValue in
|
||||||
if newValue.count > maxLength {
|
if newValue.count > maxLength {
|
||||||
@@ -35,18 +26,47 @@ struct ChangeDeviceNameModifier: ViewModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Button("Save") {
|
Button("Save") {
|
||||||
NearbyConnectionManager.shared
|
let trimmed = customName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
.setCustomDeviceName(to: customName.trimmingCharacters(in: .whitespacesAndNewlines))
|
NearbyConnectionManager.shared.setCustomDeviceName(to: trimmed)
|
||||||
}
|
}
|
||||||
|
|
||||||
Button("Cancel", role: .cancel) { }
|
Button("Cancel", role: .cancel) { }
|
||||||
|
|
||||||
} message: {
|
} message: {
|
||||||
Text("ChangeDeviceNameDescription")
|
Text("ChangeDeviceNameDescription")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
func changeDeviceNameAlert(
|
||||||
|
isPresented: Binding<Bool>,
|
||||||
|
) -> some View {
|
||||||
|
modifier(ChangeDeviceNameAlertModifier(
|
||||||
|
isPresented: isPresented
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct ChangeDeviceNameModifier: ViewModifier {
|
||||||
|
|
||||||
|
let isEnabled: Bool
|
||||||
|
|
||||||
|
@State private var isPresented = false
|
||||||
|
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
content
|
||||||
|
.onTapGesture {
|
||||||
|
guard isEnabled else { return }
|
||||||
|
|
||||||
|
lightVibration()
|
||||||
|
isPresented = true
|
||||||
|
}
|
||||||
|
.changeDeviceNameAlert(isPresented: $isPresented)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
func changeDeviceNameAlert(isEnabled: Bool = true) -> some View {
|
func changeDeviceNameAlert(isEnabled: Bool = true) -> some View {
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ struct SettingsView: View {
|
|||||||
@ObservedObject var settings = Settings.shared
|
@ObservedObject var settings = Settings.shared
|
||||||
@ObservedObject var connectionManager = NearbyConnectionManager.shared
|
@ObservedObject var connectionManager = NearbyConnectionManager.shared
|
||||||
|
|
||||||
|
@State private var isChangeDeviceNameAlertPresented = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|
||||||
LargeAppIconView(title: "Settings") {
|
LargeAppIconView(title: "Settings") {
|
||||||
@@ -46,11 +48,9 @@ struct SettingsView: View {
|
|||||||
.foregroundColor(.gray)
|
.foregroundColor(.gray)
|
||||||
|
|
||||||
Button("Edit") {
|
Button("Edit") {
|
||||||
|
isChangeDeviceNameAlertPresented.toggle()
|
||||||
}
|
}
|
||||||
.overlay(
|
.changeDeviceNameAlert(isPresented: $isChangeDeviceNameAlertPresented)
|
||||||
Color.clear
|
|
||||||
.contentShape(Rectangle()).changeDeviceNameAlert()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|||||||
Reference in new issue
Block a user