UNPKG

react-native-reanimated

Version:

More powerful alternative to Animated library for React Native.

57 lines (49 loc) • 1.52 kB
'use strict'; import { logger } from "../logger.js"; export function processStyleValue(processor, value, context) { 'worklet'; // CSS strips whitespace around a declaration value, so processors can // assume they are given a trimmed string. const normalizedValue = typeof value === 'string' ? value.trim() : value; return processor(normalizedValue, context); } // Thrown errors carry the prefix that the logger adds on its own. const ERROR_PREFIX = '[Reanimated] '; export const WARN_MESSAGES = { ignoredValue(reason) { 'worklet'; return `${reason}\nThe value is ignored.`; } }; /** * Reports a style value that a processor rejected. The value is ignored like an * invalid CSS declaration instead of throwing, which on the UI runtime would * crash the app. */ export function warnIgnoredStyleValue(error) { 'worklet'; if (__DEV__) { const message = error instanceof Error ? error.message : String(error); const reason = message.replace(ERROR_PREFIX, ''); logger.warn(WARN_MESSAGES.ignoredValue(reason), { strict: true }); } } /** * Processes `props[key]` in place. A rejected value is removed, so the prop * keeps its current value. */ export function processStylePropInPlace(props, key, processor) { 'worklet'; if (props[key] === null) { return; } try { props[key] = processStyleValue(processor, props[key]); } catch (error) { warnIgnoredStyleValue(error); delete props[key]; } } //# sourceMappingURL=processStyleValue.js.map