Skip to content

Commit b89204c

Browse files
committed
Introduce AnyButtonStyle
1 parent d02d877 commit b89204c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright (c) Vatsal Manot
3+
//
4+
5+
import SwiftUI
6+
7+
/// A type-erased wrapper for `ButtonStyle.`
8+
public struct AnyButtonStyle: ButtonStyle {
9+
public let _makeBody: (Configuration) -> AnyView
10+
11+
public init<V: View>(
12+
makeBody: @escaping (Configuration) -> V
13+
) {
14+
self._makeBody = { makeBody($0).eraseToAnyView() }
15+
}
16+
17+
public func makeBody(configuration: Configuration) -> some View {
18+
self._makeBody(configuration)
19+
}
20+
}

0 commit comments

Comments
 (0)