Skip to content

Commit

Permalink
feat: custom container style of event item
Browse files Browse the repository at this point in the history
  • Loading branch information
howljs committed Nov 12, 2022
1 parent 446fccd commit 75b9692
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
6 changes: 6 additions & 0 deletions documentation/docs/guides/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ Color of the event

<span style={{color: "grey"}}>string</span>

### containerStyle

Container style of the event

<span style={{color: "grey"}}>ViewStyle</span>

### Other props

You can add more properties to use with **[renderEventContent](#)**
Expand Down
15 changes: 13 additions & 2 deletions example/src/screens/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface CalendarProps {
navigation: NavigationProp<any>;
}

const generateColor = () => {
const randLightColor = () => {
return (
'hsl(' +
360 * Math.random() +
Expand All @@ -36,6 +36,16 @@ const generateColor = () => {
);
};

const randColor = () => {
return (
'#' +
Math.floor(Math.random() * 16777215)
.toString(16)
.padStart(6, '0')
.toUpperCase()
);
};

const unavailableHour = {
'0': [{ start: 0, end: 24 }],
'1': [
Expand Down Expand Up @@ -98,7 +108,8 @@ const Calendar = ({ route, navigation }: CalendarProps) => {
title: randomId,
start: event.start,
end: event.end,
color: generateColor(),
color: randLightColor(),
containerStyle: { borderColor: randColor(), borderWidth: 1 },
};
setEvents((prev) => [...prev, newEvent]);
};
Expand Down
1 change: 1 addition & 0 deletions src/components/Timeline/DragEditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const DragEditItem = ({
backgroundColor: event.color ? event.color : EVENT_DEFAULT_COLOR,
top: defaultTopPosition,
},
event.containerStyle,
animatedStyle,
]}
>
Expand Down
12 changes: 11 additions & 1 deletion src/components/Timeline/EventBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isEqual from 'lodash/isEqual';
import React, { memo } from 'react';
import { StyleSheet, Text, TouchableOpacity } from 'react-native';
import Animated, {
Expand Down Expand Up @@ -69,6 +70,7 @@ const EventBlock = ({
width: event.width,
opacity: eventOpacity,
},
event.containerStyle,
eventStyle,
]}
>
Expand All @@ -89,7 +91,15 @@ const EventBlock = ({
);
};

export default memo(EventBlock);
const areEqual = (prev: EventBlockProps, next: EventBlockProps) => {
const isSameEvent = isEqual(prev.event, next.event);
const isSameSelectedId = prev.selectedEventId === next.selectedEventId;
const isSameColumnWidth = prev.columnWidth === next.columnWidth;
const isSameDayIndex = prev.dayIndex === next.dayIndex;
return isSameEvent && isSameSelectedId && isSameColumnWidth && isSameDayIndex;
};

export default memo(EventBlock, areEqual);

const styles = StyleSheet.create({
eventBlock: {
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GestureResponderEvent } from 'react-native';
import type { GestureResponderEvent, StyleProp, ViewStyle } from 'react-native';
import type { SharedValue } from 'react-native-reanimated';
import type { LOCALES } from './constants';

Expand Down Expand Up @@ -179,6 +179,7 @@ export interface EventItem {
end: string;
title?: string;
color?: string;
containerStyle?: StyleProp<ViewStyle>;
[key: string]: any;
}

Expand Down

0 comments on commit 75b9692

Please sign in to comment.