Skip to content

Commit 3a3d0d7

Browse files
committed
horizontal scroll updated for iPad split view 320 width
1 parent 38ace71 commit 3a3d0d7

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

iOSswiftUIa11yTechniques/iOSswiftUIa11yTechniques.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@
12801280
"$(inherited)",
12811281
"@executable_path/Frameworks",
12821282
);
1283-
MARKETING_VERSION = 13.4;
1283+
MARKETING_VERSION = 13.5;
12841284
PRODUCT_BUNDLE_IDENTIFIER = pauljadam.com.iOSswiftUIa11yTechniques;
12851285
PRODUCT_NAME = "$(TARGET_NAME)";
12861286
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1315,7 +1315,7 @@
13151315
"$(inherited)",
13161316
"@executable_path/Frameworks",
13171317
);
1318-
MARKETING_VERSION = 13.4;
1318+
MARKETING_VERSION = 13.5;
13191319
PRODUCT_BUNDLE_IDENTIFIER = pauljadam.com.iOSswiftUIa11yTechniques;
13201320
PRODUCT_NAME = "$(TARGET_NAME)";
13211321
PROVISIONING_PROFILE_SPECIFIER = "";

iOSswiftUIa11yTechniques/iOSswiftUIa11yTechniques/CarouselView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct CarouselView: View {
154154
.stroke(Color.gray.opacity(0.8), lineWidth: 2)
155155
)
156156
}
157+
.buttonStyle(PlainButtonStyle()) //PlainButtonStyle() will prevent button text from showing as low contrast when the button is pressed
157158
.padding(.vertical, 16)
158159
Spacer()
159160
}

iOSswiftUIa11yTechniques/iOSswiftUIa11yTechniques/HorizontalScrollView.swift

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct HorizontalScrollView: View {
2323
@Environment(\.horizontalSizeClass) var horizontalSizeClass
2424
@Environment(\.verticalSizeClass) var verticalSizeClass
2525
@State private var offset: CGFloat = 0
26+
@State private var geometryData: CGRect = .zero
2627

2728
private var darkGreen = Color(red: 0 / 255, green: 102 / 255, blue: 0 / 255)
2829
private var darkRed = Color(red: 220 / 255, green: 20 / 255, blue: 60 / 255)
@@ -31,12 +32,20 @@ struct HorizontalScrollView: View {
3132
var body: some View {
3233
ScrollView {
3334
VStack {
34-
HStack {
35-
Text("Your Width")
36-
Text(UIScreen.main.bounds.size.width.description)
37-
Text("Height")
38-
Text(UIScreen.main.bounds.size.height.description)
35+
Text("Geometry Width")
36+
GeometryReader { geometry in
37+
VStack {
38+
Text("\(Int(geometry.size.width))")
39+
}
40+
.onAppear {
41+
self.geometryData = geometry.frame(in: .global)
42+
}
43+
.frame(maxWidth: .infinity, alignment: .center)
3944
}
45+
Text("\nScreen Width")
46+
Text(UIScreen.main.bounds.size.width.description)
47+
Text("Screen Height")
48+
Text(UIScreen.main.bounds.size.height.description)
4049
Text("WCAG's Reflow success criterion requires no horizontal scrolling for vertically scrolling content at a width of 320 pixels or less. When horizontal scrolling is used then it must have single tap alternatives to the gestures used to scroll the content.")
4150
.padding(.bottom)
4251
Text("Good Example")
@@ -49,8 +58,8 @@ struct HorizontalScrollView: View {
4958
.frame(height: 2.0, alignment:.leading)
5059
.background(colorScheme == .dark ? Color(.systemGreen) : darkGreen)
5160
.padding(.bottom)
52-
let layout = (UIScreen.main.bounds.size.width <= 320) ? AnyLayout(VStackLayout()) : AnyLayout(HStackLayout())
53-
if UIScreen.main.bounds.size.width <= 320 {
61+
let layout = (UIScreen.main.bounds.size.width <= 320 || geometryData.size.width <= 288) ? AnyLayout(VStackLayout()) : AnyLayout(HStackLayout())
62+
if UIScreen.main.bounds.size.width <= 320 || geometryData.size.width <= 288 {
5463
} else {
5564
HStack {
5665
Spacer()
@@ -69,13 +78,13 @@ struct HorizontalScrollView: View {
6978
}
7079
.frame(maxWidth: .infinity, alignment: .trailing)
7180
}
72-
ScrollView(UIScreen.main.bounds.size.width <= 320 ? .vertical : .horizontal) {
81+
ScrollView(UIScreen.main.bounds.size.width <= 320 || geometryData.size.width <= 288 ? .vertical : .horizontal) {
7382
layout {
7483
ForEach(0..<10) { i in
7584
Button(action: {
7685
// Handle button action
7786
}) {
78-
Text(UIScreen.main.bounds.size.width <= 320 ? "Vertical Button \(i)" : "Horizontal Button \(i)")
87+
Text(UIScreen.main.bounds.size.width <= 320 || geometryData.size.width <= 288 ? "Vertical Button \(i)" : "Horizontal Button \(i)")
7988
.padding()
8089
}
8190
.background(
@@ -88,7 +97,7 @@ struct HorizontalScrollView: View {
8897
}
8998
}
9099
.scrollTargetLayout()
91-
.offset(x: UIScreen.main.bounds.size.width <= 320 ? 0 : offset)
100+
.offset(x: UIScreen.main.bounds.size.width <= 320 || geometryData.size.width <= 288 ? 0 : offset)
92101
}
93102
.scrollTargetBehavior(.viewAligned)
94103
.safeAreaPadding(.horizontal, 40)

iOSswiftUIa11yTechniques/iOSswiftUIa11yTechniques/ResponsiveLayoutsView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct ResponsiveLayoutsView: View {
8787
.foregroundColor(colorScheme == .dark ? Color.black : Color.black)
8888
.buttonStyle(PlainButtonStyle())
8989
}
90+
.accessibilityElement(children: .contain)
9091
.padding()
9192
.overlay(
9293
RoundedRectangle(cornerRadius: 20)
@@ -119,6 +120,7 @@ struct ResponsiveLayoutsView: View {
119120
.foregroundColor(colorScheme == .dark ? Color.black : Color.black)
120121
.buttonStyle(PlainButtonStyle())
121122
}
123+
.accessibilityElement(children: .contain)
122124
.padding()
123125
.overlay(
124126
RoundedRectangle(cornerRadius: 20)
@@ -150,6 +152,7 @@ struct ResponsiveLayoutsView: View {
150152
.foregroundColor(colorScheme == .dark ? Color.black : Color.black)
151153
.buttonStyle(PlainButtonStyle())
152154
}
155+
.accessibilityElement(children: .contain)
153156
.padding()
154157
.overlay(
155158
RoundedRectangle(cornerRadius: 20)

0 commit comments

Comments
 (0)