zachgibson / react-native-parallax-swiper

Paged Parallax Swiper with Effects
MIT License
623 stars 76 forks source link

Way to prevent "Going back" #16

Closed asciifaceman closed 6 years ago

asciifaceman commented 6 years ago

Is there a conceivable way to prevent the user from swiping back to previous pages? I was thinking that popping the data or unloading data might work, but don't want to go down a crazy data manipulation hole unless there is something else.

asciifaceman commented 6 years ago

This works to get the idea across in a very hacky and ugly way, but if it was possible to make it invisible to the user...

It seems the problem is since I'm popping from the array that it "scrolls back" to the new 0.

onMomentumScrollEnd={activePageIndex => this.popOldData(activePageIndex)}
  popOldData(index) {
    if (index === this.state.previousIndex) {
      return
    }
    newdata = this.state.data.slice(this.state.previousIndex);
    this.setState({previousIndex: index});
    this.setState({data: newdata});
  }

Edit:

This is possible to achieve in reverse since pop'ing from the end and scrolling backwards (by setting scrollToIndex to data.length -1 on load), but digging through the source of parallax-swiper this might not be possible just due to the nature of rendering via array.map and RN's ScrollView limitations.

  componentWillMount() {
    this.setState({data: demoData});
    this.setState({scrollIndex: demoData.length-1});
    this.setState({previousIndex: demoData.length-1});
  }

  popOldData(index) {
    if (index == this.state.previousIndex) {
      return
    }
    newData = this.state.data;
    newData.pop();
    this.setState({data: newData});
    this.setState({scrollIndex: newData.length-1});
    this.setState({previousIndex: index});
  }
zachgibson commented 6 years ago

Hey @asciifaceman! Interesting concept you propose here. I tried this a couple of different ways and man, it does not like updating the data. I did get some cool glitch effects tho. 😆

I’m gonna try this with a plain ol’ ScrollView without any fancy parallax and see if it still behaves this way. Otherwise there might be some other approaches to manipulate scroll ability to achieve what you’re looking for.

asciifaceman commented 6 years ago

Yeah, @zachgibson I played around with it for a solid 3-4 hours.

Fundamentally the map renders in order from 0 to length-1. And those are added as children. If you start from the end and move back, popping works fine, but popping the other direction triggers a rerender of the children since indexing changed. I did find this, however:

https://github.com/ridgeO/react-native-card-stack/tree/master/src

Programmatically this only "renders" 3 cards a time in the stack already indexed in reverse and then brings in more (check the README.md for implementation example). If we could find a way to replicate this technique with parallax swiper it would be amazingly powerful and beautiful card stack machine.

Not to detract from it the way it is, just another use case.

tl;dr we might be able to support this if we migrate to flatlist? When I get out of work I might fork and dig further.

zachgibson commented 6 years ago

I’ve thought about this a bit and I think react-native-parallax-swiper and what you’re looking for are two different things. This component is meant to be a vertical or horizontal paged list where you can scroll/swipe back and forth and see the previous, current, and next “Page”—not really a 3D space of cards. I tried converting to a FlatList for the sake of seeing if I could accomplish this but I could not as even though it removes views outside of the specified window you still can scroll backwards/forwards.

asciifaceman commented 6 years ago

Yeah I just really wanted the "look" of your swiper (which looks amazing) just with it gobbling already scrolled results behind it. The idea was an "always fresh" content in the scroll being paginated with continuation tokens etc etc I had that part already figured out haha.

zachgibson commented 6 years ago

Hey @asciifaceman I’m still not seeing a way to do this as I think what you’re referring to happens in the z space i.e. 3D not 2D. Can you provide a visual or something to help clarify? Otherwise I’m going to close out this issue.

asciifaceman commented 6 years ago

Yeah I agree it isn't within the scope of your swiper and would likely have to be its own project. I think it's just a limitation of the basic components.

The best way to describe it would be every time you swiped say vertically in your swiper you could never swipe back and the old content would be recycled for memory savings.

But this isn't cleanly possible with the scroll view. So it's all good, I just don't feel up to attempting it myself just yet. I might be able to do it by starting with a card stack style structure and just wrap it in some parallaxing but that is entering "how the hell do I do this" territory haha.

zachgibson commented 6 years ago

Well if you want to make this a thing, hit me up for help with the parallax/animation part and I gotchu. 👍

asciifaceman commented 6 years ago

@zachgibson https://cdn-images-1.medium.com/max/800/0*6axAOzGiu53dLA9k.gif

What are your thoughts on this and its feasibility in RN? I know I"m asking in an old issue, but 🤷‍♂️

zachgibson commented 6 years ago

@asciifaceman Totally feasible in React Native. Not with this component, but using Animated.ScrollView and the Animated API to get these transitions wouldn’t be too hard.

asciifaceman commented 6 years ago

Yeah I was thinking in line with a new component @zachgibson if you want involved

zachgibson commented 6 years ago

Which part of the GIF are you thinking will be the functionality?

asciifaceman commented 6 years ago

The swiping and animation portions, not the content itself so much. Like the categories and switching between the funnel, list views