UNPKG

@gechiui/components

Version:
85 lines (77 loc) 2.13 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@gechiui/element"; /** * External dependencies */ import { ActionSheetIOS } from 'react-native'; /** * GeChiUI dependencies */ import { __ } from '@gechiui/i18n'; import { Component, forwardRef, useContext } from '@gechiui/element'; import { useDispatch, useSelect } from '@gechiui/data'; import { BottomSheetContext } from '@gechiui/components'; class Picker extends Component { presentPicker() { const { options, onChange, title, destructiveButtonIndex, disabledButtonIndices, getAnchor, isBottomSheetOpened, closeBottomSheet, onHandleClosingBottomSheet } = this.props; const labels = options.map(_ref => { let { label } = _ref; return label; }); const fullOptions = [__('取消')].concat(labels); ActionSheetIOS.showActionSheetWithOptions({ title, options: fullOptions, cancelButtonIndex: 0, destructiveButtonIndex, disabledButtonIndices, anchor: getAnchor && getAnchor() }, buttonIndex => { if (buttonIndex === 0) { return; } const selected = options[buttonIndex - 1]; if (selected.requiresModal && isBottomSheetOpened) { onHandleClosingBottomSheet(() => { onChange(selected.value); }); closeBottomSheet(); } else { onChange(selected.value); } }); } render() { return null; } } const PickerComponent = forwardRef((props, ref) => { const isBottomSheetOpened = useSelect(select => select('core/edit-post').isEditorSidebarOpened()); const { closeGeneralSidebar } = useDispatch('core/edit-post'); const { onHandleClosingBottomSheet } = useContext(BottomSheetContext); return createElement(Picker, _extends({ ref: ref }, props, { isBottomSheetOpened: isBottomSheetOpened, closeBottomSheet: closeGeneralSidebar, onHandleClosingBottomSheet: onHandleClosingBottomSheet })); }); export default PickerComponent; //# sourceMappingURL=index.ios.js.map