191c81973S猫头猫import {GlobalState} from '@/utils/stateMapper'; 291c81973S猫头猫import {useCallback} from 'react'; 3*ec4205c4S猫头猫import {DeviceEventEmitter} from 'react-native'; 4378a6099S猫头猫import panels from './types'; 5378a6099S猫头猫 6378a6099S猫头猫type IPanel = typeof panels; 7378a6099S猫头猫type IPanelkeys = keyof IPanel; 8378a6099S猫头猫 991c81973S猫头猫interface IPanelInfo { 1091c81973S猫头猫 name: IPanelkeys | null; 1191c81973S猫头猫 payload: any; 1291c81973S猫头猫} 13378a6099S猫头猫 1491c81973S猫头猫/** 浮层信息 */ 1591c81973S猫头猫export const panelInfoStore = new GlobalState<IPanelInfo>({ 1691c81973S猫头猫 name: null, 1791c81973S猫头猫 payload: null, 1891c81973S猫头猫}); 19378a6099S猫头猫 2091c81973S猫头猫/** 使用浮层的hook */ 2191c81973S猫头猫export default function usePanel() { 2291c81973S猫头猫 const showPanel = useCallback(function <T extends IPanelkeys>( 23378a6099S猫头猫 name: T, 24378a6099S猫头猫 payload?: Parameters<IPanel[T]>[0], 25378a6099S猫头猫 ) { 26*ec4205c4S猫头猫 if (panelInfoStore.getValue().name) { 27*ec4205c4S猫头猫 DeviceEventEmitter.emit('hidePanel', () => { 2891c81973S猫头猫 panelInfoStore.setValue({ 2991c81973S猫头猫 name, 3091c81973S猫头猫 payload, 3191c81973S猫头猫 }); 32*ec4205c4S猫头猫 }); 33*ec4205c4S猫头猫 } else { 34*ec4205c4S猫头猫 panelInfoStore.setValue({ 35*ec4205c4S猫头猫 name, 36*ec4205c4S猫头猫 payload, 37*ec4205c4S猫头猫 }); 38*ec4205c4S猫头猫 } 39378a6099S猫头猫 }, 4091c81973S猫头猫 []); 41378a6099S猫头猫 42*ec4205c4S猫头猫 const hidePanel = useCallback(() => { 43*ec4205c4S猫头猫 DeviceEventEmitter.emit('hidePanel'); 44c9af9657S猫头猫 }, []); 45378a6099S猫头猫 46*ec4205c4S猫头猫 return {showPanel, hidePanel}; 47378a6099S猫头猫} 48