Post

Replies

Boosts

Views

Activity

Animates wrongly at every switch of direction, animates right in same direction
I need to create an animation for previous and next questions. The current question should move out and next/prev question should come in. If you run the app and keep pressing next, it works well. Current question moves out towards left Next question appears from right to left. But if I switch the direction to previous, Current question moves out towards left( should move out towards right) next question comes in from left to right( which is correct). Similar discrepancy happens when I switch direction from prev to next. Why is this so? import SwiftUI struct Question { let id: Int let text: String } extension AnyTransition { static var slideRight: AnyTransition { let insertion = AnyTransition.move(edge: .trailing) let removal = AnyTransition.move(edge: .leading) return .asymmetric(insertion: insertion, removal: removal) } static var slideLeft: AnyTransition { let insertion = AnyTransition.move(edge: .leading) let removal = AnyTransition.move(edge: .trailing) return .asymmetric(insertion: insertion, removal: removal) } } struct QuizView: View { let questions = [ Question(id: 1, text: "11111111111"), Question(id: 2, text: "222222222222222222222222"), Question(id: 3, text: "3333333333333333333"), Question(id: 4, text: "444444444444444444444444"), Question(id: 5, text: "55555555555555555555"), Question(id: 6, text: "6666666666666666666666666") ] @State private var currentQuestionIndex = 0 @State private var navigationDirection: NavigationDirection = .forward var body: some View { VStack(spacing: 20) { Text(questions[currentQuestionIndex].text) .id(questions[currentQuestionIndex].id) // Important for transition .transition(navigationDirection == .forward ? .slideRight : .slideLeft) .frame(maxWidth: .infinity, maxHeight: .infinity) HStack { Button("Previous") { moveToPreviousQuestion() } .disabled(currentQuestionIndex == 0) Spacer() Button("Next") { moveToNextQuestion() } .disabled(currentQuestionIndex == questions.count - 1) } } .padding() .animation(.easeInOut(duration: 1.0), value: currentQuestionIndex) } private func moveToNextQuestion() { if currentQuestionIndex < questions.count - 1 { navigationDirection = .forward currentQuestionIndex += 1 } } private func moveToPreviousQuestion() { if currentQuestionIndex > 0 { navigationDirection = .backward currentQuestionIndex -= 1 } } } enum NavigationDirection { case forward, backward }
0
0
513
Apr ’24
iPad - List View - background to foreground - moves up
Please help. Happens only in iPad device Run the app, looks fine. Press home button, select app, below mentioned bugs happen (sometimes first time, sometimes 2nd, 3rd, 4th time) The list in the sidebar moves up (space between top nav bar and list is lost) The detail view's toolbar's items vanish (principal, leading, trailing vanish, bottom stays) import SwiftUI struct ContentView: View { var body: some View { NavigationSplitView { // Leading side (typically a list or navigation links) List { NavigationLink("Item 1", destination: detailView(text: "Detail View for Item 1")) NavigationLink("Item 2", destination: detailView(text: "Detail View for Item 2")) NavigationLink("Item 3", destination: detailView(text: "Detail View for Item 3")) NavigationLink("Item 4", destination: detailView(text: "Detail View for Item 4")) NavigationLink("Item 5", destination: detailView(text: "Detail View for Item 5")) NavigationLink("Item 6", destination: detailView(text: "Detail View for Item 6")) NavigationLink("Item 7", destination: detailView(text: "Detail View for Item 7")) NavigationLink("Item 8", destination: detailView(text: "Detail View for Item 8")) NavigationLink("Item 9", destination: detailView(text: "Detail View for Item 9")) NavigationLink("Item 10", destination: detailView(text: "Detail View for Item 10")) NavigationLink("Item 11", destination: detailView(text: "Detail View for Item 11")) NavigationLink("Item 12", destination: detailView(text: "Detail View for Item 12")) NavigationLink("Item 13", destination: detailView(text: "Detail View for Item 13")) NavigationLink("Item 14", destination: detailView(text: "Detail View for Item 14")) NavigationLink("Item 15", destination: detailView(text: "Detail View for Item 15")) NavigationLink("Item 16", destination: detailView(text: "Detail View for Item 16")) NavigationLink("Item 17", destination: detailView(text: "Detail View for Item 17")) NavigationLink("Item 18", destination: detailView(text: "Detail View for Item 18")) } .toolbar { ToolbarItem(placement: .principal) { Text("Items") } ToolbarItem(placement: .navigationBarLeading) { Button(action: { let _ = print("going back to main screen") }) { Image(systemName: "chevron.left") } } } } detail: { // Default detail view when nothing is selected Text("Select an Item") } } // Function to generate a detail view with a principal toolbar item @ViewBuilder func detailView(text: String) -> some View { Text(text) .toolbar { ToolbarItem(placement: .principal) { Text(text) } ToolbarItem(placement: .navigationBarTrailing) { Text("Trailing") } ToolbarItem(placement: .bottomBar) { Text("Bottom") } } } } // Preview struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
1
0
351
Apr ’24
iPad parent child refreshing issue - onAppear is NOT getting called every single time.
This code works well in iPhone but not on iPad. In iPad, although the "Selected topic" text in TopicDetailView changes with every list selection, **onAppear is NOT getting called every single time. ** I need to do some backend operation on onAppear here. What am I doing wrong here? At first it looks like working fine, but go backward tapping in list, random tapping, every time, "selected topic " changes, but NOT every time onAppear gets called. I must have the onAppear called every time to run backend operations. I have latest devices, simulators, Xcode as of today. I cannot use NavigationStack as I need to support ios15.0 onwards import SwiftUI struct TopicsView: View { var topics = ["Topic1","Topic2","Topic3"] var body: some View { NavigationView { List(topics, id:\.self ) { topic in NavigationLink( destination: TopicDetailView(topic: topic).id(UUID()) ) { Text(topic) } } } } } struct TopicDetailView: View { var topic: String var body: some View //body{ { VStack{ Text("Selected topic \(topic)") } .onAppear(){ print("on appear on topic \(topic)") } .onChange(of: topic){ v in print("on change to topic \(v)") } } } struct ContentView: View { var body: some View { TopicsView() } }
4
0
627
Sep ’23
In-App Purchase - AutoRenewPreference gives ID - subscription status is expired and expirationReason == .autoRenewDisabled
I am testing in-app subscription by installing x-code build locally. Everything works fine until I cancel subscription from phone's settings->app-store->manage. I have two issues then. How many times I run the app, re-build and re-run from xcode it shows the status 'subscribed'. If I delete the app from my phone and then re-install it shows the right status as 'expired. It also shows the expirationReason as 'autoRenewDisabled'. But renewalInfo.autoRenewPreference, which should be nil, still gives the product ID. The documentaton clearly states as below, but it does not follow the documentation! /// If the user disabled auto renewing, this property will be nil. public let autoRenewPreference: String?
0
0
463
Apr ’22
Exception Type: EXC_CRASH (SIGABRT)
Hi, my app is showing 180 crashes since its last release 10+ days ago. I am unable to reproduce the crash in the app from the App Store or local build. Please help. The customers are complaining. None of my code is shown in the crash log as the cause so unable to understand what's causing it. App link (its a free app): https://apps.apple.com/us/app/the-iq-test-lite-edition/id293165776 Crash Log - https://developer.apple.com/forums/content/attachment/3bc9773f-42f9-4f86-89ed-1bef0a86ec64
1
0
713
Sep ’20