No Description

BaseNavigationBarListItem.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Created by zack on 2018/4/20.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TouchableOpacity
  9. } from 'react-native'
  10. import React, {Component} from 'react'
  11. export default class BaseNavigationBarListItem extends Component {
  12. constructor(props) {
  13. super(props)
  14. this.state = {
  15. title: props.title,
  16. isSelected: props.isSelected
  17. }
  18. }
  19. componentWillReceiveProps(props) {
  20. this.setState({
  21. title: props.title,
  22. isSelected: props.isSelected
  23. })
  24. }
  25. shouldComponentUpdate(nextProps) {
  26. if (nextProps.title !== this.state.title ||
  27. nextProps.isSelected !== this.state.isSelected
  28. ) {
  29. return true
  30. }
  31. return false
  32. }
  33. render() {
  34. console.log(this.state.isSelected)
  35. return(
  36. <TouchableOpacity onPress={() => {
  37. this.props.didSelectedItem()
  38. }} style={styles.View}>
  39. <Text style={this.state.isSelected === true ? styles.TitleTextSelected : styles.TitleTextDeselected}>{this.state.title}</Text>
  40. </TouchableOpacity>
  41. )
  42. }
  43. }
  44. const styles = StyleSheet.create({
  45. View: {
  46. justifyContent: 'center',
  47. alignItems: 'center',
  48. },
  49. TitleTextDeselected: {
  50. fontSize: 14,
  51. color: "#333333",
  52. marginRight: 22
  53. },
  54. TitleTextSelected: {
  55. fontSize: 24,
  56. color: "#f01414",
  57. marginRight: 22
  58. }
  59. })