SidebarPage.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {
  2. LayoutAnimation,
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. UIManager,
  7. View,
  8. } from 'react-native';
  9. import React, { useState } from 'react';
  10. import NewscoutLogo from '../components/molecules/NewscoutLogo';
  11. import fonts from '../theme/fonts';
  12. import CircularPrimaryBackButton from '../components/organisms/Buttons/CircularPrimaryBackButton';
  13. import { List } from 'react-native-paper';
  14. import colors from '../theme/colors';
  15. import EntypoIcon from 'react-native-vector-icons/Entypo'
  16. import { ScrollView } from 'react-native-gesture-handler';
  17. const data = [
  18. {
  19. title: 'Sector Update',
  20. subTitles: ['Banking', 'Retail', 'Transport', 'Banking', 'Food & Drink'],
  21. },
  22. {
  23. title: 'Regional Update',
  24. subTitles: ['Banking', 'Retail', 'Transport', 'Banking', 'Food & Drink'],
  25. },
  26. {
  27. title: 'Finance',
  28. subTitles: ['Banking', 'Retail', 'Transport', 'Banking', 'Food & Drink'],
  29. },
  30. {
  31. title: 'Economic',
  32. subTitles: ['Banking', 'Retail', 'Transport', 'Banking', 'Food & Drink'],
  33. },
  34. {
  35. title: 'Miscellaneous',
  36. subTitles: ['Banking', 'Retail', 'Transport', 'Banking', 'Food & Drink'],
  37. },
  38. ];
  39. const SidebarPage = ({ navigation }) => {
  40. if (
  41. Platform.OS === 'android' &&
  42. UIManager.setLayoutAnimationEnabledExperimental
  43. ) {
  44. UIManager.setLayoutAnimationEnabledExperimental(true);
  45. }
  46. const [isExpanded, setExpanded] = useState(
  47. data.map((item) => {
  48. return {
  49. key: item.title,
  50. value: false
  51. };
  52. }).reduce((result, item) => {
  53. result[item.key] = item.value;
  54. return result;
  55. }, {})
  56. )
  57. return (
  58. <View style={styles.sideBarContainer}>
  59. <View style={styles.logoContainer}>
  60. <NewscoutLogo style={styles.logo} />
  61. </View>
  62. <View style={styles.buttonContainer}>
  63. <CircularPrimaryBackButton onPress={() => navigation.toggleDrawer()} />
  64. </View>
  65. <ScrollView>
  66. <View style={styles.accordionContainer}>
  67. <List.AccordionGroup>
  68. {data.map(item => (
  69. <List.Accordion
  70. key={data.indexOf(item)}
  71. id={`${data.indexOf(item)}`}
  72. style={[styles.accordionStyle]}
  73. titleStyle={[styles.accordionTextStyle, {}]}
  74. onPress={() => {
  75. // setExpandedsetIsShowingText(!isShowingText);
  76. // LayoutAnimation.configureNext(
  77. // LayoutAnimation.Presets.easeInEaseOut,
  78. // )
  79. // const nextState = { ...isExpanded };
  80. // nextState[item.title] = !nextState[item.title];
  81. //console.log("set state changes");
  82. // setExpanded(nextState);
  83. }}
  84. expanded={isExpanded[item.title]}
  85. left={() => <View style={{ paddingLeft: 16, }}><EntypoIcon name="box" size={24} /></View>}
  86. right={() => <EntypoIcon name="chevron-down" size={12} />}
  87. title={item.title}>
  88. {item.subTitles.map(subTitle => (
  89. <List.Item
  90. key={item.subTitles.indexOf(subTitle)}
  91. style={styles.accordionItemStyle}
  92. titleStyle={styles.accordionItemTextStyle}
  93. title={subTitle}
  94. />
  95. ))}
  96. </List.Accordion>
  97. ))}
  98. </List.AccordionGroup>
  99. </View>
  100. </ScrollView>
  101. </View>
  102. );
  103. };
  104. export default SidebarPage;
  105. const styles = StyleSheet.create({
  106. sideBarContainer: {
  107. paddingHorizontal: fonts.getSize(24),
  108. },
  109. logo: {
  110. width: fonts.getSize(84),
  111. height: fonts.getSize(84),
  112. },
  113. logoContainer: {
  114. justifyContent: 'center',
  115. alignItems: 'center',
  116. },
  117. buttonContainer: {},
  118. accordionContainer: {
  119. paddingVertical: fonts.getSize(16),
  120. gap: fonts.getSize(8),
  121. },
  122. accordionItemStyle: {},
  123. accordionItemTextStyle: {},
  124. accordionStyle: {
  125. backgroundColor: colors.white,
  126. borderRadius: fonts.getSize(8),
  127. borderWidth: fonts.getSize(3),
  128. borderColor: colors.lightGray,
  129. maxHeight: fonts.getSize(52),
  130. },
  131. accordionTextStyle: { fontFamily: fonts.type.medium },
  132. });