import * as React from "react"; import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext"; import { buildEntryActions, EntryActionDeps, } from "@applicaster/zapp-react-native-utils/entryActions"; import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation"; import { useScreenStateStore } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore"; import { useCurrentScreenData, useScreenContext, } from "@applicaster/zapp-react-native-utils/reactHooks/screen"; import { RegisteredAction } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator"; /** * Expands `entry.extensions.entry_action` into invokable actions, against the * screen this hook is called from. * * Entry actions are data on the entry, not an installed capability, so there is * nothing to look up by identifier: the surface showing the entry expands them. * That also decides which screen they execute against — the one whose tree this * hook runs in, rather than whichever screen happened to be current when a * global provider was registered. * * Pass the result to `resolveActionIdentifiers` / `resolvePlayerActions` as * `expandEntryActions`. */ export function useEntryActionsExpander(): ( entry: ZappEntry | ZappFeed ) => RegisteredAction[] { const { pathname } = useRoute(); const screenContext = useScreenContext(); const screenData = useCurrentScreenData(); const screenState = screenContext?.options; const screenStateStore = useScreenStateStore(); const actionExecutor = React.useContext(ActionExecutorContext); // Read through a ref so the returned expander keeps a stable identity: it // feeds `useMemo` dependency lists on surfaces that re-resolve their actions // on every registry change. const depsRef = React.useRef(); depsRef.current = { actionExecutor, actionContext: { screenData, screenState, screenRoute: pathname, screenStateStore, // From the screen context, the way `useCellClick` builds the same bag. // The ZappPipes entry context is a route-keyed map, so reading `.data` // off it was always undefined. screenEntry: screenContext?.entry, }, }; return React.useCallback( (entry: ZappEntry | ZappFeed) => buildEntryActions(entry, depsRef.current), [] ); }