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

after pop,the previous scrollview auto scroll to top? #81

Open
zgy0x01 opened this issue Sep 15, 2022 · 6 comments
Open

after pop,the previous scrollview auto scroll to top? #81

zgy0x01 opened this issue Sep 15, 2022 · 6 comments

Comments

@zgy0x01
Copy link

zgy0x01 commented Sep 15, 2022

how can i keep scrollview at the old posiiton after pop?

@zgy0x01
Copy link
Author

zgy0x01 commented Sep 16, 2022

well,i find a solution which mat be a little ugly but work :)

we can change how navigationview show .if the view is not current view ,we set its opacity to 0,in this case ,the view is still there, when it come to top,swiftui wont redraw it .

        Group {
          rootView
              .transition(navigationType == .push ? transitions.push : transitions.pop)
              .environmentObject(navigationStack)
              .opacity(showRoot ? 1.0 : 0.0)
              .allowsHitTesting(showRoot ? true : false)
            ForEach(navigationStack.viewStack.views){item in
              if(item.id == navigationStack.currentView!.id)
              {
                item.wrappedElement.transition(navigationType == .push ? transitions.push : transitions.pop)
                  .environmentObject(navigationStack)
              }
              else
              {
                item.wrappedElement.opacity(0).allowsHitTesting(false)
              }
            }
        }

to do this ,you need to remove 'private' before may properties. like viewstack,views.

@zgy0x01
Copy link
Author

zgy0x01 commented Sep 16, 2022

it's a little bit track , and may have other bug.

@zgy0x01
Copy link
Author

zgy0x01 commented Sep 19, 2022

not work!this can only keep root view not change ,but other view in foreach still redraw every time.

@zgy0x01
Copy link
Author

zgy0x01 commented Oct 8, 2022

well , i found another ugly solution.in this way,you should mannully set the stack depth.

{
rootView
.transition(navigationType == .push ? transitions.push : transitions.pop)
.environmentObject(navigationStack)
.opacity(showRoot ? 1.0 : 0.0)
.allowsHitTesting(showRoot ? true : false)
if(navigationStack.viewStack.views.count >= 1)
{
navigationStack.viewStack.views[0]
.wrappedElement
.transition(navigationType == .push ? transitions.push : transitions.pop)
.environmentObject(navigationStack)
.opacity(navigationStack.viewStack.views.count==1 ? 1.0 : 0.0)
.allowsHitTesting(navigationStack.viewStack.views.count==1 ? true : false)
}
if(navigationStack.viewStack.views.count >= 2)
{
navigationStack.viewStack.views[1]
.wrappedElement
.transition(navigationType == .push ? transitions.push : transitions.pop)
.environmentObject(navigationStack)
.opacity(navigationStack.viewStack.views.count==2 ? 1.0 : 0.0)
.allowsHitTesting(navigationStack.viewStack.views.count==2 ? true : false)
}
if(navigationStack.viewStack.views.count >= 3)
{
navigationStack.viewStack.views[2]
.wrappedElement
.transition(navigationType == .push ? transitions.push : transitions.pop)
.environmentObject(navigationStack)
.opacity(navigationStack.viewStack.views.count==3 ? 1.0 : 0.0)
.allowsHitTesting(navigationStack.viewStack.views.count==3 ? true : false)
}
if(navigationStack.viewStack.views.count >= 4)
{
navigationStack.viewStack.views[3]
.wrappedElement
.transition(navigationType == .push ? transitions.push : transitions.pop)
.environmentObject(navigationStack)
.opacity(navigationStack.viewStack.views.count==4 ? 1.0 : 0.0)
.allowsHitTesting(navigationStack.viewStack.views.count==4 ? true : false)
}
}

@zgy0x01
Copy link
Author

zgy0x01 commented Oct 8, 2022

just list every view out,and set the opt decide on current depth

@sethpoly
Copy link

It looks like the references to the views are released whenever we push another view on top in this library. This is opposite to what native SwiftUI and UIKit do. Views should usually remain in memory until removed from the stack. Use a similar library like https://github.com/AlexRoar/PathPresenter which follows the usual standards.

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

2 participants