Diet
This template allows you to customize the Diet section of the Preferences page.
- Boilerplate
- Full Example
import SwiftUI
import mealzcore
import MealziOSSDK
@available(iOS 14, *)
public struct MyCustomPreferencesDietView: PreferencesDietProtocol {
public func content(params: PreferencesDietParameters) -> some View {
// your imp here
}
}
import SwiftUI
import mealzcore
import MealziOSSDK
@available(iOS 14, *)
public struct MyCustomPreferencesDietView: PreferencesDietProtocol {
public init() {}
public func content(params: PreferencesDietParameters) -> some View {
VStack {
ToggleTitle(title: Localization.preferences.dietTitle.localised, isExpanded: params.isExpanded, toggleIsExpanded: { withAnimation { params.isExpanded.toggle() } })
if params.isExpanded {
ForEach(params.dietsTag, id: \.self) { checkableTag in
RadioOrCheckButton(label: checkableTag.tag.attributes?.name ?? "", isSelected: checkableTag.isChecked, typeOfButton: params.typeOfInput, selectOption: {
params.onTogglePreference(checkableTag.tag.id)
})
}
}
}
.padding(.horizontal, Dimension.sharedInstance.mlPadding)
}
}
Params
public struct PreferencesDietParameters {
/// The differerent types of diet (like Vegetarian)
public let dietsTag: [CheckableTag]
/// Whether or not all options are available to be seen
@Binding public var isExpanded: Bool
/// Boolean indicating if the input is a checkbox (multiple options) or radioButton (one option)
public let typeOfInput: TypeOfInput
/// A closure that selects this diet option. Multiple options can be selected at the same time
public let onTogglePreference: (String) -> Void