Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy failure:Invalid with native ScrollViewReader #1

Open
wisepmlin opened this issue Nov 16, 2021 · 0 comments
Open

proxy failure:Invalid with native ScrollViewReader #1

wisepmlin opened this issue Nov 16, 2021 · 0 comments

Comments

@wisepmlin
Copy link

ScrollView(.horizontal, showsIndicators: false)
{
ScrollViewReader
{ proxy in
LazyHStack(spacing: 0)
{
ForEach(0...timeLine.allDay(), id:.self)
{
dateItem in
VStack(spacing:0)
{
SK_Day(skDate: SKDate(
date: timeLine.getDateAtIndex(index: dateItem),
skManager: timeLine.skManager,
isDisabled: !timeLine.isEnabled(date: timeLine.getDateAtIndex(index: dateItem)),
isToday: timeLine.isToday(date: timeLine.getDateAtIndex(index: dateItem)),
isSelected: timeLine.isSpecialDate(date: timeLine.getDateAtIndex(index: dateItem)),
isBetweenStartAndEnd: timeLine.isBetweenStartAndEnd(date: timeLine.getDateAtIndex(index: dateItem))),
cellWidth: 24)

                        ZStack(alignment: .top)
                        {
                            SubDayTaskRow()
                            SubTimeLineObject(selectedNum: $selectedNum, date: dateItem)
                                .onTapGesture(perform: {
                                    timeLine.hiddenNeedleMaxTime = 3
                                    self.selectedNum = dateItem
                                    timeLine.wakeUp = timeLine.getDateAtIndex(index: dateItem)
                                })
                        }
                        .background(Color.p_c)
                        .border(width: 0.5, edges: [.top, .trailing], color: .s_c.opacity(colorScheme == .dark ? 0.5 : 1))
                    }
                    .id(dateItem)
                    .frame(width: timeLine.rowFixedWidth)
                    .zIndex(self.selectedNum == dateItem ? timeLine.selectedIndex : 0)
                    .onChange(of: timeLine.wakeUp, perform: {
                        value in
                        withAnimation(Animation.easeInOut){
                            proxy.scrollTo(timeLine.toThisDay(), anchor: .center)
                        }
                    })
                }
            }
        }
        .background(Color.p_c)
    }
    .scrollOffsetX(self.$offsetX)
    .onChange(of: self.offsetX, perform: {
        _ in
        offsetToHere.set(self.offsetX, forKey: "userData2")
    })
    .onAppear(perform: {
        guard let loaded = offsetToHere.object(forKey: "userData2") as? CGFloat else {
            return
        }
        self.offsetX = loaded
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant