Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/design-system-react-native/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,23 @@ module.exports = merge(baseConfig, {
lines: 100,
statements: 100,
},
// useAnimatedScrollHandler wraps onScroll in a Reanimated worklet; Jest uses the
// reanimated mock, which does not execute that worklet body. Scroll logic is covered
// via updateScrollYFromEvent unit tests, but the hook line that forwards scrollEvent
// into updateScrollYFromEvent stays uncovered here—so statements/lines/functions sit
// below 100% while branches remain fully exercised.
'./src/components/HeaderStandardAnimated/useHeaderStandardAnimated.ts': {
branches: 100,
functions: 75,
lines: 87,
statements: 87,
},
},

// Add coverage ignore patterns
coveragePathIgnorePatterns: [
'index.ts',
'\\.types\\.ts$',
Comment thread
brianacnguyen marked this conversation as resolved.
Outdated
'\\.d\\.ts$',
'\\.constants\\.ts$', // ignore all .constants.ts files
'\\.dev\\.ts$', // ignore all .dev.ts files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import type { Meta, StoryObj } from '@storybook/react-native';
import React from 'react';
import Animated from 'react-native-reanimated';

import { Box } from '../Box';
import { Text, TextColor, TextVariant } from '../Text';
import { TitleStandard } from '../TitleStandard';

import { HeaderStandardAnimated } from './HeaderStandardAnimated';
import { useHeaderStandardAnimated } from './useHeaderStandardAnimated';

const meta = {
title: 'Components/HeaderStandardAnimated',
component: HeaderStandardAnimated,
argTypes: {
Comment thread
brianacnguyen marked this conversation as resolved.
title: { control: 'text' },
subtitle: { control: 'text' },
twClassName: { control: 'text' },
},
decorators: [
(Story) => (
<Box twClassName="w-full flex-1 bg-background-default">
<Story />
</Box>
),
],
} satisfies Meta<typeof HeaderStandardAnimated>;

export default meta;

type Story = StoryObj<typeof HeaderStandardAnimated>;

const SampleContent = ({ itemCount = 20 }: { itemCount?: number }) => (
<>
{Array.from({ length: itemCount }).map((_, index) => (
<Box key={index} twClassName="p-4 mb-2 bg-muted rounded-lg mx-4">
<Text variant={TextVariant.BodyMd}>Item {index + 1}</Text>
<Text variant={TextVariant.BodySm}>
This is sample content to demonstrate scrolling behavior.
</Text>
</Box>
))}
</>
);

const DefaultStory = () => {
const { scrollY, onScroll, setTitleSectionHeight, titleSectionHeightSv } =
useHeaderStandardAnimated();

return (
<Box twClassName="flex-1 bg-default">
<HeaderStandardAnimated
scrollY={scrollY}
titleSectionHeight={titleSectionHeightSv}
title="Market"
onBack={() => undefined}
/>
<Animated.ScrollView
onScroll={onScroll}
scrollEventThrottle={16}
showsVerticalScrollIndicator={false}
>
<Box
onLayout={(e) => setTitleSectionHeight(e.nativeEvent.layout.height)}
>
<TitleStandard
topAccessory={
<Text
variant={TextVariant.BodySm}
color={TextColor.TextAlternative}
>
Perps
</Text>
}
title="ETH-PERP"
twClassName="px-4 pt-1 pb-3"
/>
</Box>
<SampleContent />
</Animated.ScrollView>
</Box>
);
};

const WithSubtitleStory = () => {
const { scrollY, onScroll, setTitleSectionHeight, titleSectionHeightSv } =
useHeaderStandardAnimated();

return (
<Box twClassName="flex-1 bg-default">
<HeaderStandardAnimated
scrollY={scrollY}
titleSectionHeight={titleSectionHeightSv}
title="Market"
subtitle="Perpetual futures"
onBack={() => undefined}
/>
<Animated.ScrollView
onScroll={onScroll}
scrollEventThrottle={16}
showsVerticalScrollIndicator={false}
>
<Box
onLayout={(e) => setTitleSectionHeight(e.nativeEvent.layout.height)}
>
<TitleStandard
topAccessory={
<Text
variant={TextVariant.BodySm}
color={TextColor.TextAlternative}
>
Perps
</Text>
}
title="ETH-PERP"
twClassName="px-4 pt-1 pb-3"
/>
</Box>
<SampleContent />
</Animated.ScrollView>
</Box>
);
};

export const Default: Story = {
render: () => <DefaultStory />,
};

export const Subtitle: Story = {
render: () => <WithSubtitleStory />,
};
Comment thread
brianacnguyen marked this conversation as resolved.
Loading
Loading