Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. LayoutAnimation,
  4. Text,
  5. TouchableWithoutFeedback,
  6. View
  7. } from 'react-native';
  8. import { connect } from 'react-redux';
  9. import { CardSection } from './common';
  10. import * as actions from '../actions';
  11.  
  12. class ListItem extends Component {
  13. componentWillUpdate(){
  14. LayoutAnimation.spring();
  15. }
  16.  
  17. renderDescription(){
  18. const { library, expanded } = this.props;
  19.  
  20. if (expanded) {
  21. return (
  22. <CardSection>
  23. <Text>
  24. {library.item.description}
  25. </Text>
  26. </CardSection>
  27.  
  28. );
  29. }
  30. }
  31.  
  32. render () {
  33. const { id, title } = this.props.library.item;
  34. return(
  35. <TouchableWithoutFeedback
  36. onPress={() => this.props.selectLibrary(id)}
  37. >
  38. <View>
  39. <CardSection >
  40. <Text style={styles.titleStyle}>
  41. {title}
  42. </Text>
  43. {this.renderDescription()}
  44. </CardSection>
  45. </View>
  46. </TouchableWithoutFeedback>
  47. )
  48. }
  49. }
  50.  
  51. const styles = {
  52. titleStyle: {
  53. fontSize: 18,
  54. paddingLeft: 15
  55. }
  56. };
  57.  
  58. const mapStateToProps = (state, ownProps) => {
  59. const expanded = state.selectedLibraryId === ownProps.library.item.id
  60.  
  61. return { expanded };
  62. }
  63.  
  64. export default connect(mapStateToProps, actions)(ListItem);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement