-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApp.tsx
85 lines (78 loc) · 2.03 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
import * as React from 'react';
import {View, Text} from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {
ToastBannerProvider,
ToastBannerPresenter,
useToastBannerToggler,
Transition,
} from 'react-native-toast-banner';
import {RegularBanner, BigBanner, Toast} from './src/my-banners';
const bannersList = (hideBanner: () => void) => [
{
buttonTitle: 'Regular banner',
bannerConfig: {
contentView: <RegularBanner />,
backgroundColor: 'red',
onPress: () => {
console.log('banner pressed');
},
},
},
{
buttonTitle: 'Big banner',
bannerConfig: {
contentView: <BigBanner />,
backgroundColor: 'blue',
transitions: [Transition.MoveLinear, Transition.FadeInOut],
disableHideOnPress: true,
onPress: () => {
console.log('banner pressed');
setTimeout(hideBanner, 500); // dismiss after delay
},
},
},
{
buttonTitle: 'Toast',
bannerConfig: {
contentView: <Toast />,
duration: 2000,
transitions: [Transition.FadeInOut],
},
},
];
const HomeScreen = () => {
const {showBanner, hideBanner} = useToastBannerToggler();
return (
<View style={{flex: 1, alignItems: 'center', top: 100}}>
{bannersList(hideBanner).map((banner, i) => (
<Text
style={{marginVertical: 10}}
key={i.toString()}
onPress={() => showBanner(banner.bannerConfig)}>
{banner.buttonTitle}
</Text>
))}
</View>
);
};
const AppNavigator = createStackNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
title: 'react-native-toast-banner',
},
},
});
const AppContainer = createAppContainer(AppNavigator);
const App = () => (
<SafeAreaProvider>
<ToastBannerProvider>
<AppContainer />
<ToastBannerPresenter />
</ToastBannerProvider>
</SafeAreaProvider>
);
export default App;