Unify editMode in ProfilePickerSheet

This commit is contained in:
世界
2025-12-04 18:55:37 +08:00
parent ac638567f5
commit 8ecbd3ab6c
@@ -13,9 +13,7 @@ struct ProfilePickerSheet: View {
@Binding var profileList: [ProfilePreview] @Binding var profileList: [ProfilePreview]
@Binding var selectedProfileID: Int64 @Binding var selectedProfileID: Int64
#if os(iOS) #if !os(macOS)
@State private var legacyEditMode: EditMode = .inactive
#elseif os(tvOS)
@State private var editMode: EditMode = .inactive @State private var editMode: EditMode = .inactive
#else #else
@State private var isEditing = false @State private var isEditing = false
@@ -29,9 +27,7 @@ struct ProfilePickerSheet: View {
#endif #endif
private var isEditingActive: Bool { private var isEditingActive: Bool {
#if os(iOS) #if !os(macOS)
legacyEditMode.isEditing
#elseif os(tvOS)
editMode.isEditing editMode.isEditing
#else #else
isEditing isEditing
@@ -42,8 +38,10 @@ struct ProfilePickerSheet: View {
#if os(iOS) #if os(iOS)
if #available(iOS 26, *) { if #available(iOS 26, *) {
iOSBody iOSBody
.environment(\.editMode, $editMode)
} else { } else {
legacyIOSBody legacyIOSBody
.environment(\.editMode, $editMode)
} }
#else #else
nonIOSBody nonIOSBody
@@ -71,12 +69,11 @@ struct ProfilePickerSheet: View {
private var legacyIOSBody: some View { private var legacyIOSBody: some View {
legacyListContent legacyListContent
.environment(\.editMode, $legacyEditMode)
.toolbar { .toolbar {
ToolbarItem(placement: .primaryAction) { ToolbarItem(placement: .primaryAction) {
Button(legacyEditMode.isEditing ? "Done" : "Edit") { Button(editMode.isEditing ? "Done" : "Edit") {
withAnimation { withAnimation {
legacyEditMode = legacyEditMode.isEditing ? .inactive : .active editMode = editMode.isEditing ? .inactive : .active
} }
} }
} }
@@ -170,7 +167,6 @@ struct ProfilePickerSheet: View {
ProfilePickerRow( ProfilePickerRow(
profile: profile, profile: profile,
isSelected: profile.id == selectedProfileID, isSelected: profile.id == selectedProfileID,
isEditing: isEditingActive,
isMoving: movingProfileID == profile.id, isMoving: movingProfileID == profile.id,
alert: $alert, alert: $alert,
focusedProfileID: $focusedProfileID, focusedProfileID: $focusedProfileID,
@@ -272,7 +268,7 @@ struct ProfilePickerSheet: View {
#if os(iOS) #if os(iOS)
@ViewBuilder @ViewBuilder
private var legacyListContent: some View { private var legacyListContent: some View {
if legacyEditMode.isEditing { if editMode.isEditing {
legacyEditingList legacyEditingList
} else { } else {
legacyNormalList legacyNormalList
@@ -458,13 +454,13 @@ struct ProfilePickerSheet: View {
private struct ProfilePickerRow: View { private struct ProfilePickerRow: View {
@EnvironmentObject private var environments: ExtensionEnvironments @EnvironmentObject private var environments: ExtensionEnvironments
#if os(iOS) #if !os(macOS)
@Environment(\.editMode) private var editMode @Environment(\.editMode) private var editMode
#endif #endif
let profile: ProfilePreview let profile: ProfilePreview
let isSelected: Bool let isSelected: Bool
#if os(tvOS) || os(macOS) #if os(macOS)
let isEditing: Bool let isEditing: Bool
#endif #endif
#if os(tvOS) #if os(tvOS)
@@ -484,7 +480,7 @@ private struct ProfilePickerRow: View {
let onToggleMoving: () -> Void let onToggleMoving: () -> Void
#endif #endif
#if os(iOS) #if !os(macOS)
private var isEditing: Bool { private var isEditing: Bool {
editMode?.wrappedValue.isEditing ?? false editMode?.wrappedValue.isEditing ?? false
} }