1import {GlobalState} from '@/utils/stateMapper'; 2import {DeviceEventEmitter} from 'react-native'; 3import panels from './types'; 4 5type IPanel = typeof panels; 6type IPanelkeys = keyof IPanel; 7 8interface IPanelInfo { 9 name: IPanelkeys | null; 10 payload: any; 11} 12 13/** 浮层信息 */ 14export const panelInfoStore = new GlobalState<IPanelInfo>({ 15 name: null, 16 payload: null, 17}); 18 19export function showPanel<T extends IPanelkeys>( 20 name: T, 21 payload?: Parameters<IPanel[T]>[0], 22) { 23 if (panelInfoStore.getValue().name) { 24 DeviceEventEmitter.emit('hidePanel', () => { 25 panelInfoStore.setValue({ 26 name, 27 payload, 28 }); 29 }); 30 } else { 31 panelInfoStore.setValue({ 32 name, 33 payload, 34 }); 35 } 36} 37 38export function hidePanel() { 39 DeviceEventEmitter.emit('hidePanel'); 40} 41