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