39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import {PropTypes, PureComponent} from 'react';
|
|
import RNBottomSheet from 'react-native-bottom-sheet';
|
|
|
|
export default class OptionsContext extends PureComponent {
|
|
static propTypes = {
|
|
actions: PropTypes.array,
|
|
cancelText: PropTypes.string
|
|
};
|
|
|
|
static defaultProps = {
|
|
actions: [],
|
|
cancelText: 'Cancel'
|
|
};
|
|
|
|
show = () => {
|
|
const {actions, cancelText} = this.props;
|
|
if (actions.length) {
|
|
const actionsText = actions.map((a) => a.text);
|
|
RNBottomSheet.showBottomSheetWithOptions({
|
|
options: [...actionsText, cancelText],
|
|
cancelButtonIndex: actions.length
|
|
}, (value) => {
|
|
if (value !== actions.length) {
|
|
const selectedOption = actions[value];
|
|
if (selectedOption && selectedOption.onPress) {
|
|
selectedOption.onPress();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
render() {
|
|
return null;
|
|
}
|
|
}
|