Giter Club home page Giter Club logo

Comments (2)

hartti avatar hartti commented on August 30, 2024

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.

AntoniotheFuture avatar AntoniotheFuture commented on August 30, 2024

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:
image

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())
    }
}


image

image

In the breakpoint, unit = "w", weekSelectArr = initial value, that's normal condition.

from grid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.