import React, { Component } from 'react'; import { StyleSheet, Text, View, ScrollView } from 'react-native'; import Menu, { MenuProvider, MenuTrigger, MenuOptions, MenuOption, renderers, } from 'react-native-popup-menu'; let unique = 0; const { SlideInMenu } = renderers; export default class Example extends Component { constructor(props, ctx) { super(props, ctx); this.state = { log: [] }; } selectNumber(value) { this.addLog(`selecting number: ${value}`); } selectOptionType(value) { const v = typeof value === 'object' ? JSON.stringify(value) : value; this.addLog(`selecting type: ${v}`); return value !== 'Do not close'; } addLog(value) { this.setState({ log: [...this.state.log, { value, id: ++unique, }], }); } 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 ( this.selectNumber(value)}> Slide-in menu... { null /* conditional not rendered option */ } this.selectOptionType(value)} onBackdropPress={() => this.addLog('menu will be closed by backdrop')} onOpen={() => this.addLog('menu is opening')} onClose={() => this.addLog('menu is closing')} > Context menu... {this.state.log.map((l, i) => { const wrapperStyle = {backgroundColor: i % 2 ? 'white' : 'whitesmoke'}; const textStyle = {color: l.highlighted ? 'red' : 'gray'}; return ( {l.value} this.toggleHighlight(l.id)} text={l.highlighted ? 'Unhighlight' : 'Highlight'} /> this.deleteLogItem(l.id)} text='Delete' /> ); })} ); } } const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'column', backgroundColor: 'lightgray', }, topbar: { flexDirection: 'row', backgroundColor: 'dimgray', paddingTop : 15, }, trigger: { padding: 5, margin: 5, }, triggerText: { color: 'white', }, disabled: { color: '#ccc', }, divider: { marginVertical: 5, marginHorizontal: 2, borderBottomWidth: 1, borderColor: '#ccc', }, logView: { flex: 1, flexDirection: 'column', }, logItem: { flexDirection: 'row', padding: 8, }, slideInOption: { padding: 5, }, text: { fontSize: 18, }, });