Created
May 17, 2022 11:48
-
-
Save joeltrew/dadb512312052d8070d59170b2bf586f to your computer and use it in GitHub Desktop.
AccessibilityScrollModifier lets you place content in a scrollview when dynamic text hits certain sizes or by default an Accessibility Category size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AccessibilityScrollModifier: ViewModifier { | |
@Environment(\.sizeCategory) private var sizeCategory | |
var axis: Axis.Set | |
var shouldScroll: (ContentSizeCategory) -> Bool | |
func body(content: Content) -> some View { | |
if shouldScroll(sizeCategory) { | |
ScrollView(axis, showsIndicators: true) { | |
content | |
} | |
} else { | |
content | |
} | |
} | |
} | |
extension View { | |
func accessibilityScrollView(axis: Axis.Set = .vertical) -> some View { | |
self.modifier(AccessibilityScrollModifier(axis: axis, shouldScroll: { $0.isAccessibilityCategory })) | |
} | |
func accessibilityScrollView(axis: Axis.Set = .vertical, activateAt sizeCategory: ContentSizeCategory) -> some View { | |
self.modifier(AccessibilityScrollModifier(axis: axis, shouldScroll: { $0 >= sizeCategory })) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment