Skip to content

Commit

Permalink
Fine tune watchOS behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sbertix committed Aug 22, 2023
1 parent b085f11 commit 7ba5e56
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public struct CellContent: View {
.foregroundStyle(isSelected ? Color(.secondarySystemGroupedBackground) : .primary)
.clipShape(RoundedRectangle(cornerRadius: 8))
.contentShape(RoundedRectangle(cornerRadius: 8))
#elseif os(watchOS)
.background(isSelected ? Color.accentColor : .clear)
.foregroundStyle(isSelected ? AnyShapeStyle(.background) : AnyShapeStyle(.primary))
.clipShape(RoundedRectangle(cornerRadius: 8))
.contentShape(RoundedRectangle(cornerRadius: 8))
#elseif compiler(>=5.9) && os(visionOS)
.background(
isSelected ? AnyShapeStyle(.regularMaterial) : AnyShapeStyle(.clear),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public struct HeaderCellContent: View {
.foregroundStyle(isSelected ? Color(.secondarySystemGroupedBackground) : .accentColor)
#elseif os(macOS)
.foregroundStyle(.tint)
#elseif os(watchOS)
.foregroundStyle(isSelected ? .secondary : .primary)
.foregroundStyle(isSelected ? AnyShapeStyle(.background) : AnyShapeStyle(.tint))
#elseif compiler(>=5.9) && os(visionOS)
.foregroundStyle(.secondary)
#endif
Expand Down Expand Up @@ -69,6 +72,11 @@ public struct HeaderCellContent: View {
: nil
)
.contentShape(RoundedRectangle(cornerRadius: 8))
#elseif os(watchOS)
.background(isSelected ? Color.accentColor : .clear)
.foregroundStyle(isSelected ? AnyShapeStyle(.background) : AnyShapeStyle(.primary))
.clipShape(RoundedRectangle(cornerRadius: 8))
.contentShape(RoundedRectangle(cornerRadius: 8))
#elseif compiler(>=5.9) && os(visionOS)
.background(
isSelected
Expand Down
133 changes: 67 additions & 66 deletions Sources/SystemImagePicker/SystemImagePicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,79 +187,80 @@ public struct SystemImagePicker<Selection: Hashable, Value: Hashable>: View {
text: $query,
placement: .navigationBarDrawer(displayMode: .always)
)
#endif
#elseif !os(watchOS)
.safeAreaInset(edge: .bottom) {
// Let users invalidate their symbol
// without having to find it and toggle it.
if let onInvalidate, let systemImage = id(selection) {
Button(role: .destructive) {
selection = onInvalidate()
guard shouldAutoDismiss else { return }
// Immediately reflect the selection and
// dismiss the view.
onCommit(selection)
dismiss()
} label: {
HStack {
Image(systemName: systemImage)
.font(.headline)
.imageScale(.small)
Text("Deselect Symbol")
.font(.headline.smallCaps())
.padding(.top, 8)
.padding(.bottom, 10)
Image(systemName: "xmark")
.imageScale(.small)
.font(.footnote.bold())
.foregroundStyle(.secondary)
}
.lineLimit(1)
.fixedSize()
.padding(.horizontal, 12)
#if compiler(<5.9) || !os(visionOS)
.background(.tint, in: RoundedRectangle(cornerRadius: 8))
.contentShape(RoundedRectangle(cornerRadius: 8))
#else
.background(.regularMaterial, in: Capsule())
.contentShape(Capsule())
#endif
// Let users invalidate their symbol
// without having to find it and toggle it.
if let onInvalidate, let systemImage = id(selection) {
Button(role: .destructive) {
selection = onInvalidate()
guard shouldAutoDismiss else { return }
// Immediately reflect the selection and
// dismiss the view.
onCommit(selection)
dismiss()
} label: {
HStack {
Image(systemName: systemImage)
.font(.headline)
.imageScale(.small)
Text("Deselect Symbol")
.font(.headline.smallCaps())
.padding(.top, 8)
.padding(.bottom, 10)
Image(systemName: "xmark")
.imageScale(.small)
.font(.footnote.bold())
.foregroundStyle(.secondary)
}
.buttonStyle(.plain)
.foregroundStyle(.red)
.tint(.red.opacity(0.15))
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(.bar)
.overlay(Divider(), alignment: .top)
.lineLimit(1)
.fixedSize()
.padding(.horizontal, 12)
#if compiler(<5.9) || !os(visionOS)
.background(.tint, in: RoundedRectangle(cornerRadius: 8))
.contentShape(RoundedRectangle(cornerRadius: 8))
#else
.background(.regularMaterial, in: Capsule())
.contentShape(Capsule())
#endif
}
.buttonStyle(.plain)
.foregroundStyle(.red)
.tint(.red.opacity(0.15))
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(.bar)
.overlay(Divider(), alignment: .top)
}
#if !os(macOS)
.toolbar {
// The dismiss button.
ToolbarItem(placement: .cancellationAction) {
Button("Cancel", role: .cancel) {
defer { dismiss() }
// If auto-dismiss is off, do not commit changes.
guard shouldAutoDismiss else { return }
onCommit(selection)
}
}
#endif
#if !os(macOS)
.toolbar {
// The dismiss button.
ToolbarItem(placement: .cancellationAction) {
Button("Cancel", role: .cancel) {
defer { dismiss() }
// If auto-dismiss is off, do not commit changes.
guard shouldAutoDismiss else { return }
onCommit(selection)
}
// Only add the "Done" button when auto-dismiss is off.
ToolbarItem(placement: .confirmationAction) {
if !shouldAutoDismiss {
Button("Done") {
onCommit(selection)
dismiss()
}.disabled(initialSelection == selection)
}
}
// Only add the "Done" button when auto-dismiss is off.
ToolbarItem(placement: .confirmationAction) {
if !shouldAutoDismiss {
Button("Done") {
onCommit(selection)
dismiss()
}.disabled(initialSelection == selection)
}
}
#endif
// With `shouldAutoDismiss` set to off and changes
// being made, disable drag down to dismiss so the
// user has to explicitly pick whether to discard
// or confirm the selection.
.interactiveDismissDisabled(!shouldAutoDismiss && initialSelection != selection)
}
#endif
// With `shouldAutoDismiss` set to off and changes
// being made, disable drag down to dismiss so the
// user has to explicitly pick whether to discard
// or confirm the selection.
.interactiveDismissDisabled(!shouldAutoDismiss && initialSelection != selection)
}
}

Expand Down

0 comments on commit 7ba5e56

Please sign in to comment.