88
99import SwiftUI
1010
11- /**
12- This style makes buttons take up the entire row and applies
13- a content shape that makes the entire view tappable.
14-
15- You can apply the style with `.buttonStyle(.list)`, and can
16- apply it to an entire list, just as with other styles.
17- */
11+ /// This style makes the button take up the entire row, then
12+ /// applies a shape that makes the entire view tappable.
13+ ///
14+ /// You can apply this style with `.buttonStyle(.list)`, and
15+ /// can apply it to an entire list, like any other style.
1816public struct ListButtonStyle : ButtonStyle {
1917
2018 /// Create a custom style.
@@ -61,9 +59,11 @@ public extension ButtonStyle where Self == ListButtonStyle {
6159
6260 var body : some View {
6361 List {
64- ForEach ( 0 ... 100 , id: \. self) {
65- button ( " Button \( $0) " )
66- . buttonStyle ( $0 == 0 ? . list : . list( pressedOpacity: 0.1 ) )
62+ ForEach ( 0 ... 100 , id: \. self) { index in
63+ Button ( " Button \( index) " ) {
64+ overlayText = " \( index) tapped! "
65+ }
66+ . buttonStyle ( index == 0 ? . list : . list( pressedOpacity: 0.1 ) )
6767 }
6868 }
6969 . overlay ( overlay)
@@ -78,12 +78,6 @@ public extension ButtonStyle where Self == ListButtonStyle {
7878 . opacity ( overlayText. isEmpty ? 0 : 1 )
7979 . onTapGesture { overlayText = " " }
8080 }
81-
82- func button( _ name: String ) -> some View {
83- Button ( name) {
84- overlayText = " \( name) tapped! "
85- }
86- }
8781 }
8882
8983 return Preview ( )
0 commit comments