-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2944 from studio-504/create-popup-component
- Loading branch information
Showing
11 changed files
with
255 additions
and
33 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/libs/GrowlNotification/GrowlNotificationContainer/GrowlNotificationContainerPropTypes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Animated} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; | ||
|
||
const propTypes = { | ||
/** GrowlNotification content */ | ||
children: PropTypes.node.isRequired, | ||
|
||
/** GrowlNotification Y postion, required to show or hide with fling animation */ | ||
translateY: PropTypes.instanceOf(Animated.Value).isRequired, | ||
|
||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
export default propTypes; |
22 changes: 22 additions & 0 deletions
22
src/libs/GrowlNotification/GrowlNotificationContainer/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import {Animated} from 'react-native'; | ||
import styles from '../../../styles/styles'; | ||
import withWindowDimensions from '../../../components/withWindowDimensions'; | ||
import propTypes from './GrowlNotificationContainerPropTypes'; | ||
|
||
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); |
19 changes: 19 additions & 0 deletions
19
src/libs/GrowlNotification/GrowlNotificationContainer/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import {Animated} from 'react-native'; | ||
import styles from '../../../styles/styles'; | ||
import propTypes from './GrowlNotificationContainerPropTypes'; | ||
|
||
const GrowlNotificationContainer = ({children, translateY}) => ( | ||
<Animated.View | ||
style={[ | ||
styles.growlNotificationContainer, | ||
styles.growlNotificationTranslateY(translateY), | ||
]} | ||
> | ||
{children} | ||
</Animated.View> | ||
); | ||
|
||
GrowlNotificationContainer.propTypes = propTypes; | ||
|
||
export default GrowlNotificationContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,8 @@ export default { | |
w50: { | ||
width: '50%', | ||
}, | ||
|
||
mwn: { | ||
maxWidth: 'auto', | ||
}, | ||
}; |