-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] #28 with suhyeon location select component
- Loading branch information
1 parent
018e28d
commit 1833adf
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
WithSuhyeon-iOS/WithSuhyeon-iOS/Core/DesignSystem/Component/WithSuhyeonLocationSelect.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// WithSuhyeonLocationSelect.swift | ||
// WithSuhyeon-iOS | ||
// | ||
// Created by 우상욱 on 1/15/25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct WithSuhyeonLocationSelect: View { | ||
let withSuhyeonLocation: [WithSuhyeonLocation] | ||
let selectedMainLocationIndex: Int | ||
let selectedSubLocationIndex: Int | ||
let onTabSelected: (Int, Int) -> Void | ||
|
||
var body: some View { | ||
HStack(spacing: 0) { | ||
ScrollView { | ||
VStack(spacing: 0) { | ||
ForEach(withSuhyeonLocation.indices) { index in | ||
ZStack { | ||
Text(withSuhyeonLocation[index].location) | ||
.font(.body02SB) | ||
.foregroundColor(selectedMainLocationIndex == index ? Color.white : Color.black) | ||
.padding(.vertical, 9) | ||
.padding(.leading, 12) | ||
.padding(.trailing, 42) | ||
.background( | ||
RoundedRectangle(cornerRadius: 12) | ||
.fill(selectedMainLocationIndex == index ? Color.primary500 : Color.clear) | ||
) | ||
} | ||
.frame(height: 50) | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
if(selectedMainLocationIndex != index) { | ||
onTabSelected(index, 0) | ||
} | ||
} | ||
} | ||
}.padding(.leading, 16) | ||
.padding(.trailing, 8) | ||
} | ||
Divider() | ||
.foregroundColor(.gray100) | ||
ScrollView { | ||
VStack(alignment: .leading, spacing: 0) { | ||
ForEach(withSuhyeonLocation[selectedMainLocationIndex].subLocation.indices) { index in | ||
ZStack(alignment: .leading) { | ||
HStack { | ||
Text(withSuhyeonLocation[selectedMainLocationIndex].subLocation[index]) | ||
.font(.body03SB) | ||
.foregroundColor(.gray500) | ||
Spacer() | ||
} | ||
.padding(.leading, 12) | ||
.padding(.vertical, 10) | ||
.background( | ||
RoundedRectangle(cornerRadius: 12) | ||
.fill(selectedSubLocationIndex == index ? Color.primary50 : Color.clear) | ||
) | ||
.frame(width: .infinity) | ||
.contentShape(Rectangle()) | ||
.onTapGesture { | ||
onTabSelected(selectedMainLocationIndex, index) | ||
} | ||
} | ||
.frame(height: 50) | ||
.padding(.leading, 8) | ||
.padding(.trailing, 16) | ||
} | ||
} | ||
} | ||
}.frame(height: .infinity) | ||
} | ||
} | ||
|
||
struct locationPreview: View { | ||
@State var selectedMainLocationIndex: Int = 0 | ||
@State var selectedSubLocationIndex: Int = 0 | ||
|
||
var body: some View { | ||
VStack { | ||
WithSuhyeonLocationSelect(withSuhyeonLocation: WithSuhyeonLocation.location, selectedMainLocationIndex: selectedMainLocationIndex, selectedSubLocationIndex: selectedSubLocationIndex, onTabSelected: { num1, num2 in | ||
selectedMainLocationIndex = num1 | ||
selectedSubLocationIndex = num2 | ||
}) | ||
}.frame(height: 400) | ||
} | ||
} | ||
|
||
#Preview { | ||
locationPreview() | ||
} |