Monday, August 8, 2022
HomeiOS Developmentios - Reload physique objects as soon as information from service layer...

ios – Reload physique objects as soon as information from service layer hundreds in swiftUI


I am new to the swiftUI, on the lookout for a option to refresh view as soon as service information retrieved. What I need is, as soon as web page hundreds, -or earlier than web page loads- I need to name fillUI operate so I can retrieve parsed json information from service layer, with that information I need to refresh this code block so my foreach block works with information I’ve:

                            VStack(spacing:15 ) {
                                ScrollView(.horizontal) {
                                    VStack {
                                            ForEach(0..<5) { i in
                                                MeetingCellView(meetingData: meetingListData?.get(at: i) )
                                                    .body(width: 340, top: 150)
                                                    .padding(.horizontal)
                                                    
                                            }.body(width: 350)

                                    }
                                }.body(width: 350)
                            }

In UIKit, i used to be capable of resolve these points with a method like loading and retrieving all the information first, then displaying the view itself with a knowledge. For swiftUI what’s the finest method to do this?

Right here is the total code of my associated view physique. I had searched web however could not discover the one but.

import SwiftUI

struct HomeView: View {
    @State var username: String = ""
    @State var meetingCode: String = ""
    @State var information: GetUserDetailModel? = nil
    @State var meetingListData: [Datum]? = nil
    @State var requestLoaded = false
    
    var physique: some View {
        
        ZStack{
            VStack {
                Picture("house.background")
                    .resizable()
                    .body(maxHeight: 338)
                Spacer()
                
                ZStack {
                    VStack {
                        RoundedRectangle(cornerRadius: 8)
                            .padding(.high, -20)
                            .foregroundColor(.white)
                    }
                    ScrollView(.vertical, showsIndicators: false)
                    {
                        //MARK: - ScrollView Begin
                        VStack {
                            HStack(spacing: 13.0) {
                                NavigationLink(vacation spot: CreateMeetingView()) {
                                    
                                    
                                    ZStack {
                                        RoundedRectangle(cornerRadius: 12)
                                            .foregroundColor(Colour(pink: 0.935, inexperienced: 0.914, blue: 0.957))
                                        VStack(spacing: 18) {
                                            HStack {
                                                Picture("icon.digicam")
                                                Spacer()
                                            }
                                            HStack {
                                                Textual content("New Assembly")
                                                    .foregroundColor(Colour(pink: 0.476, inexperienced: 0.228, blue: 0.701))
                                                    .font(.customized("inter-semibold", dimension: 15))
                                                Spacer()
                                            }
                                            
                                        }.padding(.horizontal, 15)
                                        
                                    }.body(maxWidth: .infinity, idealHeight: 101)
                                        .padding(.main, 25)
                                }
                                
                                NavigationLink(vacation spot: Textual content("there"))
                                {
                                    ZStack {
                                        RoundedRectangle(cornerRadius: 12)
                                            .foregroundColor(Colour(pink: 0.897, inexperienced: 0.939, blue: 0.978))
                                        VStack(spacing: 18) {
                                            HStack {
                                                Picture("icon.calendar")
                                                Spacer()
                                            }
                                            HStack {
                                                Textual content("Schedule Now")
                                                    .foregroundColor(Colour(pink: 0.038, inexperienced: 0.525, blue: 0.917))
                                                    .font(.customized("inter-semibold", dimension: 15))
                                                Spacer()
                                            }
                                            
                                        }.padding(.horizontal, 15)
                                        
                                    }.body(maxWidth: .infinity, idealHeight: 101)
                                        .padding(.trailing, 25)
                                }
                            }
                        }
                        
                        VStack {
                            HStack {
                                Textual content("Upcoming Conferences")
                                    .font(.customized("inter-semibold", dimension: 17))
                                    .padding(.main, 25)
                                Spacer()
                            }
                            
                            ZStack {
                                
                                VStack(spacing: 30) {
                                    HStack {
                                        Picture("upcoming.calendar")
                                    }
                                    HStack {
                                        Textual content("You shouldn't have a upcoming assembly.")
                                            .font(.customized("inter-regular", dimension: 15))
                                            .foregroundColor(Colour(pink: 0.692, inexperienced: 0.692, blue: 0.692))
                                    }
                                }.hidden()
                                    .padding(.vertical, 46)
                                
                                
                                VStack(spacing:15 ) {
                                    ScrollView(.horizontal) {
                                        VStack {
                                                ForEach(0..<5) { i in
                                                    MeetingCellView(meetingData: meetingListData?.get(at: i) )
                                                        .body(width: 340, top: 150)
                                                        .padding(.horizontal)
                                                        
                                                }.body(width: 350)
    
                                        }
                                    }.body(width: 350)
                                }
                                
                            }
                                .padding(.horizontal ,15)
                            
                        }.padding(.high, 25)
                            .padding(.backside, 100)
                        
                        //MARK:  ScrollView Finish
                    }
                }
            }.ignoresSafeArea()
            
            
            VStack {
                HStack {
                    Picture("splash.emblem")
                        .resizable()
                        .body(maxWidth: 100, maxHeight: 20)
                        .padding(.main, 24)
                    Spacer()
                    Picture("icon.profile")
                        .padding(.trailing,25)
                    
                    
                }
                VStack(spacing: 10.0) {
                    HStack {
                        Textual content("Good Morning,")
                            .font(.customized("inter-semibold", dimension: 13))
                            .foregroundColor(.white)
                        Spacer()
                    }
                    HStack {
                        Textual content(username)
                            .font(.customized("inter-semibold", dimension: 22))
                            .foregroundColor(.white)
                        Spacer()
                    }
                    
                    
                }.padding(.main, 24)
                
                ZStack {
                    Colour.white
                    VStack(spacing: 10.0) {
                        
                        HStack {
                            Textual content("Be part of Assembly")
                                .font(.customized("inter-semibold", dimension: 13))
                            Spacer()
                        }
                        
                        HStack {
                            TextField("Enter assembly code", textual content: $meetingCode)
                                .font(.customized("inter-regular", dimension: 15))
                                .keyboardType(.numbersAndPunctuation)
                        }
                    }.padding(.horizontal, 15)
                    
                    
                }
                .cornerRadius(6)
                .body(maxWidth: .infinity, maxHeight: 75.0)
                .padding(.horizontal, 25.0)
                .padding(.high, 30)
                
                
                Spacer()
            }.hiddenNavigationBarStyle()
            
        }
            .onAppear(carry out: fillUI)
            
            
            
    }
    func fillUI() {
        username = information?.givenName ?? "error"
        Community.meetingList {conferences in
            //print(conferences)
            meetingListData = conferences?.information
            requestLoaded = true
            
        }
    }
}

struct HomeView_Previews: PreviewProvider {
    static var previews: some View {
        HomeView()
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular