Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. import * as React from "react"
  2. import { View, ViewStyle, Animated, Text, Dimensions } from "react-native"
  3. import { HeaderProps } from "./header.props"
  4. import { translate } from "../../i18n/"
  5. import { TextField } from "../../components/text-field"
  6. import { Icon } from "../../components/icon"
  7.  
  8. interface HeaderState {
  9. modalVisible?: boolean
  10. fullHeight,
  11. modalOpacity,
  12. }
  13. /**
  14. * Header that appears on many screens. Will hold navigation buttons and screen title.
  15. */
  16. export class Header extends React.Component<HeaderProps, HeaderState> {
  17.  
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. modalVisible: false,
  22. fullHeight: new Animated.Value(0),
  23. modalOpacity: new Animated.Value(0),
  24.  
  25. };
  26. }
  27. search = (e) => {
  28. console.log(e);
  29. }
  30. showContent(visible) {
  31. let height = Dimensions.get('window').height;
  32. this.setState(
  33. { modalVisible: !this.state.modalVisible },
  34. () => {
  35. Animated.timing(
  36. this.state.modalOpacity,
  37. { toValue: this.state.modalVisible ? 1 : 0 }
  38.  
  39. ).start()
  40. Animated.timing(
  41. this.state.fullHeight,
  42. { toValue: this.state.modalVisible ? height : 0 }
  43. ).start()
  44. }
  45. )
  46. }
  47.  
  48. render() {
  49.  
  50. let searchResults = [
  51. {
  52. title: 'Grill London',
  53. address: 'PLC "Mega", Islandijos pl. 32, Kaunas'
  54. },
  55. {
  56. title: 'Piccola Italia - trattoria & pizzeria',
  57. address: 'Maironio g. 22, Kaunas 44298'
  58. }
  59. ]
  60. const {
  61. headerText,
  62. headerTx,
  63. } = this.props
  64.  
  65.  
  66. const styles = {
  67.  
  68. shadow: {
  69. shadowColor: "#000",
  70. shadowOffset: {
  71. width: 0,
  72. height: 1,
  73. },
  74. shadowOpacity: 0.1,
  75. shadowRadius: 3.84,
  76. elevation: 5,
  77. },
  78. searchIcon: {
  79. marginRight: 10,
  80. width: 20,
  81. height: 20,
  82. },
  83. modalStyle: {
  84. height: Dimensions.get('window').height,
  85. },
  86. input: {
  87. flex: 1,
  88. backgroundColor: '#fff',
  89. color: '#424242',
  90. },
  91. }
  92. const searchSection = {
  93. flex: 1,
  94. flexDirection: 'row',
  95. justifyContent: 'center',
  96. alignItems: 'flex-start',
  97. backgroundColor: '#fff',
  98. ...styles.shadow
  99. } as ViewStyle
  100. const header = headerText || (headerTx && translate(headerTx)) || ""
  101.  
  102. return (
  103. <View>
  104. <View style={[searchSection,]}>
  105.  
  106. <TextField
  107. onFocus={() => {
  108. this.showContent(true);
  109. }}
  110. onBlur={() => {
  111. this.showContent(false);
  112.  
  113. }}
  114. onChangeText={this.search} style={styles.input}
  115. inputStyle={{ borderBottomWidth: 0, paddingLeft: 10 }}
  116. placeholder="Paieska" />
  117. <Icon style={styles.searchIcon} icon="search" />
  118. </View>
  119. <Animated.View style={{
  120. width: '100%',
  121. selfAlign: 'center',
  122. opacity: this.state.modalOpacity,
  123. alignContent: 'center',
  124. alignItems: 'center',
  125. height: this.state.fullHeight,
  126. backgroundColor: "#fff",
  127. }}>
  128.  
  129. <View
  130. style={{
  131. width: '100%',
  132. paddingBottom: 15,
  133. paddingTop: 15,
  134. backgroundColor: '#fff',
  135. ...styles.shadow
  136. }}
  137. >
  138. <View
  139. style={{
  140. width: '90%',
  141. flexDirection: 'row',
  142. alignItems: 'center',
  143. marginLeft: 'auto',
  144. justifyContent: 'space-between',
  145. marginRight: 'auto',
  146. }}
  147. >
  148. <View
  149. style={{
  150. flexDirection: 'row',
  151. alignItems: 'center'
  152. }}
  153. >
  154. <Icon style={{ width:20, height:20, marginRight: 15 }} icon="near_me"></Icon>
  155. <Text style={{
  156. fontSize: 18,
  157. color: '#707070',
  158. }}>Netoliese</Text>
  159. </View>
  160. <Icon style={{width:24,height:24}} icon='map'></Icon>
  161. </View>
  162. </View>
  163. {searchResults.map((result, i) => (
  164. <View
  165. key={i}
  166. style={{
  167. width: '90%',
  168. justifyContent: 'flex-start',
  169. marginBottom: 10,
  170. paddingTop: 10,
  171. paddingBottom: 10,
  172. borderBottomWidth: 1,
  173. borderColor: '#C9C9C9',
  174. marginTop: 10,
  175. flexDirection: 'row',
  176. alignItems: 'center'
  177. }}>
  178. <Icon style={{ marginRight: 15 }} icon='clock'></Icon>
  179. <View>
  180. <Text
  181. style={{
  182. fontWeight: 'bold',
  183. fontSize: 18,
  184. paddingBottom: 5,
  185. color: '#3B3B3B',
  186. }}
  187. >{result.title}</Text>
  188. <Text
  189. style={{
  190. fontSize: 14,
  191. fontWeight: '300',
  192. color: '#757575',
  193. paddingBottom: 10,
  194. }}
  195. >{result.address}</Text>
  196. </View>
  197. </View>
  198. ))}
  199. </Animated.View>
  200. </View>
  201. )
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement