Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[User Settings] Add new Preferences view #1716

Merged
merged 33 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ca2cace
add expensifyNewsStatus toggle to preferences page
Maftalion Mar 10, 2021
ca98bf2
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 11, 2021
1edbb1c
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 11, 2021
a27b59d
add toggle library, revert accidental change
Maftalion Mar 11, 2021
fc03aee
package lock update
Maftalion Mar 11, 2021
f0475a0
add proptype comments
Maftalion Mar 11, 2021
8ffc704
Revert "package lock update"
Maftalion Mar 11, 2021
a1c53b7
style/text updates
Maftalion Mar 11, 2021
abb27a2
style/small updates
Maftalion Mar 12, 2021
7636f31
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 15, 2021
dc4dbed
update to go based off onyx prop
Maftalion Mar 16, 2021
8703977
lint error
Maftalion Mar 16, 2021
b332485
add user fetch
Maftalion Mar 17, 2021
fe50d3e
update switch styles
Maftalion Mar 17, 2021
802d076
update switchThumb style
Maftalion Mar 17, 2021
ddc8723
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 17, 2021
f48421d
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 17, 2021
67bba32
fix merge conflict
Maftalion Mar 17, 2021
38f1bc1
remove func wrapper
Maftalion Mar 17, 2021
6c4f7c3
fix whitespace
Maftalion Mar 17, 2021
a4e0640
remove shadow from thumb
Maftalion Mar 17, 2021
b7bd1da
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 18, 2021
f33775d
create switch component, remove library
Maftalion Mar 18, 2021
6732e6c
lint
Maftalion Mar 18, 2021
dcec672
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 19, 2021
942c675
remove line
Maftalion Mar 19, 2021
ff754a6
add missing style
Maftalion Mar 19, 2021
613b452
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 19, 2021
7acae50
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 20, 2021
5f92090
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 20, 2021
cfc6c56
remove package
Maftalion Mar 20, 2021
0976483
fix conflict
Maftalion Mar 20, 2021
41ae751
Merge branch 'master' into matt-preferences-toggle
Maftalion Mar 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"@react-native-firebase/analytics": "^7.6.7",
"@react-native-firebase/app": "^8.4.5",
"@react-native-firebase/crashlytics": "^8.4.9",
"@react-native-picker/picker": "^1.9.11",
"@react-navigation/drawer": "5.12.3",
"@react-navigation/native": "5.9.2",
"@react-navigation/stack": "5.14.2",
"@react-native-picker/picker": "^1.9.11",
"babel-plugin-transform-remove-console": "^6.9.4",
"dotenv": "^8.2.0",
"electron-context-menu": "^2.3.0",
Expand Down Expand Up @@ -71,8 +71,8 @@
"react-native-modal": "^11.5.6",
"react-native-onyx": "git+https://github.com/Expensify/react-native-onyx.git#9c965c8bc7dd7c080cdcb79f54409e8cd8ee2d44",
"react-native-pdf": "^6.2.2",
"react-native-reanimated": "1.13.2",
"react-native-picker-select": "8.0.4",
"react-native-reanimated": "1.13.2",
"react-native-render-html": "^6.0.0-alpha.10",
"react-native-safe-area-context": "^3.1.4",
"react-native-screens": "2.17.1",
Expand Down
54 changes: 54 additions & 0 deletions src/components/Switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, {Component} from 'react';
import {TouchableOpacity, Animated} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';

const propTypes = {
isOn: PropTypes.bool.isRequired,
onToggle: PropTypes.func.isRequired,
};

class Switch extends Component {
bondydaa marked this conversation as resolved.
Show resolved Hide resolved
constructor(props) {
super(props);
this.offPosition = 0;
this.onPosition = 20;
this.offsetX = new Animated.Value(props.isOn ? this.onPosition : this.offPosition);
bondydaa marked this conversation as resolved.
Show resolved Hide resolved

this.toggleSwitch = this.toggleSwitch.bind(this);
}

componentDidUpdate(prevProps) {
if (prevProps.isOn !== this.props.isOn) {
this.toggleSwitch();
}
}

toggleSwitch() {
Animated.timing(this.offsetX, {
toValue: this.props.isOn ? this.onPosition : this.offPosition,
duration: 300,
useNativeDriver: true,
}).start();
}

render() {
const switchTransform = {transform: [{translateX: this.offsetX}]};
const {isOn, onToggle} = this.props;

return (
<TouchableOpacity
style={[styles.switchTrack, !isOn && styles.switchInactive]}
activeOpacity={0.8}
onPress={() => onToggle(!isOn)}
bondydaa marked this conversation as resolved.
Show resolved Hide resolved
>
<Animated.View style={[styles.switchThumb, switchTransform]} />
</TouchableOpacity>
);
}
}

Switch.propTypes = propTypes;
Switch.displayName = 'Switch';

export default Switch;
16 changes: 11 additions & 5 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ function resendValidateCode(email) {
* @param {Boolean} subscribed
*/
function setExpensifyNewsStatus(subscribed) {
API.UpdateAccount({subscribed}).then((response) => {
if (response.jsonCode === 200) {
Onyx.merge(ONYXKEYS.USER, {expensifyNewsStatus: subscribed});
}
});
Onyx.merge(ONYXKEYS.USER, {expensifyNewsStatus: subscribed});

API.UpdateAccount({subscribed})
.then((response) => {
if (response.jsonCode !== 200) {
Onyx.merge(ONYXKEYS.USER, {expensifyNewsStatus: !subscribed});
}
})
.catch(() => {
Onyx.merge(ONYXKEYS.USER, {expensifyNewsStatus: !subscribed});
});
}

/**
Expand Down
31 changes: 29 additions & 2 deletions src/pages/settings/PreferencesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ import Icon from '../../components/Icon';
import NameValuePair from '../../libs/actions/NameValuePair';
import CONST from '../../CONST';
import {DownArrow} from '../../components/Icon/Expensicons';
import {setExpensifyNewsStatus} from '../../libs/actions/User';
import ScreenWrapper from '../../components/ScreenWrapper';
import Switch from '../../components/Switch';

const propTypes = {
// The chat priority mode
priorityMode: PropTypes.string,

// The details about the user that is signed in
user: PropTypes.shape({
// Whether or not the user is subscribed to news updates
expensifyNewsStatus: PropTypes.bool,
}),
};

const defaultProps = {
priorityMode: CONST.PRIORITY_MODE.DEFAULT,
user: {},
};

const priorityModes = {
Expand All @@ -38,16 +47,31 @@ const priorityModes = {
},
};

const PreferencesPage = ({priorityMode}) => (

const PreferencesPage = ({priorityMode, user}) => (
<ScreenWrapper>
<HeaderWithCloseButton
title="Preferences"
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS)}
onCloseButtonPress={() => Navigation.dismissModal()}
onCloseButtonPress={Navigation.dismissModal}
/>
<View style={styles.pageWrapper}>
<View style={[styles.settingsPageBody, styles.mb6]}>
<Text style={[styles.formLabel]} numberOfLines={1}>Notifications</Text>
<View style={[styles.flexRow, styles.mb6, styles.justifyContentBetween]}>
<View style={styles.flex4}>
<Text>
Receive relevant feature updates and Expensify news
</Text>
</View>
<View style={[styles.flex1, styles.alignItemsEnd]}>
<Switch
isOn={user.expensifyNewsStatus ?? true}
onToggle={setExpensifyNewsStatus}
/>
</View>
</View>
<Text style={[styles.formLabel]} numberOfLines={1}>
Priority Mode
</Text>
Expand Down Expand Up @@ -82,4 +106,7 @@ export default withOnyx({
priorityMode: {
key: ONYXKEYS.NVP_PRIORITY_MODE,
},
user: {
key: ONYXKEYS.USER,
},
})(PreferencesPage);
22 changes: 22 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,28 @@ const styles = {
lineHeight: 20,
},

switchTrack: {
width: 50,
height: 28,
justifyContent: 'center',
borderRadius: 20,
padding: 15,
backgroundColor: colors.green,
},

switchInactive: {
backgroundColor: colors.gray2,
},

switchThumb: {
width: 22,
height: 22,
borderRadius: 11,
position: 'absolute',
left: 4,
backgroundColor: colors.white,
},

checkboxContainer: {
backgroundColor: themeColors.componentBG,
borderRadius: 2,
Expand Down
4 changes: 4 additions & 0 deletions src/styles/utilities/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export default {
alignItems: 'center',
},

alignItemsEnd: {
alignItems: 'flex-end',
},

flexWrap: {
flexWrap: 'wrap',
},
Expand Down
1 change: 1 addition & 0 deletions src/styles/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
componentSizeSmall: 28,
componentSizeNormal: 40,
componentSizeLarge: 52,
componentBorderRadius: 8,
componentBorderRadiusSmall: 4,
componentBorderRadiusNormal: 8,
fontSizeSmall: 11,
Expand Down