Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {Platform, StyleSheet, Text, View, ScrollView, FlatList, TouchableWithoutFeedback, TouchableHighlight , Alert} from 'react-native';
  3. import {Header, TopNavigationButton, TopNavigationButtonUnchosen} from './components';
  4.  
  5.  
  6.  
  7. type Props = {};
  8. export default class App extends Component<Props> {
  9.  
  10.  
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. topNavigationOptions : [
  15. {key: 'Quick Search'},
  16. {key: 'Person Search'},],
  17. chosenTopNavigation:
  18. "Quick Search"
  19. };
  20.  
  21.  
  22. }
  23.  
  24.  
  25. renderItem = ({item}) => {
  26. if (item.key == this.state.chosenTopNavigation) {
  27. return (
  28. <TouchableWithoutFeedback onPress = { () => this.setState({chosenTopNavigation: item.key}) } >
  29. <TopNavigationButton >
  30. {item.key}
  31. </TopNavigationButton>
  32. </TouchableWithoutFeedback>
  33. )
  34. } else {
  35. return (
  36. <TouchableWithoutFeedback onPress = { () => this.setState({chosenTopNavigation: item.key}) }>
  37.  
  38.  
  39.  
  40.  
  41. //if i use a standard Text component, it swiches state and rerenders just fine, but with my View it does not work.
  42. <TopNavigationButtonUnchosen>
  43. {item.key}
  44. </TopNavigationButtonUnchosen>
  45. </TouchableWithoutFeedback>
  46. )
  47. }
  48. }
  49.  
  50.  
  51. render() {
  52. return (
  53. <View>
  54.  
  55. <TouchableHighlight onPress= {this._onPressButton}>
  56. <Header>Kopf</Header>
  57. </TouchableHighlight>
  58.  
  59.  
  60. <ScrollView horizontal = {true}>
  61. <View style = {styles.navigationContainer}>
  62. <TopNavigationButton>Quick Search</TopNavigationButton>
  63. <Text style = {styles.unchosenTextStyle}>Person Search</Text>
  64. </View>
  65. </ScrollView>
  66. <View styles = {styles.navigationContainer}>
  67. <FlatList
  68. horizontal
  69. extraData = {this.state.chosenTopNavigation}
  70. data={this.state.topNavigationOptions}
  71. renderItem = {this.renderItem.bind(this)}
  72. />
  73. </View>
  74. </View>
  75. );
  76. }
  77. }
  78.  
  79. const styles = StyleSheet.create({
  80.  
  81.  
  82. navigationContainer: {
  83. marginLeft: 20,
  84. marginTop: 15,
  85. flexDirection: 'row',
  86. alignItems: 'center',
  87. },
  88. unchosenTextStyle: {
  89. fontSize: 17,
  90. ...Platform.select({
  91. ios: {
  92. fontFamily: "OpenSans-Bold"
  93. },
  94. android: {
  95. fontFamily: "opensansBold"
  96. }
  97. }),
  98. color: '#9AA5B1',
  99. marginLeft: 20
  100. }
  101. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement