-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Create popup component, show it when profile changes is saved #2944
Changes from 23 commits
568e0d7
dbe607f
05dea2b
fb2e6e1
19cfcd6
4918c79
c6d052f
49ffc51
2133683
54d8867
82df7f0
0044553
6c628a7
7718e5e
f0e6c38
a749cfd
4e60184
18404c0
e0bc077
e562936
96aa7d5
8e39ad5
a2bf927
5dce13e
6889057
30e57b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import {Animated} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../../../styles/styles'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; | ||
|
||
const propTypes = { | ||
children: PropTypes.node.isRequired, | ||
translateY: PropTypes.instanceOf(Animated.Value).isRequired, | ||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
const GrowlNotificationContainer = ({children, translateY, isSmallScreenWidth}) => ( | ||
<Animated.View | ||
style={[ | ||
styles.growlNotificationContainer, | ||
styles.growlNotificationDesktopContainer, | ||
styles.growlNotificationTranslateY(translateY), | ||
isSmallScreenWidth && styles.mwn, | ||
]} | ||
> | ||
{children} | ||
</Animated.View> | ||
); | ||
|
||
GrowlNotificationContainer.propTypes = propTypes; | ||
|
||
export default withWindowDimensions(GrowlNotificationContainer); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react'; | ||
import {Animated} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../../../styles/styles'; | ||
|
||
const propTypes = { | ||
children: PropTypes.node.isRequired, | ||
translateY: PropTypes.instanceOf(Animated.Value).isRequired, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also could probably be generalized since they are the same in both files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, you are right, I just generalized them. |
||
}; | ||
|
||
const GrowlNotificationContainer = ({children, translateY}) => ( | ||
<Animated.View | ||
style={[ | ||
styles.growlNotificationContainer, | ||
styles.growlNotificationTranslateY(translateY), | ||
]} | ||
> | ||
{children} | ||
</Animated.View> | ||
); | ||
|
||
GrowlNotificationContainer.propTypes = propTypes; | ||
|
||
export default GrowlNotificationContainer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React, {Component} from 'react'; | ||
import { | ||
Text, View, Animated, | ||
} from 'react-native'; | ||
import { | ||
Directions, FlingGestureHandler, State, TouchableWithoutFeedback, | ||
} from 'react-native-gesture-handler'; | ||
import colors from '../../styles/colors'; | ||
import Icon from '../../components/Icon'; | ||
import {Checkmark, Exclamation} from '../../components/Icon/Expensicons'; | ||
import styles from '../../styles/styles'; | ||
import GrowlNotificationContainer from './GrowlNotificationContainer'; | ||
|
||
const types = { | ||
success: { | ||
icon: Checkmark, | ||
iconColor: colors.green, | ||
}, | ||
error: { | ||
icon: Exclamation, | ||
iconColor: colors.red, | ||
}, | ||
warning: { | ||
icon: Exclamation, | ||
iconColor: colors.yellow, | ||
}, | ||
}; | ||
|
||
const INACTIVE_POSITION_Y = -255; | ||
|
||
class GrowlNotification extends Component { | ||
constructor() { | ||
super(); | ||
|
||
this.state = { | ||
bodyText: '', | ||
type: 'success', | ||
translateY: new Animated.Value(INACTIVE_POSITION_Y), | ||
}; | ||
|
||
this.show = this.show.bind(this); | ||
this.fling = this.fling.bind(this); | ||
} | ||
|
||
/** | ||
* Show the growl notification | ||
* | ||
* @param {string} bodyText | ||
* @param {string} type | ||
* @param {number} duration - 2000 | ||
*/ | ||
show(bodyText, type, duration = 2000) { | ||
this.setState({ | ||
bodyText, | ||
type, | ||
}, () => { | ||
this.fling(0); | ||
setTimeout(() => { | ||
this.fling(INACTIVE_POSITION_Y); | ||
}, duration); | ||
}); | ||
} | ||
|
||
/** | ||
* animate growl notification | ||
* | ||
* @param {number} val | ||
*/ | ||
fling(val = INACTIVE_POSITION_Y) { | ||
Animated.spring(this.state.translateY, { | ||
toValue: val, | ||
duration: 80, | ||
useNativeDriver: true, | ||
}).start(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<FlingGestureHandler | ||
direction={Directions.UP} | ||
onHandlerStateChange={({nativeEvent}) => { | ||
if (nativeEvent.state === State.ACTIVE) { | ||
this.fling(INACTIVE_POSITION_Y); | ||
} | ||
}} | ||
> | ||
<View style={styles.growlNotificationWrapper}> | ||
<GrowlNotificationContainer translateY={this.state.translateY}> | ||
<TouchableWithoutFeedback onPress={this.fling}> | ||
<View style={styles.growlNotificationBox}> | ||
<Text style={styles.growlNotificationText}> | ||
{this.state.bodyText} | ||
</Text> | ||
<Icon src={types[this.state.type].icon} fill={types[this.state.type].iconColor} /> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
</GrowlNotificationContainer> | ||
</View> | ||
</FlingGestureHandler> | ||
); | ||
} | ||
} | ||
|
||
export default GrowlNotification; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,8 @@ export default { | |
w50: { | ||
width: '50%', | ||
}, | ||
|
||
mwn: { | ||
maxWidth: 'auto', | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These also need comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented