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
        })
        }
    }
GarySabo
  • 5,806
  • 5
  • 49
  • 124
  • 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: https://www.hackingwithswift.com/books/ios-swiftui/enabling-high-performance-metal-rendering-with-drawinggroup – weo3dev Jun 30 '22 at 07:29

1 Answers1

1

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

Nihal Harish
  • 980
  • 5
  • 13
  • 31
Vaz
  • 309
  • 2
  • 15
  • 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. – Nihal Harish Mar 31 '22 at 22:23
  • Thanks but nesting the ScrollView inside the ScrollViewReader did not resolve this issue. – GarySabo Apr 01 '22 at 00:54