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

🚀 What layout style do you want? #88

Closed
dohooo opened this issue Jan 7, 2022 · 60 comments
Closed

🚀 What layout style do you want? #88

dohooo opened this issue Jan 7, 2022 · 60 comments
Assignees
Labels
enhancement New feature or request

Comments

@dohooo
Copy link
Owner

dohooo commented Jan 7, 2022

Writing here!

BTW, looking forward to your PR!~ 🍺

@dohooo dohooo added the enhancement New feature or request label Jan 7, 2022
@dohooo dohooo self-assigned this Jan 7, 2022
@dohooo dohooo pinned this issue Jan 7, 2022
gxxgcn added a commit that referenced this issue Jan 8, 2022
give an example to show how to customize animation style

#88
gxxgcn added a commit that referenced this issue Jan 8, 2022
@dohooo
Copy link
Owner Author

dohooo commented Jan 8, 2022

scale-fade-in-out

@dohooo
Copy link
Owner Author

dohooo commented Jan 9, 2022

image

@dohooo
Copy link
Owner Author

dohooo commented Jan 9, 2022

image

@dohooo
Copy link
Owner Author

dohooo commented Jan 11, 2022

rotate-scale-fade-in-out

@dohooo
Copy link
Owner Author

dohooo commented Jan 11, 2022

rotate-in-out

@dohooo
Copy link
Owner Author

dohooo commented Jan 11, 2022

anim-tab-bar

@yepMad
Copy link
Contributor

yepMad commented Feb 26, 2022

Hello,

I want to do something like this. I believe the current "Parallax" solves this, but I have doubts about how to change the size of the item that is not in focus.
image

@dohooo
Copy link
Owner Author

dohooo commented Feb 26, 2022

Hello,

I want to do something like this. I believe the current "Parallax" solves this, but I have doubts about how to change the size of the item that is not in focus. image

https://github.com/dohooo/react-native-reanimated-carousel/blob/main/src/layouts/ParallaxLayout.tsx#L75 here

@yepMad
Copy link
Contributor

yepMad commented Feb 27, 2022

https://github.com/dohooo/react-native-reanimated-carousel/blob/main/src/layouts/ParallaxLayout.tsx#L75 here

Thank you! I actually turned this change into a property. In case you find it interesting, I can make a commit with it.

image

@dohooo
Copy link
Owner Author

dohooo commented Feb 27, 2022

cool,let me a look

@dohooo
Copy link
Owner Author

dohooo commented Feb 27, 2022

https://github.com/dohooo/react-native-reanimated-carousel/blob/main/src/layouts/ParallaxLayout.tsx#L75 here

Thank you! I actually turned this change into a property. In case you find it interesting, I can make a commit with it.

image

You are the first one to submit layout, thank you for your contribution!~

@yepMad
Copy link
Contributor

yepMad commented Feb 27, 2022

You are the first one to submit layout, thank you for your contribution!~

I am happy with that! You can see what I did in this PR. It was simple changes, and a little quick, let me know if there are any side effects or problems.
#139

@dohooo
Copy link
Owner Author

dohooo commented Feb 28, 2022

You are the first one to submit layout, thank you for your contribution!~

I am happy with that! You can see what I did in this PR. It was simple changes, and a little quick, let me know if there are any side effects or problems. #139

I released v2.3.1 just now, THX!~ @yepMad

@IAmNatch
Copy link

IAmNatch commented Mar 2, 2022

It would be great to have support for multiple items per a page. I was able to achieve this by setting the width to 50%, and adding a style of overflow: "visible", but this seems a bit hacky, as it's actually leaving the carousel wrapper entirely. As well, you'll notice when not looping the last element can still be scrolled to, leaving an awkward space. Ideally we could customize maxPages to something like data.length - itemsPerPage in order to prohibit the last swipe.

Happy to spend some time contributing to this if you could point me in the right direction.

Simulator Screen Recording - iPhone 13 - 2022-03-02 at 15 35 59

@IAmNatch
Copy link

IAmNatch commented Mar 2, 2022

