AIDWEKOV2.0

 avatar
unknown
swift
a year ago
1.8 kB
3
Indexable
import SwiftUI

struct ContentView: View {
    @StateObject var viewModel = ChatViewModel()
    @State private var messageText = ""

    var body: some View {
        VStack {
            // Your content here, like the ScrollView for messages
            ScrollView {
                ForEach(viewModel.messages) { message in
                    Text(message.text)
                        .padding()
                        .background(message.isUser ? Color.blue : Color.gray)
                        .cornerRadius(10)
                        .foregroundColor(Color.white)
                        .frame(maxWidth: .infinity, alignment: message.isUser ? .trailing : .leading)
                }
            }

            Spacer() // Pushes everything above to the top and the TextField/Button to the bottom

            // TextField and Send Button at the bottom center
            HStack {
                TextField("Enter your message", text: $messageText)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                    .padding()

                Button("Send") {
                    viewModel.sendMessage(messageText)
                    messageText = ""
                }
                .padding()
                .background(Color.blue)
                .foregroundColor(.white)
                .cornerRadius(10)
            }
            .padding(.bottom, 8) // Add padding at the bottom if needed
        }
        .background(
            Image("ADWEKO Hintergrund_Tasse")
                .resizable()
                .aspectRatio(contentMode: .fill)
                .opacity(0.1)
                .edgesIgnoringSafeArea(.all)
        )
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Editor is loading...
Leave a Comment