export ctx + update doc
This commit is contained in:
parent
519f977892
commit
a2a4f59f81
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## MenuProvider
|
## MenuProvider
|
||||||
|
|
||||||
It provides methods to handle popup menus imperatively. The same methods are exposed to the child context with name `menuActions`.
|
It provides methods to handle popup menus imperatively. The same methods are exposed to the context property `menuActions`. This can be retrieved by HOC `withMenuContext` that adds `ctx` property to your component. Then simply call `props.ctx.menuActions.method()`.
|
||||||
|
|
||||||
**Note:** It is important that `<MenuProvider />` is on the top of the component hierarchy (e.g. `ScrollView` should be inside of `MenuProvider`) and wraps all `<Menu />` components.
|
**Note:** It is important that `<MenuProvider />` is on the top of the component hierarchy (e.g. `ScrollView` should be inside of `MenuProvider`) and wraps all `<Menu />` components.
|
||||||
This is needed in order to solve z-index issues.
|
This is needed in order to solve z-index issues.
|
||||||
|
|
|
@ -4,9 +4,19 @@ import Menu, {
|
||||||
MenuProvider,
|
MenuProvider,
|
||||||
MenuOptions,
|
MenuOptions,
|
||||||
MenuOption,
|
MenuOption,
|
||||||
MenuTrigger
|
MenuTrigger,
|
||||||
|
withMenuContext,
|
||||||
} from 'react-native-popup-menu';
|
} from 'react-native-popup-menu';
|
||||||
|
|
||||||
|
const Openner = (props) => (
|
||||||
|
<TouchableOpacity style={{ paddingTop: 50 }}
|
||||||
|
onPress={() => props.ctx.menuActions.openMenu('menu-1')}>
|
||||||
|
<Text>Open menu from context</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
);
|
||||||
|
|
||||||
|
const ContextOpenner = withMenuContext(Openner);
|
||||||
|
|
||||||
export default class ControlledExample extends Component {
|
export default class ControlledExample extends Component {
|
||||||
|
|
||||||
onOptionSelect(value) {
|
onOptionSelect(value) {
|
||||||
|
@ -28,7 +38,8 @@ export default class ControlledExample extends Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<MenuProvider style={{flexDirection: 'column', padding: 30}}>
|
<MenuProvider style={{flexDirection: 'column', padding: 30}}>
|
||||||
<Menu onSelect={value => this.onOptionSelect(value)} ref={this.onRef}>
|
<Menu onSelect={value => this.onOptionSelect(value)}
|
||||||
|
name="menu-1" ref={this.onRef}>
|
||||||
<MenuTrigger text='Select option'/>
|
<MenuTrigger text='Select option'/>
|
||||||
<MenuOptions>
|
<MenuOptions>
|
||||||
<MenuOption value={1} text='One' />
|
<MenuOption value={1} text='One' />
|
||||||
|
@ -38,6 +49,7 @@ export default class ControlledExample extends Component {
|
||||||
<TouchableOpacity style={{ paddingTop: 50 }} onPress={() => this.openMenu()}>
|
<TouchableOpacity style={{ paddingTop: 50 }} onPress={() => this.openMenu()}>
|
||||||
<Text>Open menu from outside</Text>
|
<Text>Open menu from outside</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
<ContextOpenner />
|
||||||
</MenuProvider>
|
</MenuProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import './polyfills';
|
||||||
import { deprecatedComponent } from './helpers'
|
import { deprecatedComponent } from './helpers'
|
||||||
|
|
||||||
import Menu from './Menu';
|
import Menu from './Menu';
|
||||||
import MenuProvider from './MenuProvider';
|
import MenuProvider, { withCtx } from './MenuProvider';
|
||||||
import MenuOption from './MenuOption';
|
import MenuOption from './MenuOption';
|
||||||
import MenuOptions from './MenuOptions';
|
import MenuOptions from './MenuOptions';
|
||||||
import MenuTrigger from './MenuTrigger';
|
import MenuTrigger from './MenuTrigger';
|
||||||
|
@ -27,4 +27,5 @@ export {
|
||||||
MenuOptions,
|
MenuOptions,
|
||||||
MenuTrigger,
|
MenuTrigger,
|
||||||
renderers,
|
renderers,
|
||||||
|
withCtx as withMenuContext,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue