forked from instea/react-native-popup-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloseOnBackExample.js
44 lines (40 loc) · 1.24 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
import React, { Component } from 'react';
import { Text, Button } from 'react-native';
import {
Menu,
MenuContext,
MenuOptions,
MenuOption,
MenuTrigger
} from 'react-native-popup-menu';
class CloseOnBackExample extends Component {
state = {
customBackHandler: false,
}
customBackHandler = (instance) => {
alert(`Back button was pressed. Current menu state: ${instance.isMenuOpen() ? 'opened' : 'closed'}`);
return true;
}
render() {
return (
<MenuContext
style={{flexDirection: 'column', padding: 30}}
backHandler={this.state.customBackHandler ? this.customBackHandler : true}>
<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={this.state.customBackHandler ? "Change to default" : "Change to custom"}
onPress={() => this.setState({ customBackHandler: !this.state.customBackHandler })}/>
</MenuContext>
);
}
}
export default CloseOnBackExample;