Post

Replies

Boosts

Views

Activity

Reply to TabView Reloads all Tab
Seems that even with a simple view, the component in the tab still gets reloaded @State private var currentTab = 0         var body: some View {     TabView(selection: $currentTab) {       Text("he")         .tabItem {           Label("boo", systemImage: "bird")         }         .tag(0)               LAVAView()         .tabItem {           Label(StringTool.localize("lava"), systemImage: "bird")         }         .tag(1)     } my lava view containst just a text struct LAVAView: View {     init() {     print("init lava view")   }       var body: some View {     Text("hello world")   } } Thoughts @claude31 ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to TabView Reloads all Tab
This is the tab struct struct AtlasTabView: View {       @EnvironmentObject var appData: AppData   @State var reload = false       private var urlRequest: URLRequest?       init() {     setupData()   }       var body: some View {     TabView {       ValleyFaultSystemTiView()       .tabItem {         Label("tab 1", systemImage: "waveform.path.ecg")       }               WebView(request: urlRequest!)         .tabItem {           Label("tab 2", systemImage: "waveform.path.ecg.rectangle")         }               Text("temp")       .tabItem {         Label("tab 3", systemImage: "bird")       }     }   } } This is my web view struct struct WebView : UIViewRepresentable {       let request: URLRequest   let reload = false       func makeUIView(context: Context) -> WKWebView {     return WKWebView()   }       func updateUIView(_ uiView: WKWebView, context: Context) {     guard context.coordinator.needsToLoadURL else { return }     uiView.load(URLRequest(url: request.url!))   }       func makeCoordinator() -> WebView.Coordinator {     Coordinator()   }   class Coordinator {     var needsToLoadURL = true   } } And this is the 1st tab struct struct ValleyFaultSystemTiView: View, FeaturesNeeded {       @EnvironmentObject var appData: AppData   @ObservedObject private var locationManager = LocationManager()       @State private var cameraPosition: GMSCameraPosition?   @State private var coordinateBounds: GMSCoordinateBounds?   @State private var circlePopulations = [GMSCircle]()   @State private var markerShelters = [GMSMarker]()   @State private var polylinesOfFault = [GMSPolyline]()   @State private var polylines = [GMSPolyline]()   @State private var selectedMarker: GMSMarker?       var body: some View {     MapView(       circles: circlePopulations,       markers: markerShelters,       polylines: polylines,       cameraPosition: cameraPosition,       selectedMarker: selectedMarker,       coordinateBounds: coordinateBounds     )     .onAppear() {              if let path = Bundle.main.path(forResource: "test", ofType: "kml") {         do {           // process markers here         } catch {           print(error)         }       }       else {         print("file not found")       }     }   } } @Claude31 I am not sure if the right place is in onAppear since this is in a tab. But if i switch to tab 3, the print code will still be executed inside the // process markers here comment. Currrently, I am getting data from a resource file in the project (problem persists). Once i can fix avoiding having to reload each tab when switching, i will get the data from a url.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Why AVPlayer always nil
@Claude31 it seems the problem is with the instantation of AVPlayer inside init(). honeslty, i have no clue why it behaves this way. If i specify the url when the variable is declared, it works. I followed the sample here https://www.swiftanytime.com/videoplayer-in-swiftui/ and it works if it is coded like this @State var player = AVPlayer(url: URL(string: "https://swiftanytime-content.s3.ap-south-1.amazonaws.com/SwiftUI-Beginner/Video-Player/iMacAdvertisement.mp4")!) but, if it is done like this, it does not work init() {     if let url = URL(string: "https://swiftanytime-content.s3.ap-south-1.amazonaws.com/SwiftUI-Beginner/Video-Player/iMacAdvertisement.mp4") {       player = AVPlayer(url: url)     }  } Thoughts?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Why AVPlayer always nil
Seems i missed some code. here's the right one struct SatelliteVideoView: View {    @State private var player: AVPlayer?       init() {     if let url = URL(string: "https://swiftanytime-content.s3.ap-south-1.amazonaws.com/SwiftUI-Beginner/Video-Player/iMacAdvertisement.mp4") {       player = AVPlayer(url: url)     }   }       var body: some View {     if player != nil {       VideoPlayer(player: player!)     } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to How To Use Objective C Library In Swift Project
Well. I now got it to work... unexpectedly. Xcode still needs improvement. Devs do not have to keep on clearing builds, or deingtegrating pods to reset them. i got to install the lib in pods then just manually created a sapmle objective c library so that xxcode will prompt to create a header file then import the bridging header file into your project's bridging header file yep. this was never mentioned in any of the posts i came across with.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Slide View Does Not Animate. But Fade Works.
I got it to work. by adding a condition in the MyView's body if isShowing { VStack(spacing: 0) {       Group {         row("#ff0000", "color1") ........ } And this code in the button action withAnimation {         isShowingLegend.toggle() } I do not understand why it works though. any inputs are appreciated. thank you.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’22
Reply to Can A Property In An ObservableObject listen to Another Property? How?
@ptit-xav it didnt work. i have another class that contains the ToolbarItemProperties final class AppData: ObservableObject {   @Published var toolbarItem1: ToolbarItemProperties? } it works if i do it like this let item = ToolbarItemProperties() item.disabled = true appData.toolbarItem1 = item but if i directly change the value of the property like this, nothing happens. it does not re-render. any idea why? appData.toolbarItem1?.disabled = true although if i do it like this (after setting a value to the disabled property, it works appData.toolbarItem1 = appData.toolbarItem1 I still think even if a property of an ObservableObject is changed, it should refresh the view. not when the whole object is a set a value.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’22
Reply to "Invalid top-level type in JSON write"
this is irritating. I cant post a json sample even though i already trimmed it
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to LocationManager Error when requesting location
added note is i already tried erasing content or simulator, the permission category in the info plist are there (its a swiftui project) sadly no location swrvices in simulators even until ios16 so i couldnt even try to manually change it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Calculating bearing and distance between two lat and long
can you please share your code? i am also looking for this.
Replies
Boosts
Views
Activity
Nov ’22
Reply to LocationManager Error when requesting location
Weird that the solution was to onclude 2 permission. it never worked when i first added it. later on i tried to do it again and all of a sudden it worked.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to TabView Reloads all Tab
Seems that even with a simple view, the component in the tab still gets reloaded @State private var currentTab = 0         var body: some View {     TabView(selection: $currentTab) {       Text("he")         .tabItem {           Label("boo", systemImage: "bird")         }         .tag(0)               LAVAView()         .tabItem {           Label(StringTool.localize("lava"), systemImage: "bird")         }         .tag(1)     } my lava view containst just a text struct LAVAView: View {     init() {     print("init lava view")   }       var body: some View {     Text("hello world")   } } Thoughts @claude31 ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to TabView Reloads all Tab
This is the tab struct struct AtlasTabView: View {       @EnvironmentObject var appData: AppData   @State var reload = false       private var urlRequest: URLRequest?       init() {     setupData()   }       var body: some View {     TabView {       ValleyFaultSystemTiView()       .tabItem {         Label("tab 1", systemImage: "waveform.path.ecg")       }               WebView(request: urlRequest!)         .tabItem {           Label("tab 2", systemImage: "waveform.path.ecg.rectangle")         }               Text("temp")       .tabItem {         Label("tab 3", systemImage: "bird")       }     }   } } This is my web view struct struct WebView : UIViewRepresentable {       let request: URLRequest   let reload = false       func makeUIView(context: Context) -> WKWebView {     return WKWebView()   }       func updateUIView(_ uiView: WKWebView, context: Context) {     guard context.coordinator.needsToLoadURL else { return }     uiView.load(URLRequest(url: request.url!))   }       func makeCoordinator() -> WebView.Coordinator {     Coordinator()   }   class Coordinator {     var needsToLoadURL = true   } } And this is the 1st tab struct struct ValleyFaultSystemTiView: View, FeaturesNeeded {       @EnvironmentObject var appData: AppData   @ObservedObject private var locationManager = LocationManager()       @State private var cameraPosition: GMSCameraPosition?   @State private var coordinateBounds: GMSCoordinateBounds?   @State private var circlePopulations = [GMSCircle]()   @State private var markerShelters = [GMSMarker]()   @State private var polylinesOfFault = [GMSPolyline]()   @State private var polylines = [GMSPolyline]()   @State private var selectedMarker: GMSMarker?       var body: some View {     MapView(       circles: circlePopulations,       markers: markerShelters,       polylines: polylines,       cameraPosition: cameraPosition,       selectedMarker: selectedMarker,       coordinateBounds: coordinateBounds     )     .onAppear() {              if let path = Bundle.main.path(forResource: "test", ofType: "kml") {         do {           // process markers here         } catch {           print(error)         }       }       else {         print("file not found")       }     }   } } @Claude31 I am not sure if the right place is in onAppear since this is in a tab. But if i switch to tab 3, the print code will still be executed inside the // process markers here comment. Currrently, I am getting data from a resource file in the project (problem persists). Once i can fix avoiding having to reload each tab when switching, i will get the data from a url.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Why AVPlayer always nil
@Claude31 it seems the problem is with the instantation of AVPlayer inside init(). honeslty, i have no clue why it behaves this way. If i specify the url when the variable is declared, it works. I followed the sample here https://www.swiftanytime.com/videoplayer-in-swiftui/ and it works if it is coded like this @State var player = AVPlayer(url: URL(string: "https://swiftanytime-content.s3.ap-south-1.amazonaws.com/SwiftUI-Beginner/Video-Player/iMacAdvertisement.mp4")!) but, if it is done like this, it does not work init() {     if let url = URL(string: "https://swiftanytime-content.s3.ap-south-1.amazonaws.com/SwiftUI-Beginner/Video-Player/iMacAdvertisement.mp4") {       player = AVPlayer(url: url)     }  } Thoughts?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Why AVPlayer always nil
Seems i missed some code. here's the right one struct SatelliteVideoView: View {    @State private var player: AVPlayer?       init() {     if let url = URL(string: "https://swiftanytime-content.s3.ap-south-1.amazonaws.com/SwiftUI-Beginner/Video-Player/iMacAdvertisement.mp4") {       player = AVPlayer(url: url)     }   }       var body: some View {     if player != nil {       VideoPlayer(player: player!)     } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How To Use Objective C Library In Swift Project
Well. I now got it to work... unexpectedly. Xcode still needs improvement. Devs do not have to keep on clearing builds, or deingtegrating pods to reset them. i got to install the lib in pods then just manually created a sapmle objective c library so that xxcode will prompt to create a header file then import the bridging header file into your project's bridging header file yep. this was never mentioned in any of the posts i came across with.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Is it possible to rebuild overlay only and not the body?
Guess the solution is to use state and binding (in the child view)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Is it possible to rebuild overlay only and not the body?
Use state binding in the child view.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Slide View Does Not Animate. But Fade Works.
I got it to work. by adding a condition in the MyView's body if isShowing { VStack(spacing: 0) {       Group {         row("#ff0000", "color1") ........ } And this code in the button action withAnimation {         isShowingLegend.toggle() } I do not understand why it works though. any inputs are appreciated. thank you.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Aspect Ratio Of Image is Whacked
Baaaah. I luckily found the solution I was looking for a few minutes after posting this. so we use .aspectRatio(ratio, contentMode: .fit)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Can A Property In An ObservableObject listen to Another Property? How?
@ptit-xav it didnt work. i have another class that contains the ToolbarItemProperties final class AppData: ObservableObject {   @Published var toolbarItem1: ToolbarItemProperties? } it works if i do it like this let item = ToolbarItemProperties() item.disabled = true appData.toolbarItem1 = item but if i directly change the value of the property like this, nothing happens. it does not re-render. any idea why? appData.toolbarItem1?.disabled = true although if i do it like this (after setting a value to the disabled property, it works appData.toolbarItem1 = appData.toolbarItem1 I still think even if a property of an ObservableObject is changed, it should refresh the view. not when the whole object is a set a value.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to Why Can't I do var test: some View?
Please ignore. Seems the problem lies in the DailyCityReportView.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22