I've removed the optional part in the framework as follows. And it works. I don't know why the callBack guy can't be optional, though, in the framework.
import SwiftUI
public struct ColorSelectorView: View {
@Binding var selectedColor: Color
@State var callBack: ((Color) -> Void)
let colors: [Color] = [.blue, .green, .orange, .yellow, .red, .purple]
public init(selectedColor: Binding<Color>, callBack: @escaping ((Color) -> Void)) {
self._selectedColor = selectedColor
self.callBack = callBack
}
public var body: some View {
HStack {
ForEach(colors, id: \.self) { color in
Image(systemName: selectedColor == color ? "record.circle.fill" : "circle.fill")
.foregroundColor(color)
.onTapGesture {
selectedColor = color
callBack(color)
}
}
}
}
}