Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {SectionList,StyleSheet,View} from 'react-native';
  3. import { Container, Header, Content, List, ListItem, Text,Item,Icon,Input,Button } from 'native-base';
  4. export default class MyAccountPage extends Component {
  5. constructor(props){
  6. super(props);
  7.  
  8. this.state={listData:[
  9. {title: 'A', data: ['item1', 'item2']},
  10. {title: 'B', data: ['item3', 'item4']},
  11. {title: 'C', data: ['item5', 'item6']},
  12. {title: 'D', data: ['item1', 'item2']},
  13. {title: 'E', data: ['item3', 'item4']},
  14. {title: 'F', data: ['item5', 'item6']},
  15. {title: 'G', data: ['item1', 'item2']},
  16. {title: 'H', data: ['item3', 'item4']},
  17. {title: 'I', data: ['item5', 'item6']},
  18. {title: 'J', data: ['item5', 'item6']},
  19. {title: 'K', data: ['item1', 'item2']},
  20. {title: 'L', data: ['item3', 'item4']},
  21. {title: 'M', data: ['item5', 'item6']},
  22. {title: 'N', data: ['item1', 'item2']},
  23. {title: 'O', data: ['item3', 'item4']},
  24. {title: 'P', data: ['item5', 'item6']},
  25. {title: 'Q', data: ['item1', 'item2']},
  26. {title: 'R', data: ['item3', 'item4']},
  27. {title: 'S', data: ['item5', 'item6']},
  28. ],
  29. }
  30. }
  31. scrollToSection = (index) => {
  32. this.sectionListRef.scrollToLocation({
  33. animated: true,
  34. sectionIndex: index,
  35. itemIndex: 0,
  36. viewPosition: 0.05
  37. });
  38. };
  39.  
  40. render() {
  41. return (
  42. <View style={{
  43. flex: 1,
  44. paddingTop:20,
  45. }}>
  46. <Header searchBar rounded>
  47. <Item>
  48. <Icon name="ios-search" />
  49. <Input placeholder="Search" />
  50. <Icon name="ios-people" />
  51. </Item>
  52. <Button transparent>
  53. <Text>Search</Text>
  54. </Button>
  55. </Header>
  56. <View style={{flex:1,flexDirection:'row'}}>
  57. <View style={{flex:1}}>
  58. <SectionList
  59. showsHorizontalScrollIndicator={true}
  60. ref={ref => { this.sectionListRef = ref; }}
  61. renderItem={({item, index, section}) => <Text key={index}>{item}</Text>}
  62. renderSectionHeader={({section: {title}}) => (
  63. <Text style={{fontWeight: 'bold'}}>{title}</Text>
  64. )}
  65. sections={this.state.listData}
  66. keyExtractor={(item, index) => item + index}
  67. />
  68. </View>
  69.  
  70. <View>
  71. {this.state.listData.map((listData,index)=>{
  72. return <Text onPress={()=>{this.scrollToSection(index)}}>{listData.title}</Text>
  73. })}
  74. </View>
  75. </View>
  76.  
  77. </View>
  78. );
  79. }
  80. }
  81.  
  82.  
  83. const styles = StyleSheet.create({
  84. container: {
  85. flex: 1,
  86. paddingTop:20,
  87.  
  88. },
  89. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement