Support generic label and rounded rectangle shape#2
Conversation
|
what do you think @mikakruschel @cameronshemilt ? |
|
Hey @dabear,
extension SlideButton where Label == Text {
public init(_ titleKey: LocalizedStringKey, styling: Styling = .default, callback: @escaping () async -> Void) {
self.init(styling: styling, callback: callback, label: { Text(titleKey) })
}
public init<S>(_ title: S, styling: Styling = .default, callback: @escaping () async -> Void) where S: StringProtocol {
self.init(styling: styling, callback: callback, label: { Text(title) })
}
}
public init(styling: Styling = .default, callback: @escaping () async -> Void, @ViewBuilder label: () -> Label) {
self.title = label()
self.callback = callback
self.styling = styling
self._offset = .init(initialValue: styling.indicatorSpacing)
}Note: You will have to also remove the It otherwise looks fine to me. What do you think @mikakruschel? |
public extension SlideButton {
/// A struct that defines the styling options for a `SlideButton`.
struct Styling {
public static let `default`: Self = .init() //not allowed if Slidebutton is generic |
|
I think your comments should be addressed now by the latest commit 0ce2f23 |
|
And since you mentioned accessibility, I think adding an |
Fixed formatting and renamed callback parameter
| case .circular: | ||
| Circle() | ||
| case .rectangular(let cornerRadius): | ||
| RoundedRectangle(cornerRadius: cornerRadius ?? 0) |
There was a problem hiding this comment.
This should be RoundedRectangle(cornerRadius: max(0, (cornerRadius ?? 0) - styling.indicatorSpacing)) for an even spacing between the indicator and background
|
ok, updated. It would be nice if this can be merged now :) I can accessibility after this is merged, in a separate PR |
| case .circular: | ||
| Capsule() | ||
| case .rectangular(let cornerRadius): | ||
| RoundedRectangle(cornerRadius: max(0, (cornerRadius ?? 0) - styling.indicatorSpacing)) |
There was a problem hiding this comment.
Only the indicatorShape needed the spacing subtracted. The mask (which masks the background) should still be using RoundedRectangle(cornerRadius: cornerRadius ?? 0)
There was a problem hiding this comment.
ok, updated as well.
|
Thanks for the contribution, @dabear! |



This introduces a generic version of the slidebutton which can support views as title instead of String. This is necessary if you want to pass inn some Modified Text or other views as title.
( I will add this repo as a dependency to LoopKit/OmniBLE#99 if this gets accepted. )
It also adds support for shapes other than circles, and in cases you want a solid background, you can choose to set the indicator's background relative to the overall background by setting indicatorBrightness to a value between -1 and +1.
Note that, to maintain backward compatibility there are now both a SlideButton and a GenericSlideButton. This allows the caller to use SlideButton as before without any changes. In that case there will be no changes for the enduser.
All the new options are by default turned off.