2016-05-16 14:54:39 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { StyleSheet, Text, View, ScrollView } from 'react-native';
|
|
|
|
import Menu, {
|
2017-12-19 10:08:34 +00:00
|
|
|
MenuProvider,
|
2016-05-16 14:54:39 +00:00
|
|
|
MenuTrigger,
|
|
|
|
MenuOptions,
|
2016-05-31 09:06:25 +00:00
|
|
|
MenuOption,
|
2018-06-24 10:47:38 +00:00
|
|
|
renderers,
|
2016-05-16 14:54:39 +00:00
|
|
|
} from 'react-native-popup-menu';
|
|
|
|
|
|
|
|
let unique = 0;
|
2016-05-31 09:06:25 +00:00
|
|
|
const { SlideInMenu } = renderers;
|
2016-05-16 14:54:39 +00:00
|
|
|
|
|
|
|
export default class Example extends Component {
|
|
|
|
|
|
|
|
constructor(props, ctx) {
|
|
|
|
super(props, ctx);
|
|
|
|
this.state = { log: [] };
|
|
|
|
}
|
|
|
|
|
|
|
|
selectNumber(value) {
|
2016-05-27 12:40:19 +00:00
|
|
|
this.addLog(`selecting number: ${value}`);
|
2016-05-16 14:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
selectOptionType(value) {
|
|
|
|
const v = typeof value === 'object' ? JSON.stringify(value) : value;
|
2016-05-27 12:40:19 +00:00
|
|
|
this.addLog(`selecting type: ${v}`);
|
|
|
|
return value !== 'Do not close';
|
|
|
|
}
|
|
|
|
|
|
|
|
addLog(value) {
|
2016-05-16 14:54:39 +00:00
|
|
|
this.setState({
|
|
|
|
log: [...this.state.log, {
|
2016-05-27 12:40:19 +00:00
|
|
|
value,
|
2018-06-24 10:47:38 +00:00
|
|
|
id: ++unique,
|
|
|
|
}],
|
2016-05-16 14:54:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleHighlight(id) {
|
|
|
|
const log = this.state.log.map(l => {
|
|
|
|
if (l.id === id) {
|
|
|
|
return Object.assign({}, l, {highlighted: !l.highlighted});
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
})
|
|
|
|
this.setState({ log });
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteLogItem(id) {
|
|
|
|
const log = this.state.log.filter(l => l.id !== id);
|
|
|
|
this.setState({ log });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2017-12-19 10:08:34 +00:00
|
|
|
<MenuProvider style={{flex: 1}}>
|
2016-05-16 14:54:39 +00:00
|
|
|
<View style={styles.container}>
|
|
|
|
|
|
|
|
<View style={styles.topbar}>
|
2016-05-31 09:06:25 +00:00
|
|
|
<Menu name="numbers" renderer={SlideInMenu} onSelect={value => this.selectNumber(value)}>
|
2016-05-16 14:54:39 +00:00
|
|
|
<MenuTrigger style={styles.trigger}>
|
2017-12-08 10:26:28 +00:00
|
|
|
<Text style={[styles.text, styles.triggerText]}>Slide-in menu...</Text>
|
2016-05-16 14:54:39 +00:00
|
|
|
</MenuTrigger>
|
2017-12-08 10:26:28 +00:00
|
|
|
<MenuOptions customStyles={{ optionText: [styles.text, styles.slideInOption] }}>
|
|
|
|
<MenuOption value={1} text='Option one' />
|
2016-05-23 14:55:16 +00:00
|
|
|
<MenuOption value={2} text='Option two' />
|
|
|
|
<MenuOption value={3} text='Option three' />
|
|
|
|
<MenuOption value={4} text='Option four' />
|
2016-09-14 09:19:11 +00:00
|
|
|
{ null /* conditional not rendered option */ }
|
2016-05-23 14:55:16 +00:00
|
|
|
<MenuOption value={5} text='Option five' />
|
2016-05-16 14:54:39 +00:00
|
|
|
</MenuOptions>
|
|
|
|
</Menu>
|
|
|
|
<View style={{flex:1}}></View>
|
2016-05-27 12:40:19 +00:00
|
|
|
<Menu name="types" onSelect={value => this.selectOptionType(value)}
|
|
|
|
onBackdropPress={() => this.addLog('menu will be closed by backdrop')}
|
|
|
|
onOpen={() => this.addLog('menu is opening')}
|
|
|
|
onClose={() => this.addLog('menu is closing')}
|
|
|
|
>
|
2016-05-16 14:54:39 +00:00
|
|
|
<MenuTrigger style={styles.trigger}>
|
2017-12-08 10:26:28 +00:00
|
|
|
<Text style={[styles.text, styles.triggerText]}>Context menu...</Text>
|
2016-05-16 14:54:39 +00:00
|
|
|
</MenuTrigger>
|
2017-12-08 10:26:28 +00:00
|
|
|
<MenuOptions customStyles={{ optionText: styles.text }}>
|
2016-05-23 14:55:16 +00:00
|
|
|
<MenuOption value="Normal" text='Normal' />
|
2017-10-31 22:05:24 +00:00
|
|
|
<MenuOption value="N/A" disabled={true} text='Disabled' />
|
|
|
|
<MenuOption value="N/A" disableTouchable={true} text='Non-selectable' />
|
2016-05-23 14:55:16 +00:00
|
|
|
<MenuOption value="Do not close" text='Do not close' />
|
2016-05-16 14:54:39 +00:00
|
|
|
<View style={styles.divider}/>
|
2016-05-23 14:55:16 +00:00
|
|
|
<MenuOption value={{ text: 'Hello world!' }} text='Object as value' />
|
2016-05-16 14:54:39 +00:00
|
|
|
</MenuOptions>
|
|
|
|
</Menu>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
<ScrollView style={styles.logView}>
|
|
|
|
{this.state.log.map((l, i) => {
|
|
|
|
const wrapperStyle = {backgroundColor: i % 2 ? 'white' : 'whitesmoke'};
|
|
|
|
const textStyle = {color: l.highlighted ? 'red' : 'gray'};
|
|
|
|
return (
|
|
|
|
<View style={[styles.logItem, wrapperStyle]} key={l.id}>
|
2017-12-08 10:26:28 +00:00
|
|
|
<Text style={[styles.text, textStyle]}>{l.value}</Text>
|
2016-05-16 14:54:39 +00:00
|
|
|
<View style={{flex:1}}></View>
|
2016-05-25 09:07:25 +00:00
|
|
|
<Menu>
|
2017-12-08 10:26:28 +00:00
|
|
|
<MenuTrigger text='edit' customStyles={{ triggerText: styles.text }} />
|
|
|
|
<MenuOptions customStyles={{ optionText: styles.text }}>
|
2016-05-25 09:07:25 +00:00
|
|
|
<MenuOption onSelect={() => this.toggleHighlight(l.id)} text={l.highlighted ? 'Unhighlight' : 'Highlight'} />
|
|
|
|
<MenuOption onSelect={() => this.deleteLogItem(l.id)} text='Delete' />
|
2016-05-16 14:54:39 +00:00
|
|
|
</MenuOptions>
|
|
|
|
</Menu>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</ScrollView>
|
|
|
|
|
|
|
|
</View>
|
2017-12-19 10:08:34 +00:00
|
|
|
</MenuProvider>
|
2016-05-16 14:54:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'column',
|
2016-05-31 07:53:31 +00:00
|
|
|
backgroundColor: 'lightgray',
|
2016-05-16 14:54:39 +00:00
|
|
|
},
|
|
|
|
topbar: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
backgroundColor: 'dimgray',
|
2016-05-20 12:04:48 +00:00
|
|
|
paddingTop : 15,
|
2016-05-16 14:54:39 +00:00
|
|
|
},
|
|
|
|
trigger: {
|
|
|
|
padding: 5,
|
|
|
|
margin: 5,
|
|
|
|
},
|
|
|
|
triggerText: {
|
|
|
|
color: 'white',
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
color: '#ccc',
|
|
|
|
},
|
|
|
|
divider: {
|
|
|
|
marginVertical: 5,
|
|
|
|
marginHorizontal: 2,
|
|
|
|
borderBottomWidth: 1,
|
2018-06-24 10:47:38 +00:00
|
|
|
borderColor: '#ccc',
|
2016-05-16 14:54:39 +00:00
|
|
|
},
|
|
|
|
logView: {
|
|
|
|
flex: 1,
|
|
|
|
flexDirection: 'column',
|
|
|
|
},
|
|
|
|
logItem: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
padding: 8,
|
|
|
|
},
|
2017-12-08 10:26:28 +00:00
|
|
|
slideInOption: {
|
|
|
|
padding: 5,
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
fontSize: 18,
|
2018-06-24 10:47:38 +00:00
|
|
|
},
|
2016-05-16 14:54:39 +00:00
|
|
|
});
|