Last active
August 4, 2024 07:37
Revisions
-
robinkanatzar revised this gist
Aug 4, 2024 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -18,6 +18,8 @@ import SwiftUI /// } /// } /// ``` /// /// Article about this gist: https://robinkanatzar.blog/accessibile-stack-in-swiftui-af8630a1cd1d struct AStack<Content>: View where Content: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize let content: Content -
robinkanatzar revised this gist
Aug 4, 2024 . 1 changed file with 19 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,13 @@ import SwiftUI /// An accessible stack view that starts as an HStack /// then becomes a VStack once the dynamic type size /// is an accessibility size. /// /// Usage in a View: /// ``` /// var body: some View { /// AStack(hStackAlignment: .top, hStackSpacing: 100, vStackAlignment: .leading, vStackSpacing: 5) { /// Text("Hello, world!") /// Text("Hello, world!") /// Text("Hello, world!") @@ -19,16 +21,28 @@ struct AStack<Content>: View where Content: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize let content: Content let hStackAlignment: VerticalAlignment let hStackSpacing: CGFloat? let vStackAlignment: HorizontalAlignment let vStackSpacing: CGFloat? init(hStackAlignment: VerticalAlignment = .center, hStackSpacing: CGFloat? = nil, vStackAlignment: HorizontalAlignment = .center, vStackSpacing: CGFloat? = nil, @ViewBuilder content: () -> Content) { self.hStackAlignment = hStackAlignment self.hStackSpacing = hStackSpacing self.vStackAlignment = vStackAlignment self.vStackSpacing = vStackSpacing self.content = content() } var body: some View { if dynamicTypeSize.isAccessibilitySize { VStack(alignment: vStackAlignment, spacing: vStackSpacing) { content } } else { HStack(alignment: hStackAlignment, spacing: hStackSpacing) { content } } } } -
robinkanatzar revised this gist
Aug 4, 2024 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,21 @@ /// An accessible stack view that starts as an HStack /// then becomes a VStack once the dynamic type size /// is an accessibility size. /// /// Usage in a View: /// ``` /// var body: some View { /// AStack { /// Text("Hello, world!") /// Text("Hello, world!") /// Text("Hello, world!") /// Text("Hello, world!") /// Text("Hello, world!") /// Text("Hello, world!") /// Text("Hello, world!") /// } /// } /// ``` struct AStack<Content>: View where Content: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize let content: Content -
robinkanatzar created this gist
Aug 4, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ /// An accessible stack view that starts as an HStack /// then becomes a VStack once the dynamic type size /// is an accessibility size. struct AStack<Content>: View where Content: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize let content: Content init(@ViewBuilder content: () -> Content) { self.content = content() } var body: some View { if dynamicTypeSize.isAccessibilitySize { VStack { content } } else { HStack { content } } } }