-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change old ref API by createRef * Change calculateDaysArray return type Return string instead of moment object * Simplify Title component * Implement all-day events * Change defaults in App * Fix horizontal-swipe test * Add all-day-event description style * Update docs with all-day events Add dedicated guide Add props and special field
- Loading branch information
Showing
31 changed files
with
917 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Text, TouchableOpacity } from 'react-native'; | ||
|
||
import styles from './AllDayEvent.styles'; | ||
import { EventPropType } from '../utils/types'; | ||
|
||
const AllDayEventDefaultComponent = ({ event }) => ( | ||
<Text numberOfLines={1} ellipsizeMode="tail" style={styles.description}> | ||
{event.description} | ||
</Text> | ||
); | ||
|
||
const AllDayEvent = ({ | ||
event, | ||
onPress, | ||
onLongPress, | ||
left, | ||
width, | ||
top, | ||
containerStyle, | ||
EventComponent = AllDayEventDefaultComponent, | ||
}) => { | ||
const onPressWrapper = | ||
!event.disablePress && onPress && (() => onPress(event)); | ||
const onLongPressWrapper = | ||
!event.disableLongPress && onLongPress && (() => onLongPress(event)); | ||
|
||
return ( | ||
<TouchableOpacity | ||
key={event.id} | ||
onPress={onPressWrapper} | ||
onLongPress={onLongPressWrapper} | ||
disabled={!onPressWrapper && !onLongPressWrapper} | ||
style={[ | ||
styles.container, | ||
{ | ||
left, | ||
width, | ||
top, | ||
backgroundColor: event.color, | ||
}, | ||
containerStyle, | ||
event.style, | ||
]} | ||
> | ||
<EventComponent event={event} /> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
AllDayEvent.propTypes = { | ||
event: EventPropType.isRequired, | ||
left: PropTypes.number.isRequired, | ||
width: PropTypes.number.isRequired, | ||
top: PropTypes.number.isRequired, | ||
containerStyle: PropTypes.object, | ||
EventComponent: PropTypes.elementType, | ||
onPress: PropTypes.func, | ||
onLongPress: PropTypes.func, | ||
}; | ||
|
||
export default React.memo(AllDayEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
position: 'absolute', | ||
}, | ||
description: { | ||
fontSize: 14, | ||
}, | ||
}); | ||
|
||
export default styles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Animated, { | ||
useAnimatedStyle, | ||
withTiming, | ||
} from 'react-native-reanimated'; | ||
|
||
import AllDayEvent from './AllDayEvent'; | ||
import styles from './AllDayEvents.styles'; | ||
import { | ||
AllDayEventsWithMetaPropType, | ||
ReanimatedSharedValue, | ||
} from '../utils/types'; | ||
|
||
// NOTE: event height is hard-coded! | ||
export const ALL_DAY_EVENT_HEIGHT = 20; | ||
|
||
const AllDayEvents = ({ | ||
allDayEvents, | ||
days, | ||
dayWidth, | ||
style, | ||
visibleHeight, | ||
eventContainerStyle, | ||
EventComponent, | ||
onEventPress, | ||
onEventLongPress, | ||
}) => { | ||
const animatedHeight = useAnimatedStyle(() => ({ | ||
height: withTiming(visibleHeight.value, { duration: 100 }), | ||
})); | ||
return ( | ||
<Animated.View style={[styles.container, style, animatedHeight]}> | ||
{days.map((day, dayIndex) => { | ||
const events = allDayEvents[day] || []; | ||
return events.map(({ ref: event, overlap }) => { | ||
const { lane, width: nDays } = overlap; | ||
return ( | ||
<AllDayEvent | ||
key={event.id} | ||
event={event} | ||
onPress={onEventPress} | ||
onLongPress={onEventLongPress} | ||
left={dayWidth * dayIndex} | ||
width={dayWidth * nDays} | ||
top={lane * ALL_DAY_EVENT_HEIGHT} | ||
containerStyle={eventContainerStyle} | ||
EventComponent={EventComponent} | ||
/> | ||
); | ||
}); | ||
})} | ||
</Animated.View> | ||
); | ||
}; | ||
|
||
AllDayEvents.propTypes = { | ||
allDayEvents: PropTypes.objectOf( | ||
PropTypes.arrayOf(AllDayEventsWithMetaPropType), | ||
).isRequired, | ||
days: PropTypes.arrayOf(PropTypes.string), | ||
dayWidth: PropTypes.number.isRequired, | ||
style: PropTypes.object, | ||
eventContainerStyle: PropTypes.object, | ||
EventComponent: PropTypes.elementType, | ||
visibleHeight: ReanimatedSharedValue, | ||
onEventPress: PropTypes.func, | ||
onEventLongPress: PropTypes.func, | ||
}; | ||
|
||
export default AllDayEvents; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flexDirection: 'row', | ||
alignItems: 'flex-start', | ||
borderBottomWidth: 1, | ||
}, | ||
}); | ||
|
||
export default styles; |
Oops, something went wrong.