Post

Replies

Boosts

Views

Activity

Swiftui - SKStoreProductViewController inside .sheet action open 2 views - why?
Hi, In my app, a button should be pressed and then the App Store product page of a specific app should be displayed within the application. My solution creates a UIViewControllerView of the Apple product page with .sheet. Unfortunately, an empty view appears first and a little later the App Store product page is displayed too and the empty view is in the background. If you then close the App Store page, you also have to close the empty view until you are back in the ContentView. Here are a screenshot. How can I prevent the blank page or what do I have to adjust in my code so that the page does not appear? Here is my code. import SwiftUI struct ContentView: View { @State private var showAppStore = false var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) .onTapGesture { self.showAppStore.toggle() } .sheet(isPresented: $showAppStore) { AppStoreProductView() } Text("Hello, world!") } .padding() } } import SwiftUI struct AppStoreProductView: UIViewControllerRepresentable { typealias UIViewControllerType = ViewController func makeUIViewController(context: Context) -> ViewController { return ViewController() } func updateUIViewController(_ uiViewController: ViewController, context: Context) { uiViewController.openAppStore() } } import StoreKit class ViewController: UIViewController { let appURL = URL(string: "https://itunes.apple.com/app/idxxxxxxxx")! let productID = xxxxxxxx func openAppStore() { let appStoreVC = SKStoreProductViewController() appStoreVC.delegate = self let parametersDictionary = [SKStoreProductParameterITunesItemIdentifier: productID] appStoreVC.loadProduct(withParameters: parametersDictionary) { loaded, error in guard error == nil, loaded else { return } self.present(appStoreVC, animated: true) } } } extension ViewController: SKStoreProductViewControllerDelegate { func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) { viewController.dismiss(animated: true) } } Many thanks in advance for any help to eliminate the blank view. Sven
2
0
1.2k
Dec ’23
Is it possible to navigate to the same view with navigation link and a button which activate a navigation link?
Hi, I have an app which creates a grid layout with the help of LazyVGrid. Each grid item has a navigation link to the target view with parameters for the target view. Inside the grid item exists a menu button. When the user click on the menu button, the action should get the grid item valus and pass it to the same target view with the same paramters but with other values for the parameters. Is that possible? I tried it several hours without success. I tried the code below and get the following error message. SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug. ContenView import SwiftUI struct GameData {   var id: Int   var name: String } struct ContentView: View {       @State private var games = [GameData]()       @State private var showSameTargetView = false       @State private var modeValue = false       let taskHSpace: CGFloat = -30   let taskVSpace: CGFloat = 20       var body: some View {           NavigationView() {               let columns = Array(         repeating: GridItem(. flexible(), spacing: taskHSpace), count: 2)               LazyVGrid(columns: columns, spacing: taskVSpace) {                   ForEach(self.games, id: \.id) {game in                       NavigationLink(             destination: TargetView(id: game.id, gameName: game.name, mode : false)           ) {                           HStack {                               Image(systemName: "person")                 .resizable()                 .frame(width: 75, height: 100)                 .padding(15)                               VStack(alignment: .leading, spacing: 10) {                                   Text("\(game.name)")                   .font(.custom("Chalkduster", fixedSize: 18))                   .foregroundColor(Color(UIColor.brown))                   .padding(.top)                                   Spacer()               }                               Spacer()                               VStack(alignment: .leading) {                                   Menu(content: {                                       Button(action: {                     self.modeValue = true                     self.showSameTargetView = true                   }) {                     Text("Show Target View")                     Image(systemName: "square.and.pencil")                   }                 }) {                   Image(systemName: "ellipsis.circle")                     .font(.title2)                     .foregroundColor(.gray)                     .padding(20)                 }                 .id(UUID()) // temp. bug fix - https://developer.apple.com/forums/thread/692338                 .onTapGesture {} // override - avoid NavigationLink action                                   NavigationLink(destination: TargetView(id: game.id, gameName: game.name, mode : self.modeValue), isActive: self.$showSameTargetView)                 { EmptyView() }                                   Spacer()               }             }             .frame(width: 300, height: 140, alignment: .topLeading)             .background(Color.yellow)           }         }       }     }     .onAppear {       if self.games.count == 0 {         self.games.append(           GameData.init(id: 1, name: "Test1")         )         self.games.append(           GameData.init(id: 2, name: "Test2")         )         self.games.append(           GameData.init(id: 3, name: "Test3")         )       }     }     .navigationViewStyle(StackNavigationViewStyle()) // remove default split view     .navigationBarBackButtonHidden(true)     .accentColor(.black)   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } } Navigation is possible but is it the right approach to reach my goal? Many thanks in advance. Sven
1
0
1.3k
Mar ’22
NavigationLink destination - Set view programmatically
Hi, I am programming a treasure hunt for my daughter. The main view consists of several NavigationLinks as image. If you click on a task (=image), the view of the individual task comes. Each tasks view is different. HStack(alignment: .top, spacing: 20) { NavigationLink( destination: Task01View() ) { Text("1. Aufgabe") .font(.custom("Chalkduster", fixedSize: 16)) .foregroundColor(Color(UIColor.brown)) // ... } NavigationLink( destination: Task02View() ) { Text("2. Aufgabe") .font(.custom("Chalkduster", fixedSize: 16)) .foregroundColor(Color(UIColor.brown)) // ... } NavigationLink( destination: Task03View() ) { Text("3. Aufgabe") .font(.custom("Chalkduster", fixedSize: 16)) .foregroundColor(Color(UIColor.brown)) // ... } // More NavigationLinks } The app has 24 tasks. There is a separate view for each task. Currently I am hard-coding the navigation links into the source code. However, my goal is to use a For loop to generate the images with the NavigationLinks. But my problem is the destination parameter in the NavigationLink. How can I set the required view (e.g. Task01View or Task04View) automatically? My idea. for task in (1...6) { NavigationLink( destination: ??? // Here is my problem ) { Text("\(task). Aufgabe") .font(.custom("Chalkduster", fixedSize: 16)) .foregroundColor(Color(UIColor.brown)) } Thanks in advance for the support.
2
0
765
Oct ’21
SwiftUI - CustomSearchBar - Event for clicking on the circle with the X in the text field
Hello everybody, i have an application with a CustomSearchBar to search in my list entries. To generally hide the keyboard (click outside the text field to search), I use this code. // Dismiss the keyboard self.endEditing(true) ... // Import for dissmissing Keyboard extension View { 		func endEditing(_ force: Bool) { 				UIApplication.shared.windows.forEach { $0.endEditing(force)} 		} } That works great. Now I would like to hide the keyboard, too, if I click on the x on the very right of the text field. Which event do I have to intercept then? I do not really know what I have to look for. Thanks in advance. Sven
2
0
434
Dec ’20