From f702624399e70cc7643fb24b9220d45431b3fc8d Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Mon, 12 Feb 2024 21:58:59 -0800 Subject: [PATCH] Add an example for accessibilityRepresentation --- AccessibilityTalk.xcodeproj/project.pbxproj | 14 ++++-- AccessibilityTalk/ContentView.swift | 3 ++ AccessibilityTalk/CustomSlider.swift | 51 +++++++++++++++++++++ AccessibilityTalk/ExampleSliderView.swift | 30 ++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 AccessibilityTalk/CustomSlider.swift create mode 100644 AccessibilityTalk/ExampleSliderView.swift diff --git a/AccessibilityTalk.xcodeproj/project.pbxproj b/AccessibilityTalk.xcodeproj/project.pbxproj index 74e4260..d8627e9 100644 --- a/AccessibilityTalk.xcodeproj/project.pbxproj +++ b/AccessibilityTalk.xcodeproj/project.pbxproj @@ -26,6 +26,8 @@ 96088D922B7B220200E062FB /* GoodDayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96088D912B7B220200E062FB /* GoodDayView.swift */; }; 96088D942B7B286E00E062FB /* CalendarBadView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96088D932B7B286E00E062FB /* CalendarBadView.swift */; }; 96088D962B7B300C00E062FB /* CalendarGoodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96088D952B7B300C00E062FB /* CalendarGoodView.swift */; }; + 96088D982B7B37B400E062FB /* CustomSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96088D972B7B37B400E062FB /* CustomSlider.swift */; }; + 96088D9A2B7B39C300E062FB /* ExampleSliderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96088D992B7B39C300E062FB /* ExampleSliderView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -49,6 +51,8 @@ 96088D912B7B220200E062FB /* GoodDayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoodDayView.swift; sourceTree = ""; }; 96088D932B7B286E00E062FB /* CalendarBadView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarBadView.swift; sourceTree = ""; }; 96088D952B7B300C00E062FB /* CalendarGoodView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarGoodView.swift; sourceTree = ""; }; + 96088D972B7B37B400E062FB /* CustomSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSlider.swift; sourceTree = ""; }; + 96088D992B7B39C300E062FB /* ExampleSliderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleSliderView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -83,21 +87,23 @@ children = ( 96088D612B797B7700E062FB /* AccessibilityTalkApp.swift */, 96088D652B797B7900E062FB /* Assets.xcassets */, - 96088D872B7AFE7D00E062FB /* BadGoodView.swift */, 96088D8D2B7B1BF300E062FB /* BadDayView.swift */, - 96088D912B7B220200E062FB /* GoodDayView.swift */, + 96088D872B7AFE7D00E062FB /* BadGoodView.swift */, 96088D932B7B286E00E062FB /* CalendarBadView.swift */, 96088D952B7B300C00E062FB /* CalendarGoodView.swift */, - 96088D8F2B7B20FE00E062FB /* DayState.swift */, 96088D632B797B7700E062FB /* ContentView.swift */, + 96088D972B7B37B400E062FB /* CustomSlider.swift */, + 96088D8F2B7B20FE00E062FB /* DayState.swift */, 96088D732B7980D700E062FB /* DynamicTypeAdaptiveView.swift */, 96088D792B79827D00E062FB /* ExampleFormBadView.swift */, 96088D772B7981EB00E062FB /* ExampleFormGoodView.swift */, + 96088D992B7B39C300E062FB /* ExampleSliderView.swift */, 96088D7F2B798DBE00E062FB /* FlexibleSizingBadUIView.swift */, 96088D812B79925200E062FB /* FlexibleSizingGoodUIView.swift */, 96088D892B7B009400E062FB /* FlexibleSizingUIView.swift */, 96088D752B7981DC00E062FB /* FlexibleSizingView.swift */, 96088D712B797FBA00E062FB /* FlipLayoutAxisView.swift */, + 96088D912B7B220200E062FB /* GoodDayView.swift */, 96088D672B797B7900E062FB /* Preview Content */, 96088D852B799B1400E062FB /* TextSizingView.swift */, ); @@ -182,7 +188,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 96088D9A2B7B39C300E062FB /* ExampleSliderView.swift in Sources */, 96088D762B7981DC00E062FB /* FlexibleSizingView.swift in Sources */, + 96088D982B7B37B400E062FB /* CustomSlider.swift in Sources */, 96088D962B7B300C00E062FB /* CalendarGoodView.swift in Sources */, 96088D742B7980D700E062FB /* DynamicTypeAdaptiveView.swift in Sources */, 96088D642B797B7700E062FB /* ContentView.swift in Sources */, diff --git a/AccessibilityTalk/ContentView.swift b/AccessibilityTalk/ContentView.swift index 14c2521..ffb2219 100644 --- a/AccessibilityTalk/ContentView.swift +++ b/AccessibilityTalk/ContentView.swift @@ -35,6 +35,9 @@ struct ContentView: View { .accessibilityLabel("Good SwiftUI Grid") } } + Section("6. Custom Controls") { + NavigationLink("Example SwiftUI Slider") { ExampleSliderView() } + } } .navigationTitle("Accessibility Demo") .navigationBarTitleDisplayMode(.inline) diff --git a/AccessibilityTalk/CustomSlider.swift b/AccessibilityTalk/CustomSlider.swift new file mode 100644 index 0000000..b0d0192 --- /dev/null +++ b/AccessibilityTalk/CustomSlider.swift @@ -0,0 +1,51 @@ +// +// CustomSlider.swift +// AccessibilityTalk +// +// Created by Work on 2024-02-12. +// + +import SwiftUI + +struct CustomSlider: View { + @Binding var value: Double + + var body: some View { + HStack(spacing: 0) { + Button { + value = max(0, value - 0.05) + } label: { + Image(systemName: "minus.circle") + .padding(8) + .contentShape(Rectangle()) + } + + Rectangle() + .fill(Color(.systemGray3)) + .clipShape(RoundedRectangle(cornerRadius: 4)) + .frame(height: 8) + .frame(minWidth: 60) + .overlay { + GeometryReader { geometry in + Rectangle() + .fill(Color.accentColor) + .clipShape(RoundedRectangle(cornerRadius: 4)) + .frame(width: value * geometry.size.width, height: 8) + .frame(maxWidth: .infinity, alignment: .leading) + } + } + + Button { + value = min(1, value + 0.05) + } label: { + Image(systemName: "plus.circle") + .padding(8) + .contentShape(Rectangle()) + } + } + } +} + +#Preview { + CustomSlider(value: .constant(0.42)) +} diff --git a/AccessibilityTalk/ExampleSliderView.swift b/AccessibilityTalk/ExampleSliderView.swift new file mode 100644 index 0000000..b7b4b4b --- /dev/null +++ b/AccessibilityTalk/ExampleSliderView.swift @@ -0,0 +1,30 @@ +// +// ExampleSliderView.swift +// AccessibilityTalk +// +// Created by Work on 2024-02-12. +// + +import SwiftUI + +struct ExampleSliderView: View { + @State private var badValue = 0.7 + + @State private var goodValue = 0.42 + + var body: some View { + BadGoodView("Custom Slider") { + CustomSlider(value: $badValue) + } good: { + CustomSlider(value: $goodValue) + .accessibilityRepresentation { + Slider(value: $goodValue) + } + } + + } +} + +#Preview { + ExampleSliderView() +}