SettingsPage.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { Appearance, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
  2. import React, { useContext } from 'react'
  3. import colors from '../../constants/colors'
  4. import fonts from '../../constants/fonts'
  5. import NewscoutTitleHeader from '../../components/molecules/Header/NewscoutTitleHeader'
  6. import { List } from 'react-native-paper'
  7. import EntypoIcon from 'react-native-vector-icons/Entypo'
  8. import { ThemeContext } from '../../context/theme.context'
  9. import { moderateScale } from '../../constants/metrics'
  10. const SettingsPage = props => {
  11. const { navigation, route } = props
  12. const theme = useContext(ThemeContext)
  13. const currentTheme = theme.state.theme
  14. const listItem = [
  15. {
  16. id: 1,
  17. title: 'Edit Profile',
  18. icon: 'account',
  19. navigation: () => navigation.navigate('EditProfile'),
  20. },
  21. {
  22. id: 2,
  23. title: 'Notification',
  24. icon: 'bell',
  25. navigation: () => navigation.navigate('Notification'),
  26. },
  27. {
  28. id: 3,
  29. title: 'Security',
  30. icon: 'security',
  31. navigation: () => navigation.navigate('Security'),
  32. },
  33. {
  34. id: 4,
  35. title: 'Invite Friends',
  36. icon: 'account-multiple-plus',
  37. navigation: () => navigation.navigate('InviteFriends'),
  38. },
  39. {
  40. id: 5,
  41. title: 'Help',
  42. icon: 'chat-question',
  43. navigation: () => navigation.navigate('HelpPageNav'),
  44. },
  45. {
  46. id: 6,
  47. title: 'Switch Theme',
  48. icon: 'theme-light-dark',
  49. navigation: () => {
  50. if (currentTheme === 'dark')
  51. theme.dispatch({ type: "LIGHTMODE" });
  52. else
  53. theme.dispatch({ type: "DARKMODE" });
  54. }
  55. },
  56. {
  57. id: 7,
  58. title: 'Logout',
  59. icon: 'logout',
  60. navigation: () => true
  61. },
  62. ]
  63. const styles = StyleSheet.create({
  64. container: {
  65. backgroundColor: colors().dominant,
  66. height: '100%',
  67. },
  68. });
  69. return (
  70. <View style={styles.container}>
  71. <NewscoutTitleHeader
  72. title="Settings"
  73. backButtonShown={true}
  74. onBackClick={() => navigation.goBack()}
  75. headerStyle={{ elevation: 2 }}
  76. />
  77. <View>
  78. <ScrollView>
  79. {listItem.map(item => (
  80. <SettingListItem
  81. title={item.title}
  82. key={item.id}
  83. id={item.id}
  84. icon={item.icon}
  85. onPress={item.navigation}
  86. />
  87. ))}
  88. </ScrollView>
  89. </View>
  90. </View>
  91. )
  92. }
  93. const SettingListItem = props => {
  94. const { title, id, icon, onPress } = props;
  95. const theme = useContext(ThemeContext)
  96. const currentTheme = theme.state.theme
  97. const styles = StyleSheet.create({
  98. listItemText: {
  99. fontFamily: fonts.type.medium,
  100. color: colors().recessive
  101. },
  102. circularIcon: {
  103. backgroundColor: currentTheme === 'light' ? colors().primaryTintColor : colors().black_variant,
  104. marginLeft: 20,
  105. padding: 8,
  106. borderRadius: 32,
  107. },
  108. })
  109. return (
  110. <TouchableOpacity onPress={onPress}>
  111. <List.Item
  112. title={title}
  113. titleStyle={styles.listItemText}
  114. key={id}
  115. left={props => (
  116. <List.Icon
  117. {...props}
  118. size={24}
  119. style={styles.circularIcon}
  120. icon={icon}
  121. color={colors().primaryColor}
  122. />
  123. )}
  124. right={props => (
  125. <View style={{justifyContent:'center'}}><EntypoIcon
  126. name="chevron-thin-right"
  127. size={moderateScale(16)}
  128. color={colors().recessive}
  129. /></View>
  130. )}
  131. />
  132. </TouchableOpacity>
  133. );
  134. };
  135. export default SettingsPage