feat: yangshi

This commit is contained in:
jinyaqiu 2025-09-03 15:43:52 +08:00
parent b1cd957d0c
commit 55255bf0f8

View File

@ -26,19 +26,23 @@ struct PermissionManagementView: View {
// 1.
PermissionRow(
title: "Gallery Permissions",
isEnabled: photoLibraryStatus == .authorized
) {
requestPhotoLibraryPermission()
}
isEnabled: photoLibraryStatus == .authorized,
action: {
requestPhotoLibraryPermission()
},
openSettings: openAppSettings
)
.background(Color.white)
// 2.
PermissionRow(
title: "Notification Permissions",
isEnabled: notificationStatus == .authorized
) {
requestNotificationPermission()
}
isEnabled: notificationStatus == .authorized,
action: {
requestNotificationPermission()
},
openSettings: openAppSettings
)
.background(Color.white)
}
.background(Color.white)
@ -122,9 +126,11 @@ struct PermissionManagementView: View {
///
private func openAppSettings() {
if let url = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(url)
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString),
UIApplication.shared.canOpenURL(settingsUrl) else {
return
}
UIApplication.shared.open(settingsUrl)
}
}
@ -133,6 +139,14 @@ struct PermissionRow: View {
let title: String //
let isEnabled: Bool //
let action: () -> Void //
let openSettings: () -> Void //
init(title: String, isEnabled: Bool, action: @escaping () -> Void, openSettings: @escaping () -> Void) {
self.title = title
self.isEnabled = isEnabled
self.action = action
self.openSettings = openSettings
}
var body: some View {
Button(action: action) {
@ -145,18 +159,23 @@ struct PermissionRow: View {
Spacer()
//
Toggle("", isOn: .constant(isEnabled))
.labelsHidden()
.tint(Color.themePrimary)
.disabled(true)
.onAppear {
// 使
let themeColor = UIColor(Color.themePrimary)
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).onTintColor = themeColor
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).thumbTintColor = .white
// 使
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).backgroundColor = UIColor.clear
Toggle("", isOn: .init(
get: { isEnabled },
set: { newValue in
//
openSettings()
}
))
.labelsHidden()
.tint(Color.themePrimary)
.onAppear {
// 使
let themeColor = UIColor(Color.themePrimary)
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).onTintColor = themeColor
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).thumbTintColor = .white
// 使
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).backgroundColor = UIColor.clear
}
}
.padding()
}