2021-02-10 06:18:40 +01:00
|
|
|
import React, { forwardRef, useEffect } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { View } from 'react-native';
|
|
|
|
import showPopupMenu from 'react-native-popup-menu-android';
|
|
|
|
|
|
|
|
const ToolTipMenu = (props, ref) => {
|
|
|
|
const handleToolTipSelection = selection => {
|
2021-02-25 07:46:04 +01:00
|
|
|
const action = props.actions.find(action => action.id === selection.id);
|
|
|
|
action.onPress();
|
2021-02-10 06:18:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const showMenu = () => {
|
|
|
|
const actions = props.actions.map(action => ({ id: action.id, label: action.text }));
|
|
|
|
showPopupMenu(actions, handleToolTipSelection, props.anchorRef.current);
|
|
|
|
};
|
|
|
|
|
2021-02-26 03:37:28 +01:00
|
|
|
const hideMenu = () => {
|
|
|
|
console.log('not implemented');
|
|
|
|
};
|
|
|
|
|
2021-02-10 06:18:40 +01:00
|
|
|
useEffect(() => {
|
|
|
|
ref.current.showMenu = showMenu;
|
2021-02-26 03:37:28 +01:00
|
|
|
ref.current.hideMenu = hideMenu;
|
2021-02-10 06:18:40 +01:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-02-26 03:37:28 +01:00
|
|
|
}, [ref, props.actions]);
|
2021-02-10 06:18:40 +01:00
|
|
|
|
2021-02-25 04:09:41 +01:00
|
|
|
return <View ref={ref} />;
|
2021-02-10 06:18:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default forwardRef(ToolTipMenu);
|
|
|
|
ToolTipMenu.propTypes = {
|
|
|
|
actions: PropTypes.arrayOf(PropTypes.shape).isRequired,
|
|
|
|
anchorRef: PropTypes.node,
|
|
|
|
};
|