Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 KB | None | 0 0
  1. /* @flow */
  2.  
  3. import color from 'color';
  4. import * as React from 'react';
  5. import { View, StyleSheet } from 'react-native';
  6. import TouchableRipple from '../TouchableRipple';
  7. import Icon from '../Icon';
  8. import Text from '../Typography/Text';
  9. import withTheme from '../../core/withTheme';
  10. import type { Theme } from '../../types';
  11.  
  12. type Props = {
  13. /**
  14. * Title text for the list accordion.
  15. */
  16. title: React.Node,
  17. time: React.Node,//modified
  18. /**
  19. * Description text for the list accordion.
  20. */
  21. description?: React.Node,
  22. /**
  23. * Icon to display for the `ListAccordion`.
  24. */
  25. icon?: React.Node,
  26.  
  27. /**
  28. * Content of the section.
  29. */
  30. children: React.Node,
  31.  
  32. /**
  33. * @optional
  34. */
  35. theme: Theme,
  36. style?: any,
  37. expanded: React.Node
  38. };
  39.  
  40. // type State = {
  41. // expanded: boolean,
  42. // };
  43.  
  44. /**
  45. * `ListAccordion` can be used to display an expandable list item.
  46. *
  47. * <div class="screenshots">
  48. * <img class="medium" src="screenshots/list-accordion-1.png" />
  49. * <img class="medium" src="screenshots/list-accordion-2.png" />
  50. * <img class="medium" src="screenshots/list-accordion-3.png" />
  51. * </div>
  52. *
  53. * ## Usage
  54. * ```js
  55. * import * as React from 'react';
  56. * import { ListAccordion, ListItem, Checkbox } from 'react-native-paper';
  57. *
  58. * const MyComponent = () => (
  59. * <ListAccordion
  60. * title="Accordion"
  61. * icon="folder"
  62. * >
  63. * <ListItem title="First item" />
  64. * <ListItem title="Second item" />
  65. * </ListAccordion>
  66. * );
  67. * ```
  68. */
  69. class ListAccordion extends React.Component<Props, State> {
  70. state = {
  71. expanded: this.props.expanded,
  72. };
  73. // componentWillReceiveProps(nextProps) {
  74. // this.setState({ expanded: nextProps.data });
  75. // }
  76.  
  77. _handlePress = () =>
  78. this.setState(state => ({
  79. expanded: !state.expanded,
  80. }));
  81.  
  82. render() {
  83. const { icon, title, time,/* modified*/ description, children, theme, style } = this.props;
  84. const titleColor = color(theme.colors.text)
  85. .alpha(0.87)
  86. .rgb()
  87. .string();
  88. const descriptionColor = color(theme.colors.text)
  89. .alpha(0.54)
  90. .rgb()
  91. .string();
  92.  
  93. return (
  94. <View>
  95. <TouchableRipple
  96. style={[styles.container, style]}
  97. onPress={this._handlePress}
  98. >
  99. <View style={styles.row} pointerEvents="none">
  100. {icon ? (
  101. <View
  102. style={[
  103. styles.item,
  104. styles.icon,
  105. description && styles.multiline,
  106. ]}
  107. >
  108. <Icon
  109. name={icon}
  110. size={24}
  111. color={
  112. this.state.expanded
  113. ? theme.colors.primary
  114. : descriptionColor
  115. }
  116. />
  117. </View>
  118. ) : null}
  119. <View style={[styles.item, styles.content]}>
  120. {/* modified */}
  121. <View style = {{flexDirection: 'row', flex:1}}>
  122. {time && ( <Text
  123. numberOfLines={1}
  124. style={styles.time}
  125. >
  126. {time}
  127. </Text>
  128. )}
  129.  
  130. <Text
  131. numberOfLines={1}
  132. style={[
  133. styles.title,
  134. {
  135. color: this.state.expanded
  136. ? theme.colors.primary
  137. : titleColor,
  138. },
  139. ]}
  140. >
  141. {title}
  142. </Text>
  143. </View>
  144. {description && (
  145. <Text
  146. numberOfLines={2}
  147. style={[
  148. styles.description,
  149. {
  150. color: descriptionColor,
  151. },
  152. ]}
  153. >
  154. {description}
  155. </Text>
  156. )}
  157. </View>
  158. <View style={[styles.item, description && styles.multiline]}>
  159. {!this.props.arrow &&
  160. <Icon
  161. name={
  162. this.state.expanded
  163. ? 'keyboard-arrow-up'
  164. : 'keyboard-arrow-down'
  165. }
  166. color={titleColor}
  167. size={24}
  168. />
  169. }
  170. </View>
  171. </View>
  172. </TouchableRipple>
  173. {this.state.expanded
  174. ? React.Children.map(children, child => {
  175. if (
  176. icon &&
  177. React.isValidElement(child) &&
  178. !child.props.icon &&
  179. !child.props.avatar
  180. ) {
  181. return React.cloneElement(child, {
  182. style: [styles.child, child.props.style],
  183. });
  184. }
  185.  
  186. return child;
  187. })
  188. : null}
  189. </View>
  190. );
  191. }
  192. }
  193.  
  194. const styles = StyleSheet.create({
  195. container: {
  196. padding: 8,
  197. },
  198. row: {
  199. flexDirection: 'row',
  200. },
  201. icon: {
  202. width: 40,
  203. },
  204. multiline: {
  205. height: 40,
  206. alignItems: 'center',
  207. justifyContent: 'center',
  208. },
  209. title: {
  210. justifyContent: 'flex-start',
  211. flex: 5,
  212. color: "#353434",
  213. fontSize: 17,
  214. fontWeight: '500'//modified
  215. },
  216. time:{
  217. width: '20%',
  218. fontSize: 17,
  219. fontWeight: '700',
  220. color: "#D91B00"
  221. },
  222. description: {
  223. fontSize: 14,
  224. },
  225. item: {
  226. margin: 8,
  227. },
  228. child: {
  229. paddingLeft: 64,
  230. },
  231. content: {
  232. flex: 1,
  233. justifyContent: 'center',
  234. },
  235. });
  236.  
  237. export default withTheme(ListAccordion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement