blsage / iPages

Quickly implement swipable page views.
170 stars 16 forks source link

Change state in parent view of iPage will trigger unwanted animation #8

Closed DechengMa closed 3 years ago

DechengMa commented 4 years ago

Hi there, thanks for the quick fix yesterday now it works like charm!

Just encounter another issue, when I change the state of iPage parents view, iPage will trigger an unwanted animation.

Example code:

struct TabViewParentView: View {
    @State var selectedIndex: Int = 0
    @State var tabViewIsHidden: Bool = false

    var body: some View {
        ZStack {
            iPages(selection: $selectedIndex) {
                ProfileView()
                SecondView()
                ThirdView()
            }
            .hideDots(true)

            VStack {
                Button {
                    tabViewIsHidden = !tabViewIsHidden
                } label: {
                    Text("HELLO THERE!")
                }

                Spacer()

                Text("TEXT")
                    .foregroundColor(.white)
                    .opacity(tabViewIsHidden ? 0 : 1)
            }
        }
    }

}

When the button pressed and @State tabViewIsHidden was changed, the iPage will scroll to the same page with animation:

Demo:

Screen Recording 2020-10-27 at 1 30 29 pm

I wonder if it is possible to prevent this? This is needed for making my custom tab view control, I was making an auto dismissed tab view control, but when I change the state, this unwanted animation was triggered.

blsage commented 4 years ago

Ah, this is quite interesting. Please give me a minute to look into it.

blsage commented 3 years ago

Should be fixed! I also added a .animated(_:) modifier which can allow you to disable animation altogether. 😀