Post

Replies

Boosts

Views

Activity

Reply to How to embed List in ScrollView using SwiftUI
Hi Jim Dovey, You are right. I didn't realize that List can already let me scroll for the content more than one screen. The ForEach solution works for me because it seems to support more than 10 items inside.Thank you!struct ContentView: View { var body: some View { List { ForEach(1 ... 100, id: \.self ) { x in VStack { Text("dfsf") Text("sfsdfj") } } }.padding(10) } }
Dec ’19
Reply to SwiftUI equivalent to viewWillTransition event in UIKit?
A solution is figured out: I don't need to use the viewWillTransition event. Below is the code I wrote:import SwiftUI import GoogleMobileAds import UIKit struct ContentView: View { var body: some View { VStack(alignment: .leading) { AdView().frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 300).border(Color.red, width: 5) } .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity) .border(Color.yellow, width: 2) } } struct AdView : UIViewRepresentable { @State private var banner: GADBannerView = GADBannerView(adSize: kGADAdSizeBanner) func makeUIView(context: UIViewRepresentableContext<AdView>) -> GADBannerView { banner.adUnitID = "ca-app-pub-3940256099942544/2934735716" banner.rootViewController = UIApplication.shared.windows.first?.rootViewController banner.load(GADRequest()) return banner } func updateUIView(_ uiView: GADBannerView, context: UIViewRepresentableContext<AdView>) { banner.adSize = kGADAdSizeBanner banner.load(GADRequest()) } }When the device (in simulator) rotates, the AD size changed.
Dec ’19
Reply to NavigationLinks only work once?
I encountered the same situation when running app in simulator. I found that it is only for simulator with iOS 13.3. Below are my test resultsiPhone 8 simulator with iOS 13.3 --- there is issue: NavigationLink no long work after navigating backiPhone 8 simulator with iOS 13.2.2 --- OKa physical iPhone with iOS 13.3 --- OKluckly seems this is a simulator only issue and it is only for iOS 13.3. I hope it can be fixed in next iOS version.
Dec ’19
Reply to How to have a popup alert followed by a navigation push?
I found a work-around: use .sheet modifier instead of .alert modifier, such that I can use the onDismiss closure to toggle the state variable for navigation link after message is dismissed.Reference: htt ps:// swiftwithmajid.com/2019/07/24/alerts-actionsheets-modals-and-popovers-in-swiftui/However, I feel that this solution is pretty complicated, and wondering whether there is any better idea.
Dec ’19
Reply to How to have a popup alert followed by a navigation push?
Thank you Claude31!The code I initially posted was modified from some complicated original code to present the issue in a simple way, and I didn't put it back to test before posting. Thank you for checking this and correcting it. For other reader's convenience, I pasted your code to a single view project and update it to make sure it works. I got:struct ContentView: View { @State var showDetail: Bool = false @State private var displayPopupMessage: Bool = false var body: some View { NavigationView { VStack { NavigationLink(destination: DetailView(), isActive: self.$showDetail) { EmptyView() } Button(action: { self.displayPopupMessage = true }) {Text("Alert and Navigate")} .alert(isPresented: $displayPopupMessage){ Alert(title: Text("Warning"), message: Text("This is a test"), dismissButton: .default(Text("OK"), action: {self.showDetail = true}) ) } } } } } struct DetailView :View { var body: some View {Text("details ...")} }Above code was tested in a project to be fully working. I added the NavigationView to make sure it works in a separate project.This solution confirms that each section of code should only make one popup message or navigation change.Thank you!
Dec ’19
Reply to How to get the current scene of the iOS14 app developed by XCode 12 and SwiftUI?
Just an update of the status, for now I set the "Enable Multiple Windows" in info.plist to false, such that I don't need to get the scene for now. The original reason I want to get the scene object is because I am trying to use Google Admob in an iOS app for iPad. Since iPad by default supports multiple windows, Admob is asking me to input scene. After disabling multiple windows, AdMob is no longer asing for it. Google AdMob link is not allowed to be posted in the forum, so I cannot include it.
Apr ’21