Post

Replies

Boosts

Views

Activity

WKWebview/UIViewRepresentable - Hide Loading... text while webview is loading
I have the following UIViewRepresentable that loads a webview. struct SViewerWebView: UIViewRepresentable{ var url: String var token: String @Binding var isLoading: Bool func makeCoordinator() -> Coordinator { Coordinator(self) } func makeUIView(context: Context) -> WKWebView { let webConfiguration = WKWebViewConfiguration() let webView = WKWebView(frame:.zero,configuration:webConfiguration) webView.allowsBackForwardNavigationGestures = true webView.isInspectable = true webView.navigationDelegate = context.coordinator return webView } func updateUIView(_ uiView: WKWebView, context: Context) { guard let urlforRequest = URL(string: url) else { print("❌ Invalid URL:", url) return } var request = URLRequest(url: urlforRequest) request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization") print("🔄 Loading URL:", url) print("🛠 Headers:", request.allHTTPHeaderFields ?? [:]) uiView.load(request) } //coordinator class Coordinator: NSObject, WKNavigationDelegate { var parent: SViewerWebView init(_ parent: SViewerWebView) { self.parent = parent } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { DispatchQueue.main.async { self.parent.isLoading = false // Hide loading when page loads } } func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { DispatchQueue.main.async { self.parent.isLoading = false // Hide loading on error } } } } This is the state before the content loads. At this point a ProgressView() is displayed: The problem comes in the step between screenshot 1 and 3: as you can see in below pictures, before navigating to the webview content, there is a default loading text that still showing up. Apparently, it seems to be the default behavior from the wkwebview. How can I hide that text status? my view component: var body: some View { ZStack{ SViewerWebView(url: webUrl,token: TokenManager.getToken()!,isLoading: $isLoading) if isLoading{ VStack { ProgressView() .progressViewStyle(CircularProgressViewStyle()) .scaleEffect(1.5) } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.white) } } .ignoresSafeArea() }
Topic: UI Frameworks SubTopic: SwiftUI
1
0
21
3w
Scroll up and bounce back loop issue when wrapping LazyVstack within a NavigationStack
The issue I'm facing arise when using a lazyvstack within a navigationstack. I want to use the pinnedViews: .sectionHeaders feature from the lazyStack to display a section header while rendering the content with a scrollview. Below is the code i'm using and at the end I share a sample of the loop issue: struct SProjectsScreen: View { @Bindable var store: StoreOf<ProjectsFeature> @State private var searchText: String = "" @Binding var isBotTabBarHidden: Bool @Environment(\.safeArea) private var safeArea: EdgeInsets @Environment(\.screenSize) private var screenSize: CGSize @Environment(\.dismiss) var dismiss private var isLoading : Bool { store.projects.isEmpty } var body: some View { NavigationStack(path:$store.navigationPath.sending(\.setNavigationPath)) { ScrollView(.vertical){ LazyVStack(spacing:16,pinnedViews: .sectionHeaders) { Section { VStack(spacing:16) { if isLoading { ForEach(0..<5,id:\.self) { _ in ProjectItemSkeleton() } } else{ ForEach(store.projects,id:\._id) { projectItem in NavigationLink(value: projectItem) { SProjectItem(project: projectItem) .foregroundStyle(Color.theme.foreground) } .simultaneousGesture(TapGesture().onEnded({ _ in store.send(.setCurrentProjectSelected(projectItem.name)) })) } } } } header: { VStack(spacing:16) { HStack { Text("Your") Text("Projects") .fontWeight(.bold) Text("Are Here!") } .font(.title) .frame(maxWidth: .infinity,alignment: .leading) .padding(.horizontal,12) .padding(.vertical,0) HStack { SSearchField(searchValue: $searchText) Button { } label: { Image(systemName: "slider.horizontal.3") .foregroundStyle(.white) .fontWeight(.medium) .font(.system(size: 24)) .frame(width:50.66,height: 50.66) .background { Circle().fill(Color.theme.primary) } } } } .padding(.top,8) .padding(.bottom,16) .background(content: { Color.white }) } } } .scrollIndicators(.hidden) .navigationDestination(for: Project.self) { project in SFoldersScreen(project:project,isBotTabBarHidden: $isBotTabBarHidden) .toolbar(.hidden) } .padding(.horizontal,SScreenSize.hPadding) .onAppear { Task { if isLoading{ do { let projectsData = try await ProjectService.Shared.getProjects() store.send(.setProjects(projectsData)) } catch{ print("error found: ",error.localizedDescription) } } } } .refreshable { do { let projectsData = try await ProjectService.Shared.getProjects() store.send(.setProjects(projectsData)) } catch{ print("error found: ",error.localizedDescription) } } }.onChange(of: store.navigationPath, { a, b in print("Navigation path changed:", b) }) } } I'm using tca library for managing states so this is my project feature reducer: import ComposableArchitecture @Reducer struct ProjectsFeature{ @ObservableState struct State: Equatable{ var navigationPath : [Project] = [] var projects : [Project] = [ ] var currentProjectSelected : String? } enum Action{ case setNavigationPath([Project]) case setProjects([Project]) case setCurrentProjectSelected(String?) case popNavigation } var body: some ReducerOf<Self> { Reduce { state, action in switch action { case .setNavigationPath(let navigationPath): state.navigationPath = navigationPath return .none case .setProjects(let projects): state.projects = projects return .none case .setCurrentProjectSelected(let projectName): state.currentProjectSelected = projectName return .none case .popNavigation: if !state.navigationPath.isEmpty { state.navigationPath.removeLast() } state.currentProjectSelected = nil return .none } } }
1
0
31
Mar ’25
Swiftui Rendering issue: View not displayed when using almost full screen height
I plan to use the entire screen height minus 40 pixels approximately to not overlap with the time, batter and carrier data. However, I noticed that in the code shared below the vstack with pink background is not displayed at the top of the screen. The interesting part is that it's actually occupying an offset at the top of the screen. What's more, when I set an offset greater than 70 pixels, then the pink vstack displays on the view! Thus, I'm looking for an explanation to this swiftui rendering issue. Offset less than 70 pixels: Offset greater or equal than 70 pixels: GeometryReader { proxy in let offset = 40.0 let height = proxy.size.height - offset ZStack { VStack(spacing:0){ VStack{Text("heasdas")}.frame(width: 300,height: offset,alignment: .leading) .background(.pink) VStack { HStack(alignment:.center,spacing:10){ Text("Shapecloud") .font(.callout) .fontWeight(.semibold) .frame(alignment: .leading) SLine() } .frame(maxWidth: .infinity,alignment: .leading) Text("Digital Twin Solutions\nServices") .font(.largeTitle) .fontWeight(.medium) .frame(maxWidth: .infinity,alignment: .leading) } .frame(maxWidth: .infinity,maxHeight: 0.3*height,alignment: .top) .background(.red) VStack { VideoPlayer(player: player) .frame(maxWidth: .infinity,maxHeight: 300) } .frame(maxWidth: .infinity,maxHeight: 0.4*height) .background(.yellow) VStack{ Button { } label: { Text("Subscribe now").foregroundStyle(.black) .font(.headline) .fontWeight(.semibold) } .frame(maxWidth: .infinity,maxHeight: 50) .border(Color.black, width: 2) Button { } label: { Text("Sign In").foregroundStyle(.white) .font(.headline) } .frame(maxWidth: .infinity,maxHeight: 50) .background(Color.theme.primary) } .frame(maxWidth: .infinity,maxHeight: 0.3*height) .background(.green) } .padding(.horizontal, 32) .background(.cyan) .ignoresSafeArea(.all) } .ignoresSafeArea(.all) } .ignoresSafeArea(.all)
2
0
173
Feb ’25
protocol in swiftUI
I've been reading the documentation and apparently protocols force structures, classes or enumerations to implement specific methods or define certain variables. I've double checked this functionality by typing the following code. In fact, xcode compiler helped me to verify this since it popped up an alert that depicted the following message : "Type MiguelStruc does not conform to protocol Miguels ..." protocol Miguels { func someF()-> Float } public struct MiguelStruc{ var miguelVar : String = "hey" } extension MiguelStruc: Miguels{ } Now, while I was following the official swiftUI drawing paths and shapes tutorial I encountered this particular chain of code: (https://developer.apple.com/tutorials/swiftui/drawing-paths-and-shapes) Path { path in } .fill(.black) By diving into the Swiftui documentation I noticed that Shape is a protocol public protocol Shape : Sendable, Animatable, View which is implemented by the Path structure extension Path : Shape Why none of the Path extensions content are explicitly implementing any of the Shape protocol requirements? such as role, layoutDirectionBehavior, sizeThatFits, offset, intersection, union, and so on!
4
0
621
May ’24
swiftui bottom padding has no effect on a geometryreader view component
I was following the Swiftui tutorial at section 6 (https://developer.apple.com/tutorials/swiftui/creating-and-combining-views) to use a circle image to create an overlapping effect on the map. Turns out that when using a GeometryReader, the bottom padding was not working at all: VStack{ MapView().frame(height:300) CircleImage() .offset(y: -130) .padding(.bottom, -130) VStack(alignment:.leading){ Text( "Turtle Rock" ) .font( .title ) HStack { Text( "Joshua Tree National Park" ) .font( .subheadline ) Spacer() Text( "California" ) .font( .subheadline ) } }.padding(/*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/) } This is the code for the CicleImage view: GeometryReader(content: { geometry in let _ = print( geometry.size.width ) AsyncImage( url: URL( string: "https://cms.rationalcdn.com/v3/assets/blteecf9626d9a38b03/bltf5486c52361f2012/6144fafd39dff133fc23de9f/img-ios.png" ) ) .frame(width: geometry.size.width) .clipShape( Circle() ).overlay{ Circle().stroke( .white, lineWidth: 4 ) }.shadow( radius: 7 ) })
0
0
602
May ’24
VStack initialization without parentheses
Hi everyone I'm new to swiftui and I'm trying to understand the reason that allows swiftui to call a VStack or any other container view without parentheses as in: struct ContentView: View { var body: some View { VStack { Text("sth"); } } } After looking into the swift docs, it was clear as in any other programming language that instantiating a class/structure is made by calling the entity with its parentheses, an even passing some parameters if possible. Isn't should be the case for placing view components in the body computer property? So far my mind keeps telling me that the syntax should follow this convention struct ContentView: View { var body: some View { VStack() { Text("sth"); } } } At which concept should I look into for further clarifications All the best.
2
0
511
May ’24