1

The below code seems to work fine on an iPhone 13 mini but stutters or sticks when scrolling on an iPhone 13, not every time but often. The code for the Calendar is here. What could be causing this? 🤔

struct MasterCalendarWithDay: View {
    
    @Environment(\.calendar) var calendar
    
    @State private var selectedDate: Date?
    
     @State private var selectedTabIndex = 0
    
    private var month: DateInterval {
        //calendar.dateInterval(of: .year, for: Date())!
        DateInterval(start: Calendar.current.date(byAdding: .month, value: show6Months ? -6 : -1, to: Date())!, end: Date())
    }
    
    var body: some View {
        LoadingView(isShowing: $isLoadingRecoveryData, text: show6Months ? "Loading past 6 months of data.  This may take a few seconds." : "Loading...") {
            NavigationView {
                ScrollView {
                    ScrollViewReader { value in
                        VStack {
                            ZStack {
                                CalendarView(interval: month) { date in
                                    if date <= Date() {
                                    Button(action: { self.selectedDate = date }) {
                                      //Omitted
                                      
                                    }.buttonStyle(PlainButtonStyle())
                                    }
                                } // end of calender
                                .onAppear {
                                    value.scrollTo(Date().startOfDay())
                            }
                        } //end of Zstack
                    }
                }
            } //end of scroll view
            .coordinateSpace(name: "pullToRefreshInRecoveryCalendar")
            .navigate(using: $selectedDate, destination: makeDestination) 
            }
            .navigationViewStyle(.stack) //This asks SwiftUI to only show one view at a time, regardless of what device or orientation is being used, and prevents constraint warnings in console log.  From: https://www.hackingwithswift.com/articles/216/complete-guide-to-navigationview-in-swiftui
             .onChange(of: selectedTabIndex, perform: { value in
        })
        }
    }
1
  • I'm commenting as I'm unsure it would be an answer, per se, but maybe accessing Metal for rendering would help? I'm referencing Paul Hudson here: hackingwithswift.com/books/ios-swiftui/… Commented Jun 30, 2022 at 7:29

1 Answer 1

0

I think your ScrollView should be nested inside the ScrollViewReader.

var body: some View {
    ScrollViewReader { value in
        ScrollView {
                ...

See https://developer.apple.com/documentation/swiftui/scrollviewreader

Sign up to request clarification or add additional context in comments.

2 Comments

Make sure that your answer contains enough details for the OP for resolve their question. Links should only supplement or support your answer and not be the answer itelft.
Thanks but nesting the ScrollView inside the ScrollViewReader did not resolve this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.