-
Notifications
You must be signed in to change notification settings - Fork 58
/
App.tsx
160 lines (151 loc) · 4.65 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import * as React from 'react';
import { StyleSheet, View, StatusBar, Platform, Text } from 'react-native';
import { Easing, Notifier, NotifierRoot, NotifierComponents } from 'react-native-notifier';
import Modal from 'react-native-modal';
import Button from './Button';
import CustomComponent from './CustomComponent';
const isAndroid = Platform.OS === 'android';
export default function App() {
const notifierRef = React.useRef<NotifierRoot>(null);
const [statusBar, setStatusBar] = React.useState(true);
const [statusBarTranslucent, setStatusBarTranslucent] = React.useState(false);
const [isModalVisible, setModalVisible] = React.useState(false);
if (isAndroid) {
StatusBar.setHidden(!statusBar);
StatusBar.setTranslucent(statusBarTranslucent);
}
return (
<View style={styles.container}>
<Button
title="Easing: bounce"
onPress={() =>
Notifier.showNotification({
title: 'John Doe',
description: 'Hello! Can you help me with notifications?',
duration: 0,
showAnimationDuration: 800,
showEasing: Easing.bounce,
hideEasing: Easing.circle,
onStartHiding: () => console.log('Start Hiding'),
onHidden: () => console.log('Hidden'),
onPress: () => console.log('Press'),
hideOnPress: false,
swipePixelsToClose: 10,
})
}
/>
<Button
title="Long Text"
onPress={() =>
Notifier.showNotification({
title: 'New request',
duration: 6000,
description:
'You just got new incoming request from John Doe, and this is a long description',
})
}
/>
<Button
title="With Image"
onPress={() =>
Notifier.showNotification({
title: 'Check this image!',
description: 'Cool, right?',
componentProps: {
imageSource: require('./react.jpg'),
},
})
}
/>
<Button
title="Error Alert"
onPress={() =>
Notifier.showNotification({
title: 'The request was failed',
description: 'Check your internet connection, please',
Component: NotifierComponents.Alert,
componentProps: {
alertType: 'error',
},
})
}
/>
<Button
title="Successful Alert"
onPress={() =>
Notifier.showNotification({
title: 'Your profile was successfully saved!',
Component: NotifierComponents.Alert,
componentProps: {
alertType: 'success',
},
})
}
/>
<Button
title="Custom component"
onPress={() =>
notifierRef.current?.showNotification({
title: 'Custom Component',
description: 'You can pass component that you want to render',
Component: CustomComponent,
})
}
/>
<Button
title="Using refs"
onPress={() =>
notifierRef.current?.showNotification({
title: 'Called using ref!',
description: 'Amazing!',
})
}
/>
<Button title="Hide" onPress={() => Notifier.hideNotification()} />
{isAndroid && (
<>
<Button title="Toggle Status Bar" onPress={() => setStatusBar(v => !v)} />
<Button
title="Toggle Status Bar Translucent"
onPress={() => setStatusBarTranslucent(v => !v)}
/>
</>
)}
<Button title="Open react-native-modal" onPress={() => setModalVisible(true)} />
<Modal isVisible={isModalVisible} coverScreen={false}>
<View style={styles.modalContainer}>
<Text>
Property "coverScreen" set to "false" does the trick and notification should be rendered
above the modal!
</Text>
<Button
title="Show notification"
onPress={() =>
Notifier.showNotification({
title: 'Hello react-native-modal!',
description: 'Modal + Notifier = ❤️',
})
}
/>
<Button title="Hide modal" onPress={() => setModalVisible(false)} />
</View>
</Modal>
<NotifierRoot ref={notifierRef} />
</View>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#f1f1f1',
flex: 1,
justifyContent: 'center',
},
modalContainer: {
flex: 1,
backgroundColor: 'white',
justifyContent: 'center',
borderRadius: 25,
maxHeight: 500,
paddingHorizontal: 30,
},
});