One other request: "Auto Height" for horizontal layouts. I know this might not be possible, as the items are currently all positioned absolutely, but it would be great to be able to size to height of the carousel based on the height of the contents. This was achievable in snap-carousel, but they may have been using a very different strategy.

@dohooo
Copy link
Owner Author

dohooo commented Mar 3, 2022

@IAmNatch here, Let's discuss it

@testermumatstudio
Copy link

@IAmNatch were you able to figure this out, thanks for the help if you can

@testermumatstudio
Copy link

hello, where can I find an example to show more than one item

@dohooo
Copy link
Owner Author

dohooo commented Apr 8, 2022

hello, where can I find an example to show more than one item

What do you mean?

@testermumatstudio
Copy link

testermumatstudio commented Apr 9, 2022

https://user-images.githubusercontent.com/15078788/156445400-0c2a7f6c-7da2-40a9-9872-2669134bf535.gif some like this, display multiple items in carousel, where can i get this example , as mentioned @IAmNatch, if I want to display 1, 2, 4, 6 elements

@dohooo
Copy link
Owner Author

dohooo commented Apr 9, 2022

https://user-images.githubusercontent.com/15078788/156445400-0c2a7f6c-7da2-40a9-9872-2669134bf535.gif some like this, display multiple items in carousel, where can i get this example , as mentioned @IAmNatch, if I want to display 1, 2, 4, 6 elements

image

I added an example. You can look at this demo in home page, and click that gif it will navigate you to code example. 🍺

@dohooo
Copy link
Owner Author

dohooo commented Apr 9, 2022

https://user-images.githubusercontent.com/15078788/156445400-0c2a7f6c-7da2-40a9-9872-2669134bf535.gif some like this, display multiple items in carousel, where can i get this example , as mentioned @IAmNatch, if I want to display 1, 2, 4, 6 elements

BTW, This code will control the number of items that displaied.
image

@testermumatstudio
Copy link

https://user-images.githubusercontent.com/15078788/156445400-0c2a7f6c-7da2-40a9-9872-2669134bf535.gif some like this, display multiple items in carousel, where can i get this example , as mentioned @IAmNatch, if I want to display 1, 2, 4, 6 elements

BTW, This code will control the number of items that displaied. image

grateful for your help and your time, really thanks, I'm going to try and study the code

@Nadimkhan120
Copy link

@dohooo hi thanks for this amazing library,
can we use this as a swiper like tinder?

@testermumatstudio
Copy link

testermumatstudio commented May 25, 2022

¿Hola como estás? tengo un error no se si es mio o del carrusel a ver si me puedes ayudar el carrusel que tengo es web y horizontal cuando quiero hacer scroll la version web la version movil no me deja hacer scroll el dom el carrusel se mueve correctamente horizontalmente, pero no puedo hacer scroll si presiono la tarjeta que esta dentro del carrusel horizontal como lo soluciono, pongo el ejemplo en gif de regalo

¡Hola! Lamento que hayas pasado por esto. Esto está cubierto en README, como una buena práctica para ScrollView y FlatList (creo que también funciona en la web)

imagen

perfect, thank you very much for answering, I will try and commit, if I had read it but had not understood what this was for, I thought it was to move it in reference to which point could be made to slide inside the carousel on the x axis, the values of the activeoffsetx -10 10: could you tell me what they are for? since I don't have them clear from the documentation in a short summary, and should I use them in the carousel I have with activeoffsety ? since the carousel is horizontal?

@yepMad
Copy link
Contributor

yepMad commented May 25, 2022

perfect, thank you very much for answering, I will try and commit, if I had read it but had not understood what this was for, I thought it was to move it in reference to which point could be made to slide inside the carousel on the x axis, the values of the activeoffsetx -10 10: could you tell me what they are for? since I don't have them clear from the documentation in a short summary, and should I use them in the carousel I have with activeoffsety ? since the carousel is horizontal?

activeOffsetX should already solve your issue, it is intended for horizontal carousels (side to side) that are inside a scroll view. The "panGestureHandlerProps" property is from react-reanimated itself.

