0

I want the scrollView to be exact the size of its content. But if I don't set a fixed size (".frame(height: 300)"), it looks like this: Instead it should have the height of its content.

enter image description here

This is my code:

var body: some View {
    ScrollView{
        VStack(){
            Form {
                Section(header: Text("User-Settings".localized())) {
                    if (showAllOptions) {
                        Toggle(isOn: $includeProjects,
                               label:
                                {Text("Include Projects".localized())}
                        )
                    }
                    
                    Toggle(isOn: $muteWatch,
                           label: {
                        Text("Mute Watch".localized())
                    })
                    if (showAllOptions) {
                        TextField("Developer Key".localized(), text: $developerKey)
                    }
                    Button("Logout".localized()){
                        showingAlert = true
                    }
                    .alert("Delete credentials?".localized(), isPresented: $showingAlert) {
                        Button("OK".localized()) {
                            deviceId = ""
                            userId = ""
                            employeeId = ""
                            //userId = ""
                            //employeeId = ""
                        }
                        Button("CANCEL".localized(), role: .destructive) {
                            
                        }
                        
                    }
                    .foregroundColor(.red)
                 }
                if (developerKey == "4711") {
                    Section(header: Text("Developer-Settings".localized())) {
                        TextField("Dev URL", text: $developerModeParent)
                        Button("Reset URL"){
                            developerModeParent = ""
                        }
                    }
                }
            }//.frame(height: 300)
                
            
        }.onAppear{
            if (userId.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) {
                showAllOptions = false
            } else {
                showAllOptions = true
            }
            showAlertIsRunning = false
            includingProjectsCurrent = includeProjects
            if (developerModeParent.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) {
                baseUrl = "http://192.168.179.185:8160" //TODO: später hier gegen produktive URL tauschen
            } else {
                baseUrl = developerModeParent
            }
        }
        .onDisappear {
            if (includeProjects != includingProjectsCurrent) {
                Task {
                    await isWorkingSince()
                }
            }
            
            
        }
    }.frame(maxWidth: .infinity, maxHeight: .infinity)
    
    
    
}
}

Is there a way I can set the height of the scrollview to its content or just change its size with a parameter I set for a specific event, so its height gets changed if ... happens.

Steven-Carrot
  • 2,368
  • 2
  • 12
  • 37
Pjaks
  • 251
  • 1
  • 11

0 Answers0