Ingredients
This template allows you to customize the Ingredients section of the Preferences page.
- Boilerplate
- Full Example
import SwiftUI
import mealzcore
import MealziOSSDK
@available(iOS 14, *)
public struct MyCustomPreferencesIngredientsView: PreferencesIngredientsProtocol {
public func content(params: PreferencesIngredientsParameters) -> some View {
// your imp here
}
}
import SwiftUI
import mealzcore
import MealziOSSDK
@available(iOS 14, *)
public struct MyCustomPreferencesIngredientsView: PreferencesIngredientsProtocol {
public init() {}
public func content(params: PreferencesIngredientsParameters) -> some View {
VStack {
ToggleTitle(
title: Localization.preferences.tastesTitle.localised,
isExpanded: params.isExpanded,
toggleIsExpanded: { withAnimation { params.isExpanded.toggle() } })
if params.isExpanded {
MealzPreferencesTagsListView(
tags: params.ingredientsTag,
geometry: params.geometry,
onToggleTag: { tag in
params.onTogglePreference(tag.tag.id)
},
onAddTagTapped: params.onGoToSearch)
}
}
.padding(.horizontal, Dimension.sharedInstance.mlPadding)
}
}
Params
public struct PreferencesIngredientsParameters {
/// The differerent types of ingredient (like Eggs)
public let ingredientsTag: [CheckableTag]
/// The geometry so that the users can tap a tag & apply it
public let geometry: GeometryProxy
/// Whether or not all options are available to be seen
@Binding public var isExpanded: Bool
/// A closure that selects this ingredient option. Multiple options can be selected at the same time
public let onTogglePreference: (String) -> Void
/// A closure that opens up the PreferencesSearch page where users can add more blacklisted ingredients
public let onGoToSearch: () -> Void