UNPKG

react-native-reanimated

Version:

More powerful alternative to Animated library for React Native.

104 lines (97 loc) • 4 kB
'use strict'; import { isEdgeToEdge } from 'react-native-is-edge-to-edge'; import { logger } from "./common/index.js"; import { ReanimatedModule } from './ReanimatedModule'; import { SensorContainer } from "./SensorContainer.js"; export { startMapper, stopMapper } from './mappers'; export { makeMutable } from './mutables'; export const EDGE_TO_EDGE = /* @__PURE__ */isEdgeToEdge(); /** * @deprecated Please use the exported variable `reanimatedVersion` instead. * @returns `false` in Reanimated 4, `true` in Reanimated 3, doesn't exist in * Reanimated 2 or 1 */ export const isReanimated3 = () => { logger.warn('The `isReanimated3` function is deprecated. Please use the exported variable `reanimatedVersion` instead.'); return false; }; // Superseded by check in `/src/threads.ts`. // Used by `react-navigation` to detect if using Reanimated 2 or 3. /** * @deprecated Please use the exported variable `reanimatedVersion` instead. * @returns `false` in Reanimated 4, `true` in Reanimated 3, doesn't exist in * Reanimated 2 or 1 */ export const isConfigured = isReanimated3; export function getViewProp(viewTag, propName, component) { if (!component) { throw new Error('[Reanimated] Function `getViewProp` requires a component to be passed as an argument on Fabric.'); } // eslint-disable-next-line @typescript-eslint/no-misused-promises return new Promise((resolve, reject) => { return ReanimatedModule.getViewProp(viewTag, propName, component, result => { if (typeof result === 'string' && result.slice(0, 6) === 'error:') { // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors reject(result); } else { resolve(result); } }); }); } export function getSensorContainer() { if (!globalThis.__sensorContainer) { globalThis.__sensorContainer = new SensorContainer(); } return globalThis.__sensorContainer; } export function createEventHandlerWorklet(eventHandler) { return function handleEvent(_eventTimestamp, event) { 'worklet'; eventHandler(event); // We call mappers here to make sure view updates can be applied in the same frame after an event. globalThis.__mapperRun?.(); }; } export function unregisterEventHandler(id) { return ReanimatedModule.unregisterEventHandler(id); } export function createKeyboardEventHandlerWorklet(eventHandler) { // TODO: this should really go with the same code path as other events, that is // via registerEventHandler. For now we are copying the code from there. return function handleEvent(state, height) { 'worklet'; eventHandler(state, height); // We call mappers here to make sure view updates can be applied in the same frame after an event. globalThis.__mapperRun?.(); }; } export function unsubscribeFromKeyboardEvents(listenerId) { return ReanimatedModule.unsubscribeFromKeyboardEvents(listenerId); } export function isSensorAvailable(sensorType) { const sensorContainer = getSensorContainer(); return sensorContainer.isSensorAvailable(sensorType); } export function initializeSensor(sensorType, config) { const sensorContainer = getSensorContainer(); return sensorContainer.initializeSensor(sensorType, config); } export function unregisterSensor(sensorId) { const sensorContainer = getSensorContainer(); return sensorContainer.unregisterSensor(sensorId); } /** * @deprecated This function no longer has any effect in Reanimated and will be * removed in the future. */ export function enableLayoutAnimations(_flag, _isCallByUser = true) { logger.warn('`enableLayoutAnimations` is deprecated and will be removed in the future.'); } export function configureLayoutAnimationBatch(layoutAnimationsBatch) { ReanimatedModule.configureLayoutAnimationBatch(layoutAnimationsBatch); } export function setShouldAnimateExitingForTag(viewTag, shouldAnimate) { ReanimatedModule.setShouldAnimateExitingForTag(viewTag, shouldAnimate); } //# sourceMappingURL=coreCommon.js.map