Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacks and Spacers not behaving properly #336

Open
shial4 opened this issue Dec 13, 2020 · 4 comments
Open

Stacks and Spacers not behaving properly #336

shial4 opened this issue Dec 13, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@shial4
Copy link

shial4 commented Dec 13, 2020

Another thing I've noticed is that Spacer isn't working.
When I drop Stack ad spacer view is not stretch for the entire screen.
Many problems with them
Best way to play with it is to build some stuff and you will see.
I have project with different branches holding different issues states. Although, you can check develop and have a play.

@MaxDesiatov MaxDesiatov added the bug Something isn't working label Dec 19, 2020
@timdecode
Copy link

timdecode commented Dec 29, 2020

The following example breaks after the first button click. It goes from taking up the whole page to just what is required to fit the HStack.

struct ContentView: View {
    @State var count: Int = 0
    @State var items: [Int] = []

    var body: some View {
        ScrollView {
            VStack {
                HStack {
                    Spacer() 

                    Button {
                        let numToAdd = 5
                        items.append(contentsOf:(count*numToAdd)..<(count*numToAdd + numToAdd))

                        count += 1
                    } label: {
                        Text("Click me")
                    }

                    Spacer()
                    .frame(width:10.0)

                    Text("Hello, world! Button clicked \(count) times.") 

                    Spacer()
                }
                .padding()

                VStack(alignment: .leading) {
                    ForEach(items, id: \.self) { item in
                        Text("Item \(item)")
                    }
                }

                Spacer()
            }
        }
        .background(Color.red)
    }
}

I just tried Tokamak for the first time today. I'm very excited by its progress, nice work.

@shial4
Copy link
Author

shial4 commented Jan 6, 2021

Another thing I've noticed. frame modifiers for Spacers are not acting correctly. For example

Spacer().frame(minWidth: 400)

setting minimum value acts as setting frame for it. It always have that value.
Testes with HStack

Moreover. If I'm using

VStack {
MyView()
Spacer()
MyView()
}

it does work. Where for HStack it doesn't
Further more if I'm adding something to the spacer such as background or overlay in the above example with VStack.
It does break it completely

@shial4
Copy link
Author

shial4 commented Jan 6, 2021

Everything is captured here in this branch.
Please use var body: some View from ContentView.swift file
Uncomment Spacer code. and remove /comment other spacer to see difference

In order to play with HStack please navigate to NavigationBar.swift
It is just an HStack. and place with spacer there.

@shial4
Copy link
Author

shial4 commented Jan 12, 2021

Another example:

import TokamakDOM

struct TokamakApp: App {
    var body: some Scene {
        WindowGroup("spacer dead") {
            ContentView()
        }
    }
}

// @main attribute is not supported in SwiftPM apps.
// See https://bugs.swift.org/browse/SR-12683 for more details.
TokamakApp.main()




struct ContentView: View {
    var body: some View {
          ScrollView(.vertical, showsIndicators: false) {
               ZStack {
                  BodyView()
            }
        }
    }
}

struct HeaderView: View {
    var body: some View {
         Text("Header")
    }
}

struct BodyView: View {
    var body: some View {
        VStack {
            HeaderView(coordinator: coordinator)
            Spacer() // 💀 This spacer is not working 💀
            FooterView()
        }
    }
}

struct FooterView: View {
    var body: some View {
         Text("Footer")
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants