Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TouchableOpacity,
  7. FlatList,
  8. List,
  9. ListItem
  10. } from 'react-native';
  11. import {
  12. Container,
  13. Header,
  14. Item,
  15. Input,
  16. Button,
  17. StyleProvider,
  18. Icon,
  19. Body,
  20. Right,
  21. StatusBar,
  22. Card,
  23. CardItem,
  24. CheckBox,
  25. Left
  26. } from 'native-base';
  27.  
  28.  
  29.  
  30. export default class UserList extends Component {
  31.  
  32.  
  33. constructor(props) {
  34. super(props);
  35. const {params} = this.props.navigation.state;
  36. this.state = {
  37. data: [],
  38. SelectedUserList: params.selectedUserID.slice(),
  39. SelectedUserListName: [],
  40. renderedListData: [],
  41. IsInArray: true,
  42. selectedUserID: params.selectedUserID,
  43. IsSelected: (new Map(): Map<string, boolean>)
  44. }
  45. console.log("selectedUserID" + JSON.stringify(this.state.selectedUserID))
  46. console.log("selectedCropName" + JSON.stringify(params.SelectedUserListName))
  47. }
  48.  
  49. press = (hey) => {
  50. console.log('Press:'+this.state.SelectedUserList)
  51. this.state.renderedListData.map((item) => {
  52. if (item.id === hey.id) {
  53. item.check = !item.check
  54. if (item.check === true) {
  55. this.state.SelectedUserList.push(item.id);
  56. this.state.SelectedUserListName.push(item.name);
  57. console.log('selected:' + item.name);
  58. console.log(this.state.SelectedUserListName.includes(item.id))
  59. } else if (item.check === false) {
  60. const i = this.state.SelectedUserList.indexOf(item)
  61. const j = this.state.SelectedUserListName.indexOf(item)
  62. if (1 != -1) {
  63. this.state.SelectedUserList.splice(i, 1)
  64. this.state.SelectedUserListName.splice(j, 1)
  65. console.log('unselect:' + item.name)
  66. return this.state.SelectedUserList
  67. }
  68. }
  69. }
  70. })
  71. this.setState({data: this.state.data})
  72. }
  73.  
  74.  
  75.  
  76.  
  77. componentDidMount() {
  78. //Fetch Data From API
  79. ...
  80. }
  81.  
  82. render() {
  83. return (
  84. <View style={styles.container}>
  85. <View style={styles.storyContainer}>
  86. <FlatList data={this.state.renderedListData} keyExtractor={item => item.id.toString()}
  87. extraData={this.state}
  88. renderItem={({item}) => {
  89. return <TouchableOpacity style={{
  90. flexDirection: 'row',
  91. padding: 2
  92. }} onPress={() => {
  93. this.press(item)
  94. }}>
  95. <View style={{
  96. flex: 3,
  97. alignItems: 'flex-start',
  98. justifyContent: 'center'
  99. }}>
  100. {<Card
  101. style={{
  102. width: '100%',
  103. height: 80,
  104. alignItems: 'center'
  105. }}>
  106. <CardItem style={{height: '100%'}}>
  107. <Left>
  108. <View style={{
  109. flex: 1,
  110. flexDirection: 'row',
  111. alignItems: 'center'
  112. }}>
  113. <CheckBox checked={(this.state.selectedUserID.includes(item.id) || item.check ) ? true : false}
  114. style={{marginRight: 15}}/>
  115. <View>
  116. <Text style={{
  117. color: "#24466B",
  118. fontSize: 16
  119. }}>
  120. {item.name}
  121. </Text>
  122. </View>
  123. </View>
  124. </Left>
  125. </CardItem>
  126. </Card>}
  127. </View>
  128. </TouchableOpacity>
  129. }}/>
  130. </View>
  131. </View>
  132. )
  133. }
  134. };
  135.  
  136. SelectedUserList: params.selectedUserID.slice()
Add Comment
Please, Sign In to add comment