-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathCloseOnBackExample.js
73 lines (69 loc) · 1.89 KB
/
CloseOnBackExample.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
70
71
72
73
import React, { Component } from "react";
import { Text, Button } from "react-native";
import {
Menu,
MenuProvider,
MenuOptions,
MenuOption,
MenuTrigger,
} from "react-native-popup-menu";
class CloseOnBackExample extends Component {
state = {
customBackHandler: false,
additionalMenu: false,
};
customBackHandler = (instance) => {
alert(
`Back button was pressed. Current menu state: ${
instance.isMenuOpen() ? "opened" : "closed"
}`
);
return true;
};
render() {
const { additionalMenu } = this.state;
return (
<MenuProvider
style={{ flexDirection: "column", padding: 50 }}
backHandler={
this.state.customBackHandler ? this.customBackHandler : true
}
>
<Button
title={
this.state.customBackHandler
? "Change to default"
: "Change to custom"
}
onPress={() =>
this.setState({ customBackHandler: !this.state.customBackHandler })
}
/>
<Menu>
<MenuTrigger text="Select option" />
<MenuOptions>
<MenuOption value={1} text="One" />
<MenuOption value={2}>
<Text style={{ color: "red" }}>Two</Text>
</MenuOption>
<MenuOption value={3} disabled={true} text="Three" />
</MenuOptions>
</Menu>
<Button
title={additionalMenu ? "Remove 2nd menu" : "Add 2nd menu"}
onPress={() => this.setState({ additionalMenu: !additionalMenu })}
/>
{additionalMenu && (
<Menu>
<MenuTrigger text="Select option 2" />
<MenuOptions>
<MenuOption value={1} text="One" />
<MenuOption value={2} text="Two" />
</MenuOptions>
</Menu>
)}
</MenuProvider>
);
}
}
export default CloseOnBackExample;