Post

Replies

Boosts

Views

Activity

WebView
I am trying to parse some html inside my app. Not an entire html page, but just few blocks of html code. So I'm using Ink package for that. // FIRST I HAVE A WEBVIEW import SwiftUI import WebKitstruct WebView : UIViewRepresentable {   var html: String  func makeUIView(context: Context) -> WKWebView {     return WKWebView()   }  func updateUIView(_ webView: WKWebView, context: Context) {     webView.loadHTMLString(html, baseURL: nil)   }} // IN HERE I'M PARSING THE HTML AND ALSO ADDING SOME STYLING TO IT import Foundation import Ink class ParseContent: ObservableObject {   var markdown: String = ""   func parse() -> String {     let parser = MarkdownParser()     let html = parser.html(from: markdown)       let htmlStart = "<HTML><HEAD></HEAD><BODY style=\"padding: 140px; font-size: 120px; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Open Sans,Helvetica Neue,sans-serif\">"     let htmlEnd = "</BODY></HTML>"       return htmlStart + html + htmlEnd   } } // IN HERE I AM JUST USING MY PREVIOUSLY CREATED WEBVIEW WebView(html: myHtmlContent) .onAppear() {         htmlContent = ParseContent().parse()     } So here are my questions: Why the styling isn't working since I am concatenating the html ? I see it in a lot of tutorials but cant understand why not working. I would like to have the font inside my WebView, the same as I have for my other components like Text("abc") so I would keep a pattern and the visitor woudnt realize they are different components. How to set the WebView without a vertical scroll ? Keeping the entire height coming from the parsed html ? Thank you guys :)
2
0
806
Aug ’21
Convert HTML to Text
In my SwiftUI project, I am trying to convert HTML to Text. Text("h1Test/h1p Test/pbr/spanTest/spanulliitem1/liliitem2/li/ul")           .font(.body)           .frame(maxWidth: .infinity, alignment: .leading)           .padding(.bottom, 16)           Is there a way to make it happen ? Thank you
2
0
4.3k
Apr ’21
Picker without NavigationView
I have a picker on my view but it's not selectable unless I replace my VStack for a NavigationView. However I cant have a NavigationView on this page, otherwise it brakes other parts. What's the solution for that ? Thx VStack { Picker }
4
0
1.8k
Nov ’21
TabBar Transitions
I have a TabBar with 3 items: Home ScrollView Products NavigationView Users NavigationView When clicking on the tabBar buttons, I will go back to the related view. However, at the point where I had left. I would like to every time I move to a different tab, it starts fresh like 1st time. a) If it's a scrollview, after coming back to the tab I would like the view scrolled to the top. b) If it's a navigationView, after coming back to the tab, I would like to scroll to the top and move to the Navigation root list. How can I do it. Thx folks
0
0
286
Dec ’21
Call 2o API after finishing 1st one
I have a button that when pressed should call an API which return an ID. Then having this ID, I will call a 2nd API. Button(action: { var id = self.callApi1() self.callApi2(id) }) { Text("Start") } How can I call the Api2 JUST when the Api1 was finished and returned its value ? Thank you
3
0
445
Nov ’21
Loading View on API call
I have a Loading view saying "Please wait" that I want to be presented until the data from the API comes back. However, self.showLoading = false is executed even before store.getHomeItems() is finished. How can I do it ? struct HomeView: View {   @State var showLoading = false ... if (self.showLoading == true) { LoadingView() } else { //my content } ... ScrollView { //my scroll content } .onAppear { self.showLoading = true       DispatchQueue.main.async {          store.getHomeItems()       } self.showloading = false ... } I also dont know if I can call Dispatch on my HomeView, since my API layer has also an another DispatchQueue. URLSession.shared.dataTask(with: url) { (data, _, _) in       guard let data = data else { return }               let myItems = try! JSONDecoder().decode([ItemModel].self, from: data)      DispatchQueue.main.asyncAfter(deadline: .now() + 10) {         completion(myItems)       }        }     .resume() Thank you
2
0
1.3k
Nov ’21
Init or body ?
I have a store, but need to call the method inside the body. However the only way it works is if I call it inside init otherwise I have an error. @ObservedObject var store = MyStore() init(category: categoryModel) {     store.getData(categoryId: category.id) //here works } var body: some View {         store.getData(categoryId: category.id) //Here I will have the error: Type '()' cannot conform to 'View' Why ? Thx
1
0
434
Sep ’21
SF Symbols Fill
I am using SF symbols on my TabBar but even though I use the stroke version, it inserts the fill one. ProductsListView()         .tabItem {            Image(systemName: "book")            Text("Products")         } However, the image that shows up when I run the application in the book.fill Why this could be happening? Thx
2
0
1.9k
Nov ’21
Navigation Bar Color
I am trying to change the navigation bar background color of my view. Init() {    let coloredAppearance = UINavigationBarAppearance()     //coloredAppearance.configureWithTransparentBackground() //It doesnt matter what I use in here, it continues the same coloredAppearance.backgroundColor = UIColor(red: 202.0/255.0, green: 52.0/255.0, blue: 86.0/255.0, alpha: 1.0)     coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]      UINavigationBar.appearance().standardAppearance = coloredAppearance UINavigationBar.appearance().compactAppearance = coloredAppearance UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance      UINavigationBar.appearance().tintColor = .white However if you get the red, green, blue, and alpha used above, you will see the color is being shown slightly different on the NavigationBar. What's the reason for that ? Thx
1
0
323
Nov ’21
TabBar 2 clicks
I have a TabBar with 8 items. And as everybody knows, more than 5 makes the 5th item the MORE button and it's perfect. The problem is when I hit it, the button just blinks. If I hit again, then the other options are shown. Why ? Thx
1
0
327
Nov ’21
Button inside Form
I have a form and at the end of it, a button. Form { Section { } //close section button } //close form However, the button is appearing surrounded by white space, like inside a textbox. What's the reason for that?
1
0
318
Nov ’21
TabBar and Views
I have a TabBar with 5 different views for each TabBar item. All these 5 views have long content wrapped in a ScrollView. So let's say I chose my 2nd TabBar item and scroll on this view. Then I move away to another view and when I hit the 2nd TabBar item again, I want this view scrolled to the top and not at the position I left on the first visualization. How can I do that? Thx
0
0
280
Nov ’21
NavigationLInk
I have an array with 10 different categories. So I create NavigationLink for each of them, calling MyListView and passing data about the category. NavigationView { List(categories) { category in NavigationLink(destination:           MyListView(category: category) )             {           CategoryRow(category: category)   } } } So when I click in one of these 10 categories, I will call MyListView. Inside MyListView I have a call to the API bringing a lot of information about the chosen category. The problem here is, even before clicking in any category, MyListView is being called and the API is called for all the 10 categories. I only want to call MyListView and the API inside it, after selecting the category. Whats the problem here ? Thx
3
0
551
Sep ’21
Open View using Button
When I use TabView and select a TabItem, a chosen View will open right away. TabView {   HomeView()          .tabItem {             Image(systemName: "house")           Text("Home")           } } Now I am trying to do the same, using button. However with button, the chosen View will open under .sheet or .fullScreenCover. Button(text) { self.isPresented.toggle() } .sheet(isPresented: $isPresented) { self.content } How can I open the View using button, the same way it's opened using TabBar ? Thx
1
0
300
Sep ’21
Instruments
My app crashes in specific parts and I am trying to identify why. I am using Instruments - Leaks but when I access this problematic part of the app, the app crashes and nothing is shown. What would be the best tool under Instruments umbrella to check these crashes? Thanks
1
0
370
Sep ’21