2

I want to make extendable list in scrollview. I use top of the scrollview global location but when I extend section top location decreased and relocated.

Example Code :

ScrollView{
            VStack{

                GeometryReader{ reader -> AnyView in
                    print("\(reader.frame(in: .global).minY)")
                    return AnyView(Text("\(reader.frame(in: .global).minY)").onTapGesture {
                        self.isExtended.toggle()

                    })
                }
                Text("Test").onTapGesture {
                    self.isExtended.toggle()

                }
                if isExtended{
                    ForEach(0..<10,id:\.self){ index in
                        Text("\(index)")
                    }
                }

            }
        }

Output

1
  • The code you have posted does not appear to relocate when the expanded section is toggled. Are you making changes to hide the status bar? Commented Nov 14, 2019 at 22:13

1 Answer 1

0

All works as expected. By reader.frame(in: .global).minY you get ScroolView content view's minY (and not ScroolView's itself as you might expected) allowed position for spring effect when you drag upward out of screen. Try to drag and you see it in debug output.

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

2 Comments

I know it is content minY. MinY decreased when i tap extend and also it increased normal position in miliseconds. It works well when i drag scrollview.
ok, then please clarify the question, because I don't observe anything 'weird' in how provided code behaves.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.