-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(calendar): component implementation (#153)
* feat(calendar): initial setup * feat(calendar): separated components * feat(calendar): boundingMonth prop * feat(calendar): update example * fix(calendar): months count to render in last year * fix(calendar): selection * refactor(calendar): separated week component * fix(calendar): selection optimizations * fix(calendar): selection optimizations - selection changes prop * fix(calendar): selection optimizations with shouldComponentUpdate * feat(calendar): day names component - base * feat(calendar): apply styles * feat(calendar): apply styles * feat(calendar): month header * feat(calendar): localized weekday & month names * fix(calendar): non-required selected date * feat(calendar): ranged calendar * fix(calendar): styles * feat(calendar): highlight today * feat(calendar): filter dates * feat(calendar): custom day render function * feat(calendar/range): custom day render function * feat(calendar): update example * refactor(calendar): move components to separate dirs * refactor(calendar): selection strategies * fix(calendar): cell selection after it was highlighted * fix(calendar): runtime warnings * fix(calendar): no-state-initialized warning * fix(calendar): day component key prop null-pointer * refactor(calendar): lint * feat(calendar): implementation examples * fix(calendar): month count rendering * feat(calendar): update examples * fix(calendar): render component after onLayout * refactor(calendar): month view as list item instead of year * feat(calendar): scrollTo* functions support * fix(calendar): month height calculation * feat(docs): update rkCalendar docs * feat(calendar): horizontal and vertical layout implementation * feat(calendar): add scrollTo next/prev month methods * feat(example): add horizontal calendar example * refactor(calendar): locale service with mocked data * fix(calendar): android - scroll to today on initial render * fix(calendar): bounding dates selection * docs(calendar): add layout prop description * feat(example): add calendar examples description * docs(calendar): add no-documented methods description and demo gif * refactor(calendar): style props to types refactor(calendar): move props to types refactor(calendar): rk-typed styles apply * refactor(calendar): render method as function * refactor(calendar): linebreaks * refactor(calendar): apply naming convenience * refactor(calendar): fix layout axis variables typo
- Loading branch information
1 parent
1492f41
commit 5daf561
Showing
35 changed files
with
2,258 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,31 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { | ||
RkCalendar, | ||
RkStyleSheet, | ||
} from 'react-native-ui-kitten'; | ||
|
||
export class BaseCalendarScreen extends React.Component { | ||
static navigationOptions = { | ||
title: 'Base Calendar', | ||
}; | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<RkCalendar | ||
min={new Date(2018, 0, 1)} | ||
max={new Date(2019, 0, 1)} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = RkStyleSheet.create(theme => ({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: theme.colors.background, | ||
paddingHorizontal: 8, | ||
}, | ||
})); |
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,32 @@ | ||
import React from 'react'; | ||
import { View } from 'react-native'; | ||
import { | ||
RkCalendar, | ||
RkStyleSheet, | ||
} from 'react-native-ui-kitten'; | ||
|
||
export class BoundingCalendarScreen extends React.Component { | ||
static navigationOptions = { | ||
title: 'Bounding Month Calendar', | ||
}; | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<RkCalendar | ||
min={new Date(2018, 0, 1)} | ||
max={new Date(2019, 0, 1)} | ||
boundingMonth={false} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = RkStyleSheet.create(theme => ({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: theme.colors.background, | ||
paddingHorizontal: 8, | ||
}, | ||
})); |
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,101 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
View, | ||
FlatList, | ||
TouchableOpacity, | ||
} from 'react-native'; | ||
import { | ||
RkText, | ||
RkStyleSheet, | ||
} from 'react-native-ui-kitten'; | ||
|
||
export class CalendarScreen extends React.Component { | ||
static navigationOptions = { | ||
title: 'Calendars', | ||
}; | ||
|
||
static propTypes = { | ||
navigation: PropTypes.shape({ | ||
navigate: PropTypes.func.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
static data = [ | ||
{ | ||
title: 'Base', | ||
description: "'Minimum code' implementation", | ||
route: 'BaseCalendar', | ||
}, | ||
{ | ||
title: 'Range', | ||
description: 'If you want to select date range', | ||
route: 'RangeCalendar', | ||
}, | ||
{ | ||
title: 'Bounding Month', | ||
description: 'No next month days at the end of the current', | ||
route: 'BoundingCalendar', | ||
}, | ||
{ | ||
title: 'Custom Day Cell', | ||
description: "Don't like default implementation?", | ||
route: 'CustomCalendar', | ||
}, | ||
{ | ||
title: 'Horizontal', | ||
description: 'Like vertical but horizontal', | ||
route: 'HorizontalCalendar', | ||
}, | ||
]; | ||
|
||
getItemKey = (item, index) => index.toString(); | ||
|
||
onItemClick = (item) => { | ||
this.props.navigation.navigate(item.route); | ||
}; | ||
|
||
renderItem = ({ item }) => ( | ||
<TouchableOpacity onPress={() => this.onItemClick(item)}> | ||
<View style={styles.componentRow}> | ||
<RkText rkType='header'>{item.title}</RkText> | ||
<RkText rkType='subtitle'>{item.description}</RkText> | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<RkText> | ||
{'RkCalendar is a component which allows user to select date or date range.' + | ||
' Check out some examples below prepared for you to see the power!'} | ||
</RkText> | ||
<View style={styles.descriptionSeparator} /> | ||
<FlatList | ||
data={CalendarScreen.data} | ||
keyExtractor={this.getItemKey} | ||
renderItem={this.renderItem} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = RkStyleSheet.create(theme => ({ | ||
container: { | ||
flex: 1, | ||
paddingVertical: 8, | ||
paddingHorizontal: 16, | ||
backgroundColor: theme.colors.screen.base, | ||
}, | ||
descriptionSeparator: { | ||
height: 2, | ||
marginVertical: 8, | ||
backgroundColor: theme.colors.border.base, | ||
}, | ||
componentRow: { | ||
paddingVertical: 8, | ||
justifyContent: 'space-between', | ||
}, | ||
})); |
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,107 @@ | ||
import React from 'react'; | ||
import { | ||
View, | ||
Text, | ||
} from 'react-native'; | ||
import { | ||
RkCalendar, | ||
RkStyleSheet, | ||
} from 'react-native-ui-kitten'; | ||
|
||
export class CustomCalendarScreen extends React.Component { | ||
static navigationOptions = { | ||
title: 'Custom Calendar', | ||
}; | ||
|
||
getContentStyle = (state) => ({ | ||
container: { | ||
base: state.isToday ? [styles.dayContainer, styles.dayContainerToday] : styles.dayContainer, | ||
selected: state.isSelected ? styles.dayContainerSelected : null, | ||
highlighted: state.isHighlighted ? styles.dayContainerHighlighted : null, | ||
disabled: state.isDisabled ? styles.dayContainerDisabled : null, | ||
}, | ||
text: { | ||
base: state.isToday ? [styles.dayText, styles.dayTextToday] : styles.dayText, | ||
selected: state.isSelected ? styles.dayTextSelected : null, | ||
highlighted: state.isHighlighted ? styles.dayTextHighlighted : null, | ||
disabled: state.isDisabled ? styles.dayTextDisabled : null, | ||
}, | ||
revenue: { | ||
fontSize: 12, | ||
}, | ||
}); | ||
|
||
renderDay = (date, state) => { | ||
const { container, text, revenue } = this.getContentStyle(state); | ||
const revenueText = state.isEmpty ? '' : `${(date.getDate() + 100) * date.getDate()}$`; | ||
return ( | ||
<View style={[container.base, container.selected, container.highlighted, container.disabled]}> | ||
<Text style={[text.base, text.selected, text.highlighted, text.disabled]}> | ||
{state.isEmpty ? '' : date.getDate()} | ||
</Text> | ||
<Text style={[text.base, text.selected, text.highlighted, text.disabled, revenue]}> | ||
{revenueText} | ||
</Text> | ||
</View> | ||
); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<RkCalendar | ||
min={new Date(2018, 0, 1)} | ||
max={new Date(2019, 0, 1)} | ||
renderDay={this.renderDay} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = RkStyleSheet.create(theme => ({ | ||
container: { | ||
flex: 1, | ||
backgroundColor: theme.colors.background, | ||
paddingHorizontal: 8, | ||
}, | ||
dayContainer: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
borderRadius: 4, | ||
paddingVertical: 8, | ||
}, | ||
dayContainerToday: { | ||
backgroundColor: theme.colors.highlight, | ||
}, | ||
dayContainerSelected: { | ||
backgroundColor: theme.colors.button.primary, | ||
borderRadius: 4, | ||
}, | ||
dayContainerHighlighted: { | ||
backgroundColor: theme.colors.button.primary, | ||
opacity: 0.25, | ||
borderRadius: 0, | ||
}, | ||
dayContainerDisabled: { | ||
opacity: 0.25, | ||
}, | ||
dayText: { | ||
fontSize: theme.fonts.sizes.large, | ||
color: theme.colors.text.base, | ||
fontWeight: '300', | ||
}, | ||
dayTextToday: { | ||
fontWeight: 'bold', | ||
}, | ||
dayTextSelected: { | ||
color: theme.colors.text.inverse, | ||
fontWeight: 'bold', | ||
}, | ||
dayTextHighlighted: { | ||
fontWeight: '300', | ||
}, | ||
dayTextDisabled: { | ||
}, | ||
})); |
Oops, something went wrong.