UNPKG

react-native-reanimated

Version:

More powerful alternative to Animated library for React Native.

123 lines (119 loc) 4.8 kB
import NativeReanimatedModule from './NativeReanimated'; import { nativeShouldBeMock, isWeb } from './PlatformChecker'; import { makeShareableCloneRecursive } from './shareables'; import { initializeUIRuntime } from './initializers'; import { SensorContainer } from './SensorContainer'; export { startMapper, stopMapper } from './mappers'; export { runOnJS, runOnUI } from './threads'; export { makeShareable } from './shareables'; export { makeMutable, makeRemote } from './mutables'; /** * @returns `true` in Reanimated 3, doesn't exist in Reanimated 2 or 1 */ export const isReanimated3 = () => true; // Superseded by check in `/src/threads.ts`. // Used by `react-navigation` to detect if using Reanimated 2 or 3. /** * @deprecated This function was superseded by other checks. * We keep it here for backward compatibility reasons. * If you need to check if you are using Reanimated 3 or Reanimated 2 * please use `isReanimated3` function instead. * @returns `true` in Reanimated 3, doesn't exist in Reanimated 2 */ export const isConfigured = isReanimated3; // this is for web implementation global._WORKLET = false; global._log = function (s) { console.log(s); }; export function getViewProp(viewTag, propName) { if (global._IS_FABRIC) { throw new Error('[react-native-reanimated] `getViewProp` is not supported on Fabric yet'); } return new Promise((resolve, reject) => { return NativeReanimatedModule.getViewProp(viewTag, propName, result => { if (typeof result === 'string' && result.substr(0, 6) === 'error:') { reject(result); } else { resolve(result); } }); }); } export function getSensorContainer() { if (!global.__sensorContainer) { global.__sensorContainer = new SensorContainer(); } return global.__sensorContainer; } export function registerEventHandler(eventHash, eventHandler) { function handleAndFlushAnimationFrame(eventTimestamp, event) { 'worklet'; global.__frameTimestamp = eventTimestamp; eventHandler(event); global.__flushAnimationFrame(eventTimestamp); global.__frameTimestamp = undefined; } return NativeReanimatedModule.registerEventHandler(eventHash, makeShareableCloneRecursive(handleAndFlushAnimationFrame)); } export function unregisterEventHandler(id) { return NativeReanimatedModule.unregisterEventHandler(id); } export function subscribeForKeyboardEvents(eventHandler, options) { // 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. function handleAndFlushAnimationFrame(state, height) { 'worklet'; const now = performance.now(); global.__frameTimestamp = now; eventHandler(state, height); global.__flushAnimationFrame(now); global.__frameTimestamp = undefined; } return NativeReanimatedModule.subscribeForKeyboardEvents(makeShareableCloneRecursive(handleAndFlushAnimationFrame), options.isStatusBarTranslucentAndroid ?? false); } export function unsubscribeFromKeyboardEvents(listenerId) { return NativeReanimatedModule.unsubscribeFromKeyboardEvents(listenerId); } export function registerSensor(sensorType, config, eventHandler) { const sensorContainer = getSensorContainer(); return sensorContainer.registerSensor(sensorType, config, makeShareableCloneRecursive(eventHandler)); } export function initializeSensor(sensorType, config) { const sensorContainer = getSensorContainer(); return sensorContainer.initializeSensor(sensorType, config); } export function unregisterSensor(sensorId) { const sensorContainer = getSensorContainer(); return sensorContainer.unregisterSensor(sensorId); } if (!isWeb()) { initializeUIRuntime(); } let featuresConfig = { enableLayoutAnimations: false, setByUser: false }; export function enableLayoutAnimations(flag) { let isCallByUser = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; if (isCallByUser) { featuresConfig = { enableLayoutAnimations: flag, setByUser: true }; NativeReanimatedModule.enableLayoutAnimations(flag); } else if (!featuresConfig.setByUser && featuresConfig.enableLayoutAnimations !== flag) { featuresConfig.enableLayoutAnimations = flag; NativeReanimatedModule.enableLayoutAnimations(flag); } } export function configureLayoutAnimations(viewTag, type, config) { let sharedTransitionTag = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; NativeReanimatedModule.configureLayoutAnimation(viewTag, type, sharedTransitionTag, makeShareableCloneRecursive(config)); } export function configureProps(uiProps, nativeProps) { if (!nativeShouldBeMock()) { NativeReanimatedModule.configureProps(uiProps, nativeProps); } } //# sourceMappingURL=core.js.map