From the documentation of reanimated itself:

Range along X axis (in points) where fingers travels without activation of handler. Moving outside of this range implies activation of handler. Range can be given as an array or a single number. If range is set as an array, first value must be lower or equal to 0, a the second one higher or equal to 0. If only one number p is given a range of (-inf, p) will be used if p is higher or equal to 0 and (-p, inf) otherwise.

@OlehDeneka-docode
Copy link

OlehDeneka-docode commented Jun 3, 2022

@dohooo how can i disable bouncing?
And is there a way to display items like this without having to scale them?
Screenshot 2022-06-03 at 19 23 23

@dohooo
Copy link
Owner Author

dohooo commented Jun 3, 2022

@dohooo how can i disable bouncing?
And is there a way to display items like this without having to scale them?
Screenshot 2022-06-03 at 19 23 23

Disable bouncing

image

> Without scale.

https://github.com/dohooo/react-native-reanimated-carousel/blob/main/docs/custom-animation.md
You can customize the animation, Like this #128 , #128 (comment)

@OlehDeneka-docode
Copy link

oh man, thank you so much) guess i didnt look good enough in docs and issues

@quicksilverr
Copy link

anim-tab-bar

Just had a query regarding this, how can we make the highlighter from centre?

@wqcstrong
Copy link

https://user-images.githubusercontent.com/15078788/156445400-0c2a7f6c-7da2-40a9-9872-2669134bf535.gif some like this, display multiple items in carousel, where can i get this example , as mentioned @IAmNatch, if I want to display 1, 2, 4, 6 elements

image

I added an example. You can look at this demo in home page, and click that gif it will navigate you to code example. 🍺

How to center the active item?

@dohooo
Copy link
Owner Author

dohooo commented Jun 18, 2022

@wqcstrong @quicksilverr

Here.
Fold example

Tab-bar example

@aditya-keri-betterhalf
Copy link

@dohooo - Great work on this library, thank you for all the efforts on this!

I would love to know how I can implement this vertical stack animation in the Carousel ?

https://www.youtube.com/shorts/-lvrU34Jt50

I was able to achieve something similar on the horizontal with mode="stack" and snapDirection="left". I think if there was an option of snapDirection="bottom" or "top", I should be able to achieve the above animation ?

@dohooo
Copy link
Owner Author

dohooo commented Jun 24, 2022

@dohooo - Great work on this library, thank you for all the efforts on this!

I would love to know how I can implement this vertical stack animation in the Carousel ?

https://www.youtube.com/shorts/-lvrU34Jt50

I was able to achieve something similar on the horizontal with mode="stack" and snapDirection="left". I think if there was an option of snapDirection="bottom" or "top", I should be able to achieve the above animation ?

It's very easy..

@aditya-keri-betterhalf
Copy link

@dohooo - Great work on this library, thank you for all the efforts on this!
I would love to know how I can implement this vertical stack animation in the Carousel ?
https://www.youtube.com/shorts/-lvrU34Jt50
I was able to achieve something similar on the horizontal with mode="stack" and snapDirection="left". I think if there was an option of snapDirection="bottom" or "top", I should be able to achieve the above animation ?

It's very easy..

Would like to know how!

@dohooo
Copy link
Owner Author

dohooo commented Jun 24, 2022

@dohooo - Great work on this library, thank you for all the efforts on this!
I would love to know how I can implement this vertical stack animation in the Carousel ?
https://www.youtube.com/shorts/-lvrU34Jt50
I was able to achieve something similar on the horizontal with mode="stack" and snapDirection="left". I think if there was an option of snapDirection="bottom" or "top", I should be able to achieve the above animation ?

It's very easy..

Would like to know how!

RPReplay_Final1656070531.MP4

@aditya-keri-betterhalf
Copy link

@dohooo - Great work on this library, thank you for all the efforts on this!
I would love to know how I can implement this vertical stack animation in the Carousel ?
https://www.youtube.com/shorts/-lvrU34Jt50
I was able to achieve something similar on the horizontal with mode="stack" and snapDirection="left". I think if there was an option of snapDirection="bottom" or "top", I should be able to achieve the above animation ?

