mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-13 11:09:20 +01:00
Update useMenuElements.ios.ts
This commit is contained in:
parent
1cada11c50
commit
9ec0ef51e4
1 changed files with 28 additions and 40 deletions
|
@ -21,9 +21,6 @@ const handlerRegistry = new Map<string, MenuActionHandler>();
|
|||
// Store subscription references for proper cleanup
|
||||
let subscriptions: { remove: () => void }[] = [];
|
||||
|
||||
// For debugging purposes - track active screen
|
||||
let activeScreen: string | null = null;
|
||||
|
||||
// Create a more robust emitter with error handling
|
||||
try {
|
||||
if (Platform.OS === 'ios' && MenuElementsEmitter) {
|
||||
|
@ -48,8 +45,8 @@ function safeNavigate(routeName: string, params?: Record<string, any>): void {
|
|||
navigationRef.dispatch(
|
||||
CommonActions.navigate({
|
||||
name: routeName,
|
||||
params
|
||||
})
|
||||
params,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -64,7 +61,7 @@ function cleanupListeners(): void {
|
|||
try {
|
||||
subscription.remove();
|
||||
} catch (e) {
|
||||
console.warn("[MenuElements] Error removing subscription:", e);
|
||||
console.warn('[MenuElements] Error removing subscription:', e);
|
||||
}
|
||||
});
|
||||
subscriptions = [];
|
||||
|
@ -95,8 +92,6 @@ function initializeListeners(): void {
|
|||
const currentRoute = navigationRef.current?.getCurrentRoute();
|
||||
if (!currentRoute) return;
|
||||
|
||||
activeScreen = currentRoute.name;
|
||||
|
||||
const screenName = currentRoute.name;
|
||||
const params = (currentRoute.params as { walletID?: string }) || {};
|
||||
const walletID = params.walletID;
|
||||
|
@ -110,18 +105,16 @@ function initializeListeners(): void {
|
|||
if (typeof handler === 'function') {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if (eventEmitter) {
|
||||
try {
|
||||
subscriptions.push(eventEmitter.addListener('openSettings', globalActions.navigateToSettings));
|
||||
subscriptions.push(eventEmitter.addListener('addWalletMenuAction', globalActions.navigateToAddWallet));
|
||||
subscriptions.push(eventEmitter.addListener('importWalletMenuAction', globalActions.navigateToImportWallet));
|
||||
subscriptions.push(eventEmitter.addListener('reloadTransactionsMenuAction', globalActions.executeReloadTransactions));
|
||||
} catch (error) {
|
||||
console.error("[MenuElements] Error setting up event listeners:", error);
|
||||
}
|
||||
try {
|
||||
subscriptions.push(eventEmitter.addListener('openSettings', globalActions.navigateToSettings));
|
||||
subscriptions.push(eventEmitter.addListener('addWalletMenuAction', globalActions.navigateToAddWallet));
|
||||
subscriptions.push(eventEmitter.addListener('importWalletMenuAction', globalActions.navigateToImportWallet));
|
||||
subscriptions.push(eventEmitter.addListener('reloadTransactionsMenuAction', globalActions.executeReloadTransactions));
|
||||
} catch (error) {
|
||||
console.error('[MenuElements] Error setting up event listeners:', error);
|
||||
}
|
||||
|
||||
listenersInitialized = true;
|
||||
|
@ -139,12 +132,7 @@ const useMenuElements = (): MenuElementsHook => {
|
|||
useEffect(() => {
|
||||
initializeListeners();
|
||||
|
||||
const unsubscribe = navigationRef.addListener('state', () => {
|
||||
const currentRoute = navigationRef.current?.getCurrentRoute();
|
||||
if (currentRoute) {
|
||||
activeScreen = currentRoute.name;
|
||||
}
|
||||
});
|
||||
const unsubscribe = navigationRef.addListener('state', () => {});
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
|
|
Loading…
Add table
Reference in a new issue