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

Implement complex items interaction (cards stack) #195

Closed
bd-arc opened this issue Oct 24, 2017 · 3 comments
Closed

Implement complex items interaction (cards stack) #195

bd-arc opened this issue Oct 24, 2017 · 3 comments
Assignees
Labels

Comments

@bd-arc
Copy link
Contributor

bd-arc commented Oct 24, 2017

The goal is to implement the following kind of interaction, relying only on the FlatList component and on Animated interpolations. It might not be possible, but we need to find out :-)

Event-cards-iOS-interaction, by Divan Raj
react-native-snap-carousel advanced layout idea

Onboarding, by Luobing
react-native-snap-carousel advanced layout idea

InVision Studio - Movies app concept, by Charles Patterson for InVision
react-native-snap-carousel advanced layout idea

@bd-arc bd-arc added the feature label Oct 24, 2017
@bd-arc bd-arc self-assigned this Oct 24, 2017
@bd-arc bd-arc changed the title Implement complex items interaction Implement complex items interaction (cards stack) Jan 9, 2018
@bd-arc
Copy link
Contributor Author

bd-arc commented Jan 23, 2018

See also #244

@bd-arc
Copy link
Contributor Author

bd-arc commented Jan 23, 2018

And yes, this is possible 🎉

react-native-snap-carousel custom animations

    _initPositionsAndInterpolators (props = this.props) {

        [...]

            } else {
                animatedValue = this._scrollPos.interpolate({
                    inputRange: [
                        (_index - 3) * sizeRef,
                        (_index - 2) * sizeRef,
                        (_index - 1) * sizeRef,
                        _index * sizeRef,
                        (_index + 1) * sizeRef
                    ],
                    outputRange: [3, 2, 1, 0, -1],
                    extrapolate: 'clamp'
                });
            }

            interpolators.push(animatedValue);
        });

        this.setState({ interpolators });
    }
    _renderItem ({ item, index }) {
        const { interpolators } = this.state;
        const {
            data,
            ...
        } = this.props;

        const animatedValue = interpolators && interpolators[index];

        if (!animatedValue && animatedValue !== 0) {
            return false;
        }

        [...]

        const animatedStyle = animate ? {
            zIndex: data.length - index,
            opacity: animatedValue.interpolate({
                inputRange: [-1, 0, 1, 2, 3],
                outputRange: [1, 1, 0.75, 0.5, 0]
            }),
            transform: [{
                scale: animatedValue.interpolate({
                    inputRange: [-1, 0, 1, 2, 3],
                    outputRange: [0.9, 1, 0.9, 0.8, 0.8]
                })
            }, {
                translateX: animatedValue.interpolate({
                    inputRange: [-1, 0, 1, 2, 3],
                    outputRange: [
                        -itemWidth * 0.5,
                        0,
                        -itemWidth * 0.99,
                        -itemWidth * 2.25,
                        -itemWidth * 3.45
                    ]
                })
            }]
        } : {};

        [...]
    }

I'm now going to work on adding the ability to use a custom interpolator like this one.

@bd-arc
Copy link
Contributor Author

bd-arc commented Jan 29, 2018

Feature released in version 3.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant