-
Notifications
You must be signed in to change notification settings - Fork 1
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 #654 from bounswe/MOBILE-646
feat(mobile): Notifications on successful login/register
- Loading branch information
Showing
4 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { View, Text, StyleSheet, Animated } from 'react-native'; | ||
|
||
type NotificationProps = { | ||
message: string; | ||
duration?: number; // Duration in milliseconds (default: 3000ms) | ||
onHide?: () => void; // Callback when notification hides | ||
color?: string, | ||
}; | ||
|
||
const Notification: React.FC<NotificationProps> = ({ message, duration = 3000, onHide, color }) => { | ||
const [fadeAnim] = useState(new Animated.Value(0)); // Animation value | ||
|
||
useEffect(() => { | ||
// Fade in the notification | ||
Animated.timing(fadeAnim, { | ||
toValue: 1, | ||
duration: 300, | ||
useNativeDriver: true, | ||
}).start(); | ||
|
||
// Automatically hide the notification after the specified duration | ||
const timer = setTimeout(() => { | ||
Animated.timing(fadeAnim, { | ||
toValue: 0, | ||
duration: 300, | ||
useNativeDriver: true, | ||
}).start(() => { | ||
if (onHide) onHide(); // Call onHide callback if provided | ||
}); | ||
}, duration); | ||
|
||
return () => clearTimeout(timer); // Cleanup timer on unmount | ||
}, [fadeAnim, duration, onHide]); | ||
|
||
return ( | ||
<Animated.View style={[styles.notification, { opacity: fadeAnim }, color && {backgroundColor: color}]}> | ||
<Text style={styles.notificationText}>{message}</Text> | ||
</Animated.View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
notification: { | ||
position: 'absolute', | ||
top: 50, | ||
left: 10, | ||
right: 10, | ||
backgroundColor: '#4caf50', | ||
padding: 10, | ||
borderRadius: 5, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
zIndex: 1000, // Ensure it stays above other UI elements | ||
}, | ||
notificationText: { | ||
color: 'white', | ||
fontWeight: 'bold', | ||
}, | ||
}); | ||
|
||
export default Notification; |
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