It's very easy..

Would like to know how!

RPReplay_Final1656070531.MP4

This is great! Exactly what I need. Could you please help me with the props you've used to achieve this ? or an example you've created ?

@dohooo
Copy link
Owner Author

dohooo commented Jun 25, 2022

@dohooo - Great work on this library, thank you for all the efforts on this!

I would love to know how I can implement this vertical stack animation in the Carousel ?

https://www.youtube.com/shorts/-lvrU34Jt50

I was able to achieve something similar on the horizontal with mode="stack" and snapDirection="left". I think if there was an option of snapDirection="bottom" or "top", I should be able to achieve the above animation ?

It's very easy..

Would like to know how!

RPReplay_Final1656070531.MP4

This is great! Exactly what I need. Could you please help me with the props you've used to achieve this ? or an example you've created ?

I have added to examples.

image

@in2progress
Copy link

Stellar work on this library. Wondering if a combination of vertical and horizontal mode is possible.

image

@dohooo
Copy link
Owner Author

dohooo commented Aug 29, 2022

Stellar work on this library. Wondering if a combination of vertical and horizontal mode is possible.

image

Thank you. It seems that it is not possible at present. More modifications are needed.

@dohooo dohooo changed the title What layout style do you want? 🚀 What layout style do you want? Sep 15, 2022
@dohooo dohooo closed this as completed Sep 15, 2022
@IAmNatch
Copy link

IAmNatch commented Oct 31, 2022

Hey @dohooo, I've been looking at your multiple example again, and I've been hitting an issue which I would call "overscrolling".

When the carousel is set to "loop", everything works as expected, however when loop is disabled, you can scroll the last element all the way to "position 1" instead of it being the last item in the carousel.

Current Implementation:

Slot 1 Slot 2 Slot 3
LastItem Empty Empty

Ideal Implementation

Slot 1 Slot 2 Slot 3
ThirdLastItem SecondLastItem LastItem

I've attached a minimal reproduction in expo here:
https://snack.expo.dev/@srobbins/reanimated-carousel-overscroll-example

I think this would be made possible by allowing us to set maxPages on the ScrollViewGesture, where maxPages would be totalItems.length - numberOfItemsOnScreen, however there would still be a slight problem of navigating to the last item.

Curious what you think about this!

Edit: I believe this is the same issue as #240.

@IAmNatch
Copy link

@dohooo I have a PR that adds support for this here:
#295

@dohooo
Copy link
Owner Author

dohooo commented Jan 10, 2023

@dohooo I have a PR that adds support for this here: #295

Solved in #297.

@ijhar-nivoda
Copy link

ijhar-nivoda commented Jan 23, 2023

oie_EZQUySpbhBoB
hey @dohooo , how can do style like this ? is it possible without parallax ?

@vbylen
Copy link

vbylen commented May 27, 2023

stacked card animations that look like this would be amazing:

https://www.youtube.com/watch?v=xPbRsca_l7c

@SinanAldefai
Copy link

SinanAldefai commented Jun 7, 2023

One other request: "Auto Height" for horizontal layouts. I know this might not be possible, as the items are currently all positioned absolutely, but it would be great to be able to size to height of the carousel based on the height of the contents. This was achievable in snap-carousel, but they may have been using a very different strategy.

Has someone already found a way for this? Or is it just not possible?

@rbhuzwandar
Copy link

How to use parallax mode, but hide the left nad right item. so the active item will show full width screen ?

@estebanfdiazp
Copy link

estebanfdiazp commented Nov 9, 2023

Screenshot 2023-11-09 at 17 22 59 Which layout should I use to achieve something like this?

@guircoelho
Copy link

Hi! I managed to dynamically retrieve the height of the carousel items. While it requires a bit more effort, it is possible as shown below:

How It Works:

  1. Measure Item Heights: Each item is rendered invisibly off-screen to capture its height using the measure function.
  2. Set Initial Height: The maximum height of all items is set as the initial height of the carousel.
  3. Update on Scroll: As the carousel scrolls, the height is dynamically updated based on the height of the currently visible item.
