Comments (2)
Not exactly sure what you are asking and what is the problem.
I guess I would like to know what is the expected behavior in addition to the real-life behavior you described, and then also would need to see more complete code snapshot (what is displayed if unit is not equal to "w"?)
As a first step, when you first get to the view, what is the value of unit and weekSelectArr? (set a breakpoint at 2nd line of your code snippet and check what the variables contain)
from grid.
I want to make my view as same as Ios official App - Reminders's custom repeat dose:
When you pick repeat frequency to "Monthly", you can select from the grid below of which days of month you want to repeat the reminder:
In the work of mine,I use "unit" variable to control 3 different grids' appearance, but when the variable change, the grid only show one item, when I click the item, it come back into grid, that's the final appearance I want.
@State private var weekSelectArr = [false, false, false, false, false,false,false]
@State private var monthSelectArr = [false, false, false, false, false,false,false,false, false, false, false, false,false,false,false, false, false, false, false,false,false,false, false, false, false, false,false,false,false,false,false]
@State private var yearSelectArr = [false, false, false, false, false,false,false,false,false,false,false,false]
...
if(todoRepeat.unit == "w"){
Grid(tracks: 3) {
ForEach(weekSelectArr.indices){item in
Toggle(isOn: self.$weekSelectArr[item]) {
Text(weekdays[item])
.frame(height:50)
}.toggleStyle(GridToggleStyle())
}
}.frame(height:300)
}
if(todoRepeat.unit == "m"){
Grid(tracks: 7) {
ForEach(monthSelectArr.indices){item in
Toggle(isOn: self.$monthSelectArr[item]) {
Text(String(item+1))
.frame(height:50)
}.toggleStyle(GridToggleStyle())
}
}.frame(height:300)
}
if(todoRepeat.unit == "y"){
Grid(tracks: 3) {
ForEach(yearSelectArr.indices){item in
Toggle(isOn: self.$yearSelectArr[item]) {
Text(months[item])
.frame(height:50)
}.toggleStyle(GridToggleStyle())
}
}.frame(height:250)
}
Styles.swift:
import Foundation
import SwiftUI
struct GridToggleStyle: ToggleStyle{
func makeBody(configuration: Configuration) -> some View {
Button(action: {
configuration.isOn.toggle()
}) {
Spacer()
configuration.label
.lineLimit(1)
.truncationMode(.tail)
Spacer()
}
.background(configuration.isOn ? Color.blue : Color.white)
.foregroundColor(configuration.isOn ? Color.white : Color.blue)
.buttonStyle(BorderlessButtonStyle())
}
}
In the breakpoint, unit = "w", weekSelectArr = initial value, that's normal condition.
from grid.
Related Issues (20)
- Add Github Sponsor or other way to "tip" HOT 2
- Nested grid causes parent grid layout issues
- Performance issue when scroll has 1000 items and more HOT 3
- Example app not working on Apple M1 computers HOT 1
- when the item count is 0 it align to center HOT 1
- can not add views with if state of a @State boolean value HOT 2
- Change cell span dynamically HOT 1
- How do you refresh the grid? HOT 11
- Items overlap HOT 4
- Grid lines HOT 2
- Timetable
- zIndex for Grid Items HOT 3
- TextEditor with multiple columns? HOT 1
- ScrollView Nesting Issues. HOT 5
- Top alignment for cells HOT 6
- Urgent! - 1.4.2 build fails HOT 1
- How to create columns with different view heights? HOT 1
- Does it support tvOS? HOT 1
- can support this layout? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grid.