106 lines
2.8 KiB
JavaScript
106 lines
2.8 KiB
JavaScript
/**
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
* evaluation purposes only.
|
|
*
|
|
* Facebook reserves all rights not expressly granted.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* @flow
|
|
* @providesModule MovieCell
|
|
*/
|
|
'use strict';
|
|
|
|
var React = require('react');
|
|
var ReactNative = require('react-native');
|
|
var {
|
|
Image,
|
|
Platform,
|
|
StyleSheet,
|
|
Text,
|
|
TouchableHighlight,
|
|
TouchableNativeFeedback,
|
|
View
|
|
} = ReactNative;
|
|
|
|
var getStyleFromScore = require('./getStyleFromScore');
|
|
var getImageSource = require('./getImageSource');
|
|
var getTextFromScore = require('./getTextFromScore');
|
|
|
|
class MovieCell extends React.Component {
|
|
render() {
|
|
var criticsScore = this.props.movie.ratings.critics_score;
|
|
var TouchableElement = TouchableHighlight;
|
|
if (Platform.OS === 'android') {
|
|
TouchableElement = TouchableNativeFeedback;
|
|
}
|
|
return (
|
|
<View>
|
|
<TouchableElement
|
|
onPress={this.props.onSelect}
|
|
onShowUnderlay={this.props.onHighlight}
|
|
onHideUnderlay={this.props.onUnhighlight}>
|
|
<View style={styles.row}>
|
|
<Image
|
|
source={getImageSource(this.props.movie, 'det')}
|
|
style={styles.cellImage}
|
|
/>
|
|
<View style={styles.textContainer}>
|
|
<Text style={styles.movieTitle} numberOfLines={2}>
|
|
{this.props.movie.title}
|
|
</Text>
|
|
<Text style={styles.movieYear} numberOfLines={1}>
|
|
{this.props.movie.year}
|
|
{' '}•{' '}
|
|
<Text style={getStyleFromScore(criticsScore)}>
|
|
Critics {getTextFromScore(criticsScore)}
|
|
</Text>
|
|
</Text>
|
|
</View>
|
|
</View>
|
|
</TouchableElement>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
var styles = StyleSheet.create({
|
|
textContainer: {
|
|
flex: 1,
|
|
},
|
|
movieTitle: {
|
|
flex: 1,
|
|
fontSize: 16,
|
|
fontWeight: '500',
|
|
marginBottom: 2,
|
|
},
|
|
movieYear: {
|
|
color: '#999999',
|
|
fontSize: 12,
|
|
},
|
|
row: {
|
|
alignItems: 'center',
|
|
backgroundColor: 'white',
|
|
flexDirection: 'row',
|
|
padding: 5,
|
|
},
|
|
cellImage: {
|
|
backgroundColor: '#dddddd',
|
|
height: 93,
|
|
marginRight: 10,
|
|
width: 60,
|
|
},
|
|
cellBorder: {
|
|
backgroundColor: 'rgba(0, 0, 0, 0.1)',
|
|
height: StyleSheet.hairlineWidth,
|
|
marginLeft: 4,
|
|
},
|
|
});
|
|
|
|
module.exports = MovieCell;
|