forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnackbarExample.js
69 lines (61 loc) · 1.36 KB
/
SnackbarExample.js
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
/* @flow */
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import {
Snackbar,
Colors,
withTheme,
Button,
type Theme,
} from 'react-native-paper';
type Props = {
theme: Theme,
};
type State = {
visible: boolean,
};
class SnackbarExample extends React.Component<Props, State> {
static title = 'Snackbar';
state = {
visible: false,
};
render() {
const {
theme: {
colors: { background },
},
} = this.props;
return (
<View style={[styles.container, { backgroundColor: background }]}>
<Button
mode="outlined"
onPress={() => this.setState(state => ({ visible: !state.visible }))}
>
{this.state.visible ? 'Hide' : 'Show'}
</Button>
<Snackbar
visible={this.state.visible}
onDismiss={() => this.setState({ visible: false })}
action={{
label: 'Undo',
onPress: () => {
// Do something
},
}}
duration={Snackbar.DURATION_MEDIUM}
>
Hey there! I'm a Snackbar.
</Snackbar>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.grey200,
alignItems: 'center',
justifyContent: 'center',
},
});
export default withTheme(SnackbarExample);