No Description

CountryCodeItem.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Created by zack on 2018/6/28.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. TouchableOpacity,
  9. Image,
  10. TextInput,
  11. Keyboard
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  15. export default class CountryCodeItem extends Component {
  16. constructor(props) {
  17. super(props)
  18. this.state = {
  19. name: props.name,
  20. phoneCode: props.phoneCode,
  21. }
  22. }
  23. componentWillReceiveProps(props) {
  24. this.setState({
  25. name: props.name,
  26. phoneCode: props.phoneCode,
  27. })
  28. }
  29. shouldComponentUpdate(nextProps) {
  30. if (nextProps.name !== this.state.name || nextProps.phoneCode !== this.state.phoneCode) {
  31. return true
  32. }
  33. return false
  34. }
  35. render() {
  36. return(
  37. <TouchableOpacity onPress={() => {
  38. this.props.didSelectedItem()
  39. }} style={styles.View}>
  40. <Text style={styles.NameText}>{this.state.name}</Text>
  41. <Text style={styles.PhoneCodeText}>{this.state.phoneCode}</Text>
  42. <View style={{position: 'absolute', width: ScreenDimensions.width, height: 0.5, backgroundColor: '#efeff4', left: 0, bottom: 0}} />
  43. </TouchableOpacity>
  44. )
  45. }
  46. }
  47. const styles = StyleSheet.create({
  48. View: {
  49. width: ScreenDimensions.width,
  50. height:45,
  51. flexDirection: 'row',
  52. justifyContent: 'space-between',
  53. alignItems: 'center',
  54. },
  55. NameText: {
  56. fontSize: 16,
  57. color: '#333333',
  58. marginLeft: 15,
  59. },
  60. PhoneCodeText: {
  61. fontSize: 16,
  62. color: '#333333',
  63. marginRight: 45,
  64. }
  65. })