ViktorMaric / HalfModal

SwiftUI package for displaying custom iOS 13 like modal.
54 stars 3 forks source link

Alignment #1

Closed ChopsKingsland closed 3 years ago

ChopsKingsland commented 3 years ago

How do I move the text from the centre to the left? image

ViktorMaric commented 3 years ago

Put the content inside a HStack like that:

AnyView(HStack {
            Text("No description")
            Spacer()
        })
ChopsKingsland commented 3 years ago

Do you also know how I stop this? Only happened when I added a tab view image

Code: https://pastebin.com/pwjUHsV5

ViktorMaric commented 3 years ago

You should put your NavigationView and HalfModal inside a ZStack like this:

TabView {
    Group {
        ZStack {
            NavigationView {
                VStack {
                    ...
                }
            }
            if showingHalfModal {
                HalfModalView(content: AnyView(HStack {
                    Text(mDesc)
                        .padding()

                }), header: AnyView(Text("hello")), isPresented: $showingHalfModal)
            }
        }
    }
    .tabItem {
        Image(systemName: "flame")
        Text("Launches")
    }

    Text("rockets")
        .tabItem {
            Image(systemName: "paperplane")
            Text("Rockets")
        }
}
ChopsKingsland commented 3 years ago

I have changed it to this: https://pastebin.com/pwjUHsV5 an it doesn't even show up now!

ViktorMaric commented 3 years ago

Put the HalfModal inside the ZStack, below the NavigationView:

var body: some View {

        TabView {
            Group {

                ZStack {
                    NavigationView {
                        VStack {
                            Spacer()
                                .frame(height: 1)
                                .navigationBarTitle("Launches")

                            List {

                                ForEach(launches, id: \.id) { launch in
                                    Button(action: {
                                        self.mName = launch.name
                                        self.mDate = Date(timeIntervalSince1970: launch.date_unix).getFormattedDate(format: "dd/MM/yyyy HH:mm:ss")
                                        self.rID = launch.rocket
                                        self.mImg = launch.links.patch.missionPatch ?? "null"
                                        self.mDesc = launch.details ?? "No description"
                                        self.show_modal.toggle()
                                        withAnimation {
                                            self.showingHalfModal = true
                                        }
                                    }) {
                                        HStack {
                                            URLimageView(urlString: launch.links.patch.missionPatch)
                                            Group {
                                                Text(launch.name)
                                                    .font(.system(size: 23))
                                                    .frame(maxWidth: .infinity, alignment: .leading)
                                                    .fixedSize(horizontal: false, vertical: true)
                                                Text(Date(timeIntervalSince1970: launch.date_unix).getFormattedDate(format: "dd/MM/yyyy HH:mm:ss"))
                                                    .font(.system(size: 11.5))
                                                    .foregroundColor(Color.gray)
                                                    .frame(maxWidth: .infinity, alignment: .leading)
                                                    .fixedSize(horizontal: false, vertical: true)
                                                Spacer()
                                            }
                                        }
                                    }
                                    .buttonStyle(PlainButtonStyle())
                                }
                            }.onAppear {
                                apiCall().getUsers{ (launches) in self.launches = launches}
                            }.listStyle(SidebarListStyle())
                            .frame(alignment: .center)
                        }

                    }
                    if showingHalfModal {
                        HalfModalView(content: AnyView(HStack {
                            Text(mDesc)
                                .padding()

                        }), header: AnyView(HStack {
                                                URLimageView(urlString: self.mImg)
                                                VStack(alignment: .leading) {
                                                    Text(self.mName)
                                                    Text(self.mDate)
                                                        .font(.system(size: 10))
                                                        .foregroundColor(Color.gray)
                                                }}), isPresented: $showingHalfModal)
                    }
                }
            }
            .tabItem {
                Image(systemName: "flame")
                Text("Launches")
            }
            Text("rockets")
                .tabItem {
                    Image(systemName: "paperplane")
                    Text("Rockets")
                }
        }

    }
ChopsKingsland commented 3 years ago

I just realised it was me being stupid, I put it one too low. Thanks for the help, your add-on really saved me time!

ViktorMaric commented 3 years ago

Happy to help! Good luck with the app!

ChopsKingsland commented 3 years ago

Sorry for asking so many questions, but it doesn't work in a second view that I've added... My code is https://pastebin.com/yB2Fm8ry

The errors are cannot find 'showingHalfModal2' in scope on line 248 & cannot find '$showingHalfModal2' in scope on line 261