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

created new props to fix timeline width #2490

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
11 changes: 8 additions & 3 deletions src/timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export interface TimelineProps {
timelineLeftInset?: number;
/** Identifier for testing */
testID?: string;
/**
* Width for the timeline component
*/
availableWidth?: number;
}

const Timeline = (props: TimelineProps) => {
Expand Down Expand Up @@ -143,6 +147,7 @@ const Timeline = (props: TimelineProps) => {
numberOfDays = 1,
timelineLeftInset = 0,
testID,
availableWidth,
} = props;

const pageDates = useMemo(() => {
Expand All @@ -161,8 +166,8 @@ const Timeline = (props: TimelineProps) => {
const {scrollEvents} = useTimelineOffset({onChangeOffset, scrollOffset, scrollViewRef: scrollView});

const width = useMemo(() => {
return constants.screenWidth - timelineLeftInset;
}, [timelineLeftInset]);
return (availableWidth ?? constants.screenWidth) - timelineLeftInset;
}, [availableWidth, timelineLeftInset]);

const packedEvents = useMemo(() => {
return map(pageEvents, (_e, i) => {
Expand Down Expand Up @@ -247,7 +252,7 @@ const Timeline = (props: TimelineProps) => {
// @ts-expect-error
ref={scrollView}
style={styles.current.container}
contentContainerStyle={[styles.current.contentStyle, {width: constants.screenWidth}]}
contentContainerStyle={[styles.current.contentStyle, {width: (availableWidth ?? constants.screenWidth)}]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer not to have a prop just for the content container width but instead, allow overriding/merge to the 'contentContainerStyle'. Maybe by exposing 'scrollViewProps' prop where you can pass any ScrollView props and override some (!) of its props.

showsVerticalScrollIndicator={false}
{...scrollEvents}
testID={testID}
Expand Down