Open abilgin88 opened 1 year ago
Button(action: {
isGridViewActive = false
haptic.impactOccurred()
**gridSwitch()** remove here
}) {
Image(systemName: "square.fill.text.grid.1x2")
.font(.title2)
.foregroundColor(isGridViewActive ? .PrimaryColor : .SecondaryColor)
}
AdvancedGridShowcaseView Component Tasks:
[x] Load Plant Data:
Plant
objects.[x] Implement Selected Plant State:
@State
property namedselectedPlant
to track the selected plant image name.[x] Define Grid Layout State:
@State
property namedgridLayout
to define the grid layout for the gallery.[x] Create Grid Column State:
@State
property namedgridColumn
to control the number of grid columns.3.0
.[x] Add Haptic Feedback Generator:
UIImpactFeedbackGenerator
property namedhaptics
to provide haptic feedback for interactions.[x] Build Gallery Content:
ScrollView
to contain the gallery content with vertical scrolling.VStack
to vertically align the components within the scroll view.30
.[x] Display Selected Plant Image:
PlantImageView
to display the selected plant image.selectedPlant
as theimageName
parameter.8
and a stroke color of.white
.[x] Add Grid Column Slider:
SliderView
component to adjust the number of grid columns.gridColumn
state to the slider's value.[x] Implement Grid Layout Switch:
gridSwitch(gridColumn:)
to adjust the grid layout based on thegridColumn
state.gridLayout
with an array of grid items according to the chosen column count.[x] Display Plant Images in Grid:
LazyVGrid
with columns determined by thegridLayout
.Plant
item in theplants
array.[x] Display Individual Plant Images:
PlantImageView
to display individual plant images.imageName
to theitem.image
value.1
and a stroke color of.white
.[x] Handle Image Selection:
onTapGesture
for each plant image in the grid.selectedPlant
state with the tapped plant's image name.haptics.impactOccurred()
.[x] Randomize Initial Image:
onAppear
modifier of theLazyVGrid
, call therandomizeImage()
function to set an initial random image.[x] Optimize Layout and Padding:
VStack
to add space around the gallery content.10
and vertical padding to50
.[x] Ensure Full Scrollable Area:
.frame(maxWidth: .infinity, maxHeight: .infinity)
on theScrollView
to ensure the entire content is scrollable.Commit: Link to Commit
https://user-images.githubusercontent.com/96279901/261786284-725e55a4-93eb-4be8-ba66-a6e5f6292799.mov