-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
horizontal calendar list and few twicks
- Loading branch information
Showing
11 changed files
with
246 additions
and
11 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,153 @@ | ||
/** | ||
* Copyright 2016 Reza (github.com/rghorbani). | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const { Platform, StyleSheet, Text, TouchableOpacity } = require('react-native'); | ||
|
||
const defaultStyle = require('../../../style'); | ||
|
||
class Day extends React.Component { | ||
static propTypes = { | ||
// TODO: disabled props should be removed | ||
state: PropTypes.oneOf(['selected', 'disabled', 'today', '']), | ||
|
||
// Specify theme properties to override specific styles for calendar parts. Default = {} | ||
theme: PropTypes.object, | ||
marking: PropTypes.any, | ||
onPress: PropTypes.func, | ||
date: PropTypes.object | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.style = styleConstructor(props.theme); | ||
this.onDayPress = this.onDayPress.bind(this); | ||
this.onDayLongPress = this.onDayLongPress.bind(this); | ||
} | ||
|
||
onDayPress() { | ||
this.props.onPress(this.props.date); | ||
} | ||
onDayLongPress() { | ||
this.props.onLongPress(this.props.date); | ||
} | ||
|
||
shouldComponentUpdate(nextProps) { | ||
const changed = ['state', 'children', 'marking', 'onPress'].reduce((prev, next) => { | ||
if (prev) { | ||
return prev; | ||
} else if (nextProps[next] !== this.props[next]) { | ||
return next; | ||
} | ||
return prev; | ||
}, false); | ||
if (changed === 'marking') { | ||
let markingChanged = false; | ||
if (this.props.marking && nextProps.marking) { | ||
markingChanged = (!( | ||
this.props.marking.marked === nextProps.marking.marked | ||
&& this.props.marking.selected === nextProps.marking.selected | ||
&& this.props.marking.disabled === nextProps.marking.disabled)); | ||
} else { | ||
markingChanged = true; | ||
} | ||
// console.log('marking changed', markingChanged); | ||
return markingChanged; | ||
} else { | ||
// console.log('changed', changed); | ||
return !!changed; | ||
} | ||
} | ||
|
||
render() { | ||
let containerStyle = [this.style.base]; | ||
let textStyle = [this.style.text]; | ||
|
||
let marking = this.props.marking || {}; | ||
if (marking && marking.constructor === Array && marking.length) { | ||
marking = { | ||
marking: true | ||
}; | ||
} | ||
const isDisabled = typeof marking.disabled !== 'undefined' ? marking.disabled : this.props.state === 'disabled'; | ||
|
||
if (marking.selected) { | ||
containerStyle.push(this.style.selected); | ||
} else if (isDisabled) { | ||
textStyle.push(this.style.disabledText); | ||
} else if (this.props.state === 'today') { | ||
textStyle.push(this.style.todayText); | ||
} | ||
|
||
if (marking.customStyles && typeof marking.customStyles === 'object') { | ||
const styles = marking.customStyles; | ||
if (styles.container) { | ||
if (styles.container.borderRadius === undefined) { | ||
styles.container.borderRadius = 16; | ||
} | ||
containerStyle.push(styles.container); | ||
} | ||
if (styles.text) { | ||
textStyle.push(styles.text); | ||
} | ||
} | ||
|
||
return ( | ||
<TouchableOpacity | ||
style={containerStyle} | ||
onPress={this.onDayPress} | ||
onLongPress={this.onDayLongPress} | ||
activeOpacity={marking.activeOpacity} | ||
disabled={marking.disableTouchEvent} | ||
> | ||
<Text allowFontScaling={false} style={textStyle}>{String(this.props.children)}</Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
} | ||
|
||
const STYLESHEET_ID = 'stylesheet.day.single'; | ||
|
||
function styleConstructor(theme = {}) { | ||
const appStyle = {...defaultStyle, ...theme}; | ||
return StyleSheet.create({ | ||
base: { | ||
width: 32, | ||
height: 32, | ||
alignItems: 'center' | ||
}, | ||
text: { | ||
marginTop: Platform.OS === 'android' ? 4 : 6, | ||
fontSize: appStyle.textDayFontSize, | ||
fontFamily: appStyle.textDayFontFamily, | ||
fontWeight: '300', | ||
color: appStyle.dayTextColor, | ||
backgroundColor: 'rgba(255, 255, 255, 0)' | ||
}, | ||
alignedText: { | ||
marginTop: Platform.OS === 'android' ? 4 : 6 | ||
}, | ||
selected: { | ||
backgroundColor: appStyle.selectedDayBackgroundColor, | ||
borderRadius: 16 | ||
}, | ||
todayText: { | ||
color: appStyle.todayTextColor | ||
}, | ||
selectedText: { | ||
color: appStyle.selectedDayTextColor | ||
}, | ||
disabledText: { | ||
color: appStyle.textDisabledColor | ||
}, | ||
...(theme[STYLESHEET_ID] || {}) | ||
}); | ||
} | ||
|
||
module.exports = Day; |
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
Oops, something went wrong.