const Advertising = () => {
  const items = []; // TODO

  const carouselRef = React.useRef<ICarouselInstance>(null);
  const [activeSlide, setActiveSlide] = useState(0);
  const {width: screenWidth} = useWindowDimensions();
  const [itemHeights, setItemHeights] = useState([]);
  const [carouselHeight, setCarouselHeight] = useState(0);
  const itemRefs = useRef([]);

  useEffect(() => {
    const heights = items.map((item, index) => {
      return new Promise(resolve => {
        itemRefs.current[index]?.measure((x, y, width, height) => {
          resolve(height);
        });
      });
    });

    Promise.all(heights).then(heights => {
      setItemHeights(heights);
      setCarouselHeight(Math.max(...heights)); // Set the initial height to the maximum item height
    });
  }, [items]);

  const handleScrollEnd = (index: number) => {
    setCarouselHeight(itemHeights[index]);
    setActiveSlide(index);
  };

  const renderItem = ({
    item,
    index,
    renderHidden,
  }: {
    item: AdsProps;
    index: number;
    renderHidden: boolean;
  }) => {
    return (
      <View
        key={item.cd_matia}
        style={[
          styles.listItem,
          renderHidden && {opacity: 0, zIndex: -1, position: 'absolute'},
          !renderHidden && {height: itemHeights[index]},
        ]}
        ref={ref => renderHidden && (itemRefs.current[index] = ref)}>
        <TouchableOpacity
          activeOpacity={0.7}
          onPress={() => openNewsDetails(item.ds_matia_link)}>
          <CustomImage url={item.imagem} width={120} height={96} />
        </TouchableOpacity>
        <View style={styles.textContainer}>
          <NewsItemSubject subject={item.ds_matia_assun} />
          <TouchableOpacity onPress={() => openNewsDetails(item.ds_matia_link)}>
            <TextPrimary style={styles.listItemTitle}>
              {item.ds_matia_titulo}
            </TextPrimary>
          </TouchableOpacity>
        </View>
      </View>
    );
  };

  const moveAnimation = useRef(new Animated.Value(0)).current;
  const moveOffset = 90;

  useEffect(() => {
    const toValue = -((moveOffset / items.length) * activeSlide);
    if (!isNaN(toValue)) {
      Animated.timing(moveAnimation, {
        toValue: toValue,
        duration: 1000,
        useNativeDriver: true,
        easing: Easing.out(Easing.cubic),
      }).start();
    }
  }, [moveAnimation, activeSlide]);

  return (
    <View style={styles.container}>
      <View style={styles.rowContainer}>
        {items &&
          items.map((item, index) =>
            renderItem({item, index, renderHidden: true}),
          )}
        {/* {items &&
          items.map((item, index) => (
            <View
              key={`measure-${index}`}
              ref={ref => (itemRefs.current[index] = ref)}
              style={[
                styles.listItem,
                {opacity: 0, zIndex: 2, position: 'absolute'},
              ]}>
              <TouchableOpacity
                activeOpacity={0.7}
                onPress={() => openNewsDetails(item.ds_matia_link)}>
                <CustomImage url={item.imagem} width={120} height={96} />
              </TouchableOpacity>
              <View style={styles.textContainer}>
                <NewsItemSubject subject={item.ds_matia_assun} />
                <TouchableOpacity
                  onPress={() => openNewsDetails(item.ds_matia_link)}>
                  <TextPrimary style={styles.listItemTitle}>
                    {item.ds_matia_titulo}
                  </TextPrimary>
                </TouchableOpacity>
              </View>
            </View>
          ))} */}
        <Carousel
          ref={carouselRef}
          data={items}
          width={screenWidth}
          height={carouselHeight || 50}
          loop={true}
          renderItem={({item, index}) =>
            renderItem({item, index, render: false})
          }
          onScrollEnd={handleScrollEnd}
          pagingEnabled={true}
          style={{width: '100%'}}
        />
      </View>
    </View>
  );

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

No branches or pull requests