- App.tsx: full navigation (Auth stack + Main tabs with 5 screens) - Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen - HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors - MapScreen: interactive map with layer toggles (6 layers) - MarketplaceScreen: categories (6), products (5), search - ChatScreen: AI chat with quick prompts (4), bot responses - ProfileScreen: user info, stats, menu (9 items), logout - AlertsScreen: alert list with severity, acknowledge - SensorsScreen: sensor list with type filters (6 types), search - ZonesScreen: zone cards with stats - SettingsScreen: language picker (FR/EN/ES/DE), privacy, about - Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n - Hooks: useSensors, useAlerts, useNotifications, useLocation - Components: Card, Button, LoadingSpinner, ErrorBoundary, Header - Services: iotService, notificationService (with axios API client) - Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN) - Theme: colors.ts with full design system (Blue Ocean palette) - Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
125 lines
3.6 KiB
TypeScript
125 lines
3.6 KiB
TypeScript
'use strict';
|
|
import { runOnUIImmediately } from '../threads';
|
|
|
|
type CallbackDetails = {
|
|
callback: (frameInfo: FrameInfo) => void;
|
|
startTime: number | null;
|
|
};
|
|
|
|
export type FrameInfo = {
|
|
timestamp: number;
|
|
timeSincePreviousFrame: number | null;
|
|
timeSinceFirstFrame: number;
|
|
};
|
|
|
|
export interface FrameCallbackRegistryUI {
|
|
frameCallbackRegistry: Map<number, CallbackDetails>;
|
|
activeFrameCallbacks: Set<number>;
|
|
previousFrameTimestamp: number | null;
|
|
runCallbacks: (callId: number) => void;
|
|
nextCallId: number;
|
|
registerFrameCallback: (
|
|
callback: (frameInfo: FrameInfo) => void,
|
|
callbackId: number
|
|
) => void;
|
|
unregisterFrameCallback: (callbackId: number) => void;
|
|
manageStateFrameCallback: (callbackId: number, state: boolean) => void;
|
|
}
|
|
|
|
export const prepareUIRegistry = runOnUIImmediately(() => {
|
|
'worklet';
|
|
|
|
const frameCallbackRegistry: FrameCallbackRegistryUI = {
|
|
frameCallbackRegistry: new Map<number, CallbackDetails>(),
|
|
activeFrameCallbacks: new Set<number>(),
|
|
previousFrameTimestamp: null,
|
|
nextCallId: 0,
|
|
|
|
runCallbacks(callId) {
|
|
const loop = (timestamp: number) => {
|
|
if (callId !== this.nextCallId) {
|
|
return;
|
|
}
|
|
if (this.previousFrameTimestamp === null) {
|
|
this.previousFrameTimestamp = timestamp;
|
|
}
|
|
|
|
const delta = timestamp - this.previousFrameTimestamp;
|
|
|
|
this.activeFrameCallbacks.forEach((callbackId: number) => {
|
|
const callbackDetails = this.frameCallbackRegistry.get(callbackId)!;
|
|
|
|
const { startTime } = callbackDetails;
|
|
|
|
if (startTime === null) {
|
|
// First frame
|
|
callbackDetails.startTime = timestamp;
|
|
|
|
callbackDetails.callback({
|
|
timestamp,
|
|
timeSincePreviousFrame: null,
|
|
timeSinceFirstFrame: 0,
|
|
});
|
|
} else {
|
|
// Next frame
|
|
callbackDetails.callback({
|
|
timestamp,
|
|
timeSincePreviousFrame: delta,
|
|
timeSinceFirstFrame: timestamp - startTime,
|
|
});
|
|
}
|
|
});
|
|
|
|
if (this.activeFrameCallbacks.size > 0) {
|
|
this.previousFrameTimestamp = timestamp;
|
|
requestAnimationFrame(loop);
|
|
} else {
|
|
this.previousFrameTimestamp = null;
|
|
}
|
|
};
|
|
|
|
// runCallback() should only be called after registering a callback,
|
|
// so if there is only one active callback, then it means that there were
|
|
// zero previously and the loop isn't running yet.
|
|
if (this.activeFrameCallbacks.size === 1 && callId === this.nextCallId) {
|
|
requestAnimationFrame(loop);
|
|
}
|
|
},
|
|
|
|
registerFrameCallback(
|
|
callback: (frameInfo: FrameInfo) => void,
|
|
callbackId: number
|
|
) {
|
|
this.frameCallbackRegistry.set(callbackId, {
|
|
callback,
|
|
startTime: null,
|
|
});
|
|
},
|
|
|
|
unregisterFrameCallback(callbackId: number) {
|
|
this.manageStateFrameCallback(callbackId, false);
|
|
this.frameCallbackRegistry.delete(callbackId);
|
|
},
|
|
|
|
manageStateFrameCallback(callbackId: number, state: boolean) {
|
|
if (callbackId === -1) {
|
|
return;
|
|
}
|
|
if (state) {
|
|
this.activeFrameCallbacks.add(callbackId);
|
|
this.runCallbacks(this.nextCallId);
|
|
} else {
|
|
const callback = this.frameCallbackRegistry.get(callbackId)!;
|
|
callback.startTime = null;
|
|
|
|
this.activeFrameCallbacks.delete(callbackId);
|
|
if (this.activeFrameCallbacks.size === 0) {
|
|
this.nextCallId += 1;
|
|
}
|
|
}
|
|
},
|
|
};
|
|
|
|
global._frameCallbackRegistry = frameCallbackRegistry;
|
|
});
|