@@ -2,6 +2,7 @@ import React, { PureComponent } from 'react';
22import { Animated } from 'react-native' ;
33import PropTypes from 'prop-types' ;
44import styled from '@stream-io/styled-components' ;
5+ import { themed } from '../styles/theme' ;
56
67const Container = styled . TouchableOpacity `
78 display: flex;
@@ -14,69 +15,74 @@ const Container = styled.TouchableOpacity`
1415 margin-bottom: 0;
1516 border-radius: 13px;
1617 background-color: ${ ( { theme } ) => theme . colors . primary } ;
17- color: white;
1818 transform: translateY(9px);
19- ${ ( { theme } ) => theme . messageList . messageNotification . css }
19+ ${ ( { theme } ) => theme . messageList . messageNotification . container . css }
2020` ;
2121
2222const MessageNotificationText = styled . Text `
2323 color: white;
2424 font-size: 12px;
2525 font-weight: 600;
26- ${ ( { theme } ) => theme . messageList . messageNotificationText . css }
26+ ${ ( { theme } ) => theme . messageList . messageNotification . text . css }
2727` ;
28-
29- export class MessageNotification extends PureComponent {
30- constructor ( props ) {
31- super ( props ) ;
32- this . state = {
33- notificationOpacity : new Animated . Value ( 0 ) ,
28+ /**
29+ * @example ./docs/MessageNotification.md
30+ * @extends PureComponent
31+ */
32+ export const MessageNotification = themed (
33+ class MessageNotification extends PureComponent {
34+ static themePath = 'messageList.messageNotification' ;
35+ constructor ( props ) {
36+ super ( props ) ;
37+ this . state = {
38+ notificationOpacity : new Animated . Value ( 0 ) ,
39+ } ;
40+ }
41+ static propTypes = {
42+ /** If we should show the notification or not */
43+ showNotification : PropTypes . bool ,
44+ /** Onclick handler */
45+ onPress : PropTypes . func . isRequired ,
3446 } ;
35- }
36- static propTypes = {
37- /** If we should show the notification or not */
38- showNotification : PropTypes . bool ,
39- /** Onclick handler */
40- onPress : PropTypes . func . isRequired ,
41- } ;
42-
43- static defaultProps = {
44- showNotification : true ,
45- } ;
4647
47- componentDidMount ( ) {
48- Animated . timing ( this . state . notificationOpacity , {
49- toValue : this . props . showNotification ? 1 : 0 ,
50- duration : 500 ,
51- } ) . start ( ) ;
52- }
48+ static defaultProps = {
49+ showNotification : true ,
50+ } ;
5351
54- componentDidUpdate ( prevProps ) {
55- if ( prevProps . showNotification !== this . props . showNotification ) {
52+ componentDidMount ( ) {
5653 Animated . timing ( this . state . notificationOpacity , {
5754 toValue : this . props . showNotification ? 1 : 0 ,
5855 duration : 500 ,
5956 } ) . start ( ) ;
6057 }
61- }
6258
63- render ( ) {
64- if ( ! this . props . showNotification ) {
65- return null ;
66- } else {
67- return (
68- < Animated . View
69- style = { {
70- position : 'absolute' ,
71- bottom : 0 ,
72- opacity : this . state . notificationOpacity ,
73- } }
74- >
75- < Container onPress = { this . props . onPress } >
76- < MessageNotificationText > New Messages</ MessageNotificationText >
77- </ Container >
78- </ Animated . View >
79- ) ;
59+ componentDidUpdate ( prevProps ) {
60+ if ( prevProps . showNotification !== this . props . showNotification ) {
61+ Animated . timing ( this . state . notificationOpacity , {
62+ toValue : this . props . showNotification ? 1 : 0 ,
63+ duration : 500 ,
64+ } ) . start ( ) ;
65+ }
66+ }
67+
68+ render ( ) {
69+ if ( ! this . props . showNotification ) {
70+ return null ;
71+ } else {
72+ return (
73+ < Animated . View
74+ style = { {
75+ position : 'absolute' ,
76+ bottom : 0 ,
77+ opacity : this . state . notificationOpacity ,
78+ } }
79+ >
80+ < Container onPress = { this . props . onPress } >
81+ < MessageNotificationText > New Messages</ MessageNotificationText >
82+ </ Container >
83+ </ Animated . View >
84+ ) ;
85+ }
8086 }
81- }
82- }
87+ } ,
88+ ) ;
0 commit comments