UNPKG

repoweaver

Version:

A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies

1 lines 6.07 kB
{"ast":null,"code":"\"use strict\";\n\nimport * as React from 'react';\nimport { NavigationContext } from \"./NavigationContext.js\";\nexport function useFocusEvents({\n state,\n emitter\n}) {\n const navigation = React.useContext(NavigationContext);\n const lastFocusedKeyRef = React.useRef(undefined);\n const currentFocusedKey = state.routes[state.index].key;\n React.useEffect(() => navigation?.addListener('focus', () => {\n lastFocusedKeyRef.current = currentFocusedKey;\n emitter.emit({\n type: 'focus',\n target: currentFocusedKey\n });\n }), [currentFocusedKey, emitter, navigation]);\n React.useEffect(() => navigation?.addListener('blur', () => {\n lastFocusedKeyRef.current = undefined;\n emitter.emit({\n type: 'blur',\n target: currentFocusedKey\n });\n }), [currentFocusedKey, emitter, navigation]);\n React.useEffect(() => {\n const lastFocusedKey = lastFocusedKeyRef.current;\n lastFocusedKeyRef.current = currentFocusedKey;\n if (lastFocusedKey === undefined && !navigation) {\n emitter.emit({\n type: 'focus',\n target: currentFocusedKey\n });\n }\n if (lastFocusedKey === currentFocusedKey || !(navigation ? navigation.isFocused() : true)) {\n return;\n }\n if (lastFocusedKey === undefined) {\n return;\n }\n emitter.emit({\n type: 'blur',\n target: lastFocusedKey\n });\n emitter.emit({\n type: 'focus',\n target: currentFocusedKey\n });\n }, [currentFocusedKey, emitter, navigation]);\n}","map":{"version":3,"names":["React","NavigationContext","useFocusEvents","state","emitter","navigation","useContext","lastFocusedKeyRef","useRef","undefined","currentFocusedKey","routes","index","key","useEffect","addListener","current","emit","type","target","lastFocusedKey","isFocused"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/core/src/useFocusEvents.tsx"],"sourcesContent":["import type { NavigationState } from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport { NavigationContext } from './NavigationContext';\nimport type { EventMapCore } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options<State extends NavigationState> = {\n state: State;\n emitter: NavigationEventEmitter<EventMapCore<State>>;\n};\n\n/**\n * Hook to take care of emitting `focus` and `blur` events.\n */\nexport function useFocusEvents<State extends NavigationState>({\n state,\n emitter,\n}: Options<State>) {\n const navigation = React.useContext(NavigationContext);\n const lastFocusedKeyRef = React.useRef<string | undefined>(undefined);\n\n const currentFocusedKey = state.routes[state.index].key;\n\n // When the parent screen changes its focus state, we also need to change child's focus\n // Coz the child screen can't be focused if the parent screen is out of focus\n React.useEffect(\n () =>\n navigation?.addListener('focus', () => {\n lastFocusedKeyRef.current = currentFocusedKey;\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }),\n [currentFocusedKey, emitter, navigation]\n );\n\n React.useEffect(\n () =>\n navigation?.addListener('blur', () => {\n lastFocusedKeyRef.current = undefined;\n emitter.emit({ type: 'blur', target: currentFocusedKey });\n }),\n [currentFocusedKey, emitter, navigation]\n );\n\n React.useEffect(() => {\n const lastFocusedKey = lastFocusedKeyRef.current;\n\n lastFocusedKeyRef.current = currentFocusedKey;\n\n // We wouldn't have `lastFocusedKey` on initial mount\n // Fire focus event for the current route on mount if there's no parent navigator\n if (lastFocusedKey === undefined && !navigation) {\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }\n\n // We should only emit events when the focused key changed and navigator is focused\n // When navigator is not focused, screens inside shouldn't receive focused status either\n if (\n lastFocusedKey === currentFocusedKey ||\n !(navigation ? navigation.isFocused() : true)\n ) {\n return;\n }\n\n if (lastFocusedKey === undefined) {\n // Only fire events after initial mount\n return;\n }\n\n emitter.emit({ type: 'blur', target: lastFocusedKey });\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }, [currentFocusedKey, emitter, navigation]);\n}\n"],"mappings":";;AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,iBAAiB;AAY1B,OAAO,SAASC,cAAcA,CAAgC;EAC5DC,KAAK;EACLC;AACc,CAAC,EAAE;EACjB,MAAMC,UAAU,GAAGL,KAAK,CAACM,UA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