I believe .buttonStyle(ButtonStyle)
modifier is how to control the look&feel of Button. So I want to implement my ButtonStyle to get a customized button look.
This is what's in the source:
public protocol ButtonStyle {
/// A `View` representing the body of a `Button`.
associatedtype Body : View
/// Creates a `View` representing the body of a `Button`.
///
/// - Parameter configuration: The properties of the button instance being
/// created.
///
/// This method will be called for each instance of `Button` created within
/// a view hierarchy where this style is the current `ButtonStyle`.
func makeBody(configuration: Self.Configuration) -> Self.Body
/// The properties of a `Button` instance being created.
typealias Configuration = ButtonStyleConfiguration
@available(*, deprecated, renamed: "makeBody(configuration:)")
func body(configuration: Button<Self.Label>, isPressed: Bool) -> Self.Body
@available(*, deprecated, message: "Use makeBody(configuration:) instead.")
typealias Label = ButtonStyleLabel
}
An provided implementation:
public struct DefaultButtonStyle : PrimitiveButtonStyle {
public init()
/// Creates a `View` representing the body of a `Button`.
///
/// - Parameter configuration: The properties of the button instance being
/// created.
///
/// This method will be called for each instance of `Button` created within
/// a view hierarchy where this style is the current `ButtonStyle`.
public func makeBody(configuration: DefaultButtonStyle.Configuration) -> some View
/// A `View` representing the body of a `Button`.
public typealias Body = some View
}
My attempt to make one:
// Error: Type 'MyButtonStyle' does not conform to protocol 'PrimitiveButtonStyle'
struct MyButtonStyle : PrimitiveButtonStyle {
public init() { }
public func makeBody(configuration: DefaultButtonStyle.Configuration) -> some View {
Rectangle() // temporary just for now...
}
// Error: 'some' types are only implemented for the declared type of properties and subscripts and the return type of functions
public typealias Body = some View
}
What to do to just past the compile error?