import { ReplaySubject } from "rxjs"; import { filter } from "rxjs/operators"; import { BUTTON_PREFIX } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/DefaultComponents/tv/TvActionButtons/const"; import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager/index.ios"; type FocusableID = string; type RegistrationEvent = { id: FocusableID; registered: boolean; }; const isFocusableButton = (id: Option): boolean => id && id.includes?.(BUTTON_PREFIX); const registeredSubject$ = new ReplaySubject(1); export const focusableButtonsRegistration$ = (focusableGroupId: string) => registeredSubject$.pipe( filter( (value) => value.registered && focusManager.isChildOf(value.id, focusableGroupId) ) ); export const emitRegistered = (id: Option): void => { if (isFocusableButton(id)) { registeredSubject$.next({ id, registered: true }); } }; export const emitUnregistered = (id: Option): void => { if (isFocusableButton(id)) { registeredSubject$.next({ id, registered: false }); } };