Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created May 14, 2023 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/e6605aacdc4d91dd73c41cf7b71a18c6 to your computer and use it in GitHub Desktop.
Save laevandus/e6605aacdc4d91dd73c41cf7b71a18c6 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@StateObject var viewModel = ViewModel()
@Namespace var colorSelectionNamespace
var body: some View {
VStack {
HStack {
ForEach(viewModel.topColors) { item in
Button(action: { viewModel.selectTopColor(item) }) {
Rectangle()
.foregroundColor(item.color)
.frame(width: 40, height: 40)
}
.matchedGeometryEffect(id: item.id, in: colorSelectionNamespace)
}
}
.frame(minHeight: 50)
Spacer()
.frame(height: 200)
HStack {
ForEach(viewModel.bottomColors) { item in
Button(action: { viewModel.selectBottomColor(item) }) {
Circle()
.foregroundColor(item.color)
.frame(width: 20, height: 20)
}
.matchedGeometryEffect(id: item.id, in: colorSelectionNamespace)
}
}
.frame(minHeight: 50)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment