Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Carousel : Add new options, and fixes / Add Story Indicator #200

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nparigi-ledger
Copy link
Contributor

@nparigi-ledger nparigi-ledger commented May 16, 2022

This is non-breaking changes

Add StoryIndicator, an indicator for Carousel component like Instagram stories

Add new options to Carousel (mostly to be able to have a Carousel like Instagram stories, like having the possibility to tap on side to scroll, custom indicator, no restart after carousel end etc)

  • Fixes :
    The delay was not resetting after scrolling
    When scrolling to next item, the activeIndex was changing multiple time from the current index to the next index.
Screen_Recording_20220516-151401_Expo.Go.mp4

…m stories - Add new options to Carousel and fixes about delay and activeIndex with scroll
@nparigi-ledger nparigi-ledger requested a review from elbywan May 16, 2022 14:26
@vercel
Copy link

vercel bot commented May 16, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
ledger-live-ui-native ✅ Ready (Inspect) Visit Preview May 18, 2022 at 0:59AM (UTC)
ledger-live-ui-react ✅ Ready (Inspect) Visit Preview May 18, 2022 at 0:59AM (UTC)

@github-actions github-actions bot added the native Stuff that only impact the native package label May 16, 2022
@nparigi-ledger nparigi-ledger changed the title Add Story Indicator for Carousel - Carousel : Add new options, and fixs Carousel : Add new options, and fixes / Add Story Indicator May 16, 2022
@nparigi-ledger nparigi-ledger requested a review from a team May 16, 2022 14:37
Copy link
Contributor

@LFBarreto LFBarreto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Avoid conflict with styled-system's size property by nulling size and renaming it
size: undefined,
flexDirection: "row",
alignItems: "stretch",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you can use witdh: "100%" as a prop on Flex too

useEffect(() => {
if (isActive) {
width.value = 100;
} else if (full) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (full || !IsActive)
so you dont repeat the if statement here

() => ({
width: withTiming(`${width.value}%`, {
duration: isActive ? duration || 200 : 0,
easing: duration ? Easing.linear : Easing.linear,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why tho? 😅

return (
<Flex
height={4}
backgroundColor="neutral.c50"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we want that color to be a prop for easier future integration 🤔

height={4}
backgroundColor="neutral.c50"
margin={"auto"}
borderRadius={"8px"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borderRadius uses radii styled system gradation i think this is equals to borderRadius={2} or something

flex={1}
mx={1}
>
{full ? <ActiveBar /> : <AnimatedBar style={animatedStyles} />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the full state doesn't require any animation and is a simple switch here i would put all animated logic into a AnimatedBar component directly 🤔

return (
<TabsContainer>
{storiesArray.map((_, storyIndex) => (
<StoryBar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably add a key so react doesn't warn you about this

@@ -141,6 +198,8 @@ function Carousel({
scrollEventThrottle={200}
contentContainerStyle={{ width: `${fullWidth}%` }}
decelerationRate="fast"
disableIntervalMomentum={true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just disableIntervalMomentum if its true

onChange?: (index: number) => void;
duration?: number;
}>
| React.ReactElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of mixed types, it works but it requires a probably costly check on React.isValidElement where you could just have an extra prop IndicatorElement
and check what to show

{
 IndicatorElement ? (
          IndicatorElement
        ) : IndicatorComponent 
         ? (
          <IndicatorComponent
            ...
          />
        ) : null
 }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
native Stuff that only impact the native package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants