CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-reanimated

More powerful alternative to Animated library for React Native with UI thread animations and advanced gesture handling.

Pending
Overview
Eval results
Files

configuration-utilities.mddocs/

Configuration and Utilities

Configuration functions, feature flags, property adapters, and utility functions for customizing and extending React Native Reanimated functionality.

Capabilities

Configuration Helpers

Functions for configuring Reanimated behavior and extending component properties.

/**
 * Adds properties to the whitelist for native props processing
 * @param props - Array of property names to whitelist
 */
function addWhitelistedNativeProps(props: string[]): void;

/**
 * Adds properties to the whitelist for UI props processing
 * @param props - Array of property names to whitelist
 */
function addWhitelistedUIProps(props: string[]): void;

/**
 * Configures the Reanimated logger settings
 * @param config - Logger configuration options
 */
function configureReanimatedLogger(config: LoggerConfig): void;

interface LoggerConfig {
  /** Severity level for logging */
  level?: 'debug' | 'info' | 'warn' | 'error';
  /** Whether to enable strict mode logging */
  strict?: boolean;
}

Usage Examples:

import { 
  addWhitelistedNativeProps, 
  addWhitelistedUIProps,
  configureReanimatedLogger 
} from "react-native-reanimated";

// Whitelist custom properties for native processing
addWhitelistedNativeProps(['customProperty', 'myNativeProp']);

// Whitelist properties for UI thread processing
addWhitelistedUIProps(['animatedValue', 'customAnimatedProp']);

// Configure logger
configureReanimatedLogger({
  level: 'warn',
  strict: true,
});

Feature Flags

System for managing experimental features and runtime capabilities.

/**
 * Gets a static feature flag value
 * @param flag - Feature flag name
 * @returns Feature flag value
 */
function getStaticFeatureFlag(flag: string): boolean | undefined;

/**
 * Sets a dynamic feature flag value
 * @param flag - Feature flag name
 * @param value - Feature flag value
 */
function setDynamicFeatureFlag(flag: string, value: boolean): void;

Usage Examples:

import { getStaticFeatureFlag, setDynamicFeatureFlag } from "react-native-reanimated";

// Check if a feature is enabled
const isNewAnimationEngineEnabled = getStaticFeatureFlag('NEW_ANIMATION_ENGINE');

if (isNewAnimationEngineEnabled) {
  // Use new animation features
  console.log('Using new animation engine');
}

// Enable experimental features
setDynamicFeatureFlag('EXPERIMENTAL_TRANSFORMS', true);
setDynamicFeatureFlag('BETA_LAYOUT_ANIMATIONS', false);

// Feature-gated functionality
const MyComponent = () => {
  const useBetaFeatures = getStaticFeatureFlag('BETA_FEATURES');
  
  const animatedStyle = useAnimatedStyle(() => {
    if (useBetaFeatures) {
      return { 
        transform: [{ experimental: 'enabled' }] 
      };
    }
    return { 
      transform: [{ scale: 1 }] 
    };
  });

  return <Animated.View style={animatedStyle} />;
};

Property Adapters

Functions for creating custom property adaptation logic.

/**
 * Creates an animated property adapter for custom prop handling
 * @param adapter - Adapter function for property transformation
 * @returns Property adapter for use with animated components
 */
function createAnimatedPropAdapter<T>(
  adapter: (props: T) => T
): AnimatedPropAdapter<T>;

type AnimatedPropAdapter<T> = (props: T) => T;

Usage Examples:

import { createAnimatedPropAdapter, useAnimatedProps } from "react-native-reanimated";

// Create a custom prop adapter
const colorAdapter = createAnimatedPropAdapter((props) => {
  // Transform color values for platform compatibility
  if (props.color && typeof props.color === 'string') {
    return {
      ...props,
      color: Platform.OS === 'android' ? props.color.toUpperCase() : props.color,
    };
  }
  return props;
});

// Custom component with adapter
const CustomAnimatedComponent = () => {
  const color = useSharedValue('red');
  
  const animatedProps = useAnimatedProps(() => ({
    color: color.value,
    customProp: `animated-${color.value}`,
  }), [], colorAdapter);

  return <Animated.View animatedProps={animatedProps} />;
};

// Multiple adapters for complex transformations
const multiAdapter = createAnimatedPropAdapter((props) => {
  // Apply multiple transformations
  let transformedProps = { ...props };
  
  // Normalize numeric values
  if (typeof transformedProps.opacity === 'string') {
    transformedProps.opacity = parseFloat(transformedProps.opacity);
  }
  
  // Apply platform-specific adjustments
  if (Platform.OS === 'ios' && transformedProps.shadowRadius) {
    transformedProps.shadowRadius *= 1.5; // iOS needs larger shadow radius
  }
  
  return transformedProps;
});

Version and Compatibility

Functions for checking Reanimated version and compatibility.

/**
 * Gets the current Reanimated JavaScript version
 */
const reanimatedVersion: string;

/**
 * Checks if the current version is Reanimated 3 or higher
 * @returns True if running Reanimated 3+
 */
function isReanimated3(): boolean;

/**
 * Checks if Reanimated is properly configured
 * @returns True if Reanimated is configured correctly
 */
function isConfigured(): boolean;

Usage Examples:

import { reanimatedVersion, isReanimated3, isConfigured } from "react-native-reanimated";

// Version checks
console.log('Reanimated version:', reanimatedVersion);

if (isReanimated3()) {
  console.log('Using Reanimated 3 features');
  // Use modern APIs
} else {
  console.log('Using legacy Reanimated APIs');
  // Fallback to older APIs
}

// Configuration validation
if (!isConfigured()) {
  console.error('Reanimated is not properly configured');
  throw new Error('Please check your Reanimated installation');
}

// Conditional feature usage
const MyComponent = () => {
  const canUseAdvancedFeatures = isReanimated3() && isConfigured();
  
  const animatedStyle = useAnimatedStyle(() => {
    if (canUseAdvancedFeatures) {
      return {
        transform: [{ perspective: 1000 }, { rotateX: '45deg' }],
      };
    }
    return {
      transform: [{ scale: 1.1 }],
    };
  });

  return <Animated.View style={animatedStyle} />;
};

Plugin Utilities

Functions for working with the Reanimated Babel plugin and development warnings.

/**
 * Gets a warning about improper shared value usage in styles
 * @param usageInfo - Information about the improper usage
 * @returns Warning message
 */
function getUseOfValueInStyleWarning(usageInfo: any): string;

Usage Examples:

import { getUseOfValueInStyleWarning } from "react-native-reanimated";

// Development helper for plugin warnings
const validateStyleUsage = (styleObject: any) => {
  if (__DEV__) {
    // Check for improper shared value usage
    const warning = getUseOfValueInStyleWarning(styleObject);
    if (warning) {
      console.warn(warning);
    }
  }
};

// Usage in component
const MyComponent = () => {
  const scale = useSharedValue(1);
  
  // This would trigger a warning in development
  const incorrectStyle = {
    transform: [{ scale: scale }], // Should be scale.value
  };
  
  if (__DEV__) {
    validateStyleUsage(incorrectStyle);
  }
  
  // Correct usage
  const animatedStyle = useAnimatedStyle(() => ({
    transform: [{ scale: scale.value }],
  }));

  return <Animated.View style={animatedStyle} />;
};

Types

Configuration Types

enum ReanimatedLogLevel {
  debug = 0,
  info = 1,
  warn = 2,
  error = 3,
}

interface LoggerConfig {
  level?: 'debug' | 'info' | 'warn' | 'error';
  strict?: boolean;
}

Feature Flag Types

type FeatureFlagName = string;
type FeatureFlagValue = boolean | undefined;

interface FeatureFlags {
  [key: string]: FeatureFlagValue;
}

Adapter Types

type AnimatedPropAdapter<T> = (props: T) => T;

interface AnimatedPropsAdapterWorklet<T = Record<string, unknown>> {
  (props: T): void;
}

type AnimatedPropsAdapterFunction<T = Record<string, unknown>> = 
  (props: T) => void;

Install with Tessl CLI

npx tessl i tessl/npm-react-native-reanimated

docs

animated-components.md

animation-functions.md

configuration-utilities.md

core-reactive-system.md

css-integration.md

event-handling.md

index.md

interpolation-easing.md

layout-animations.md

platform-functions.md

screen-transitions.md

testing-utilities.md

worklet-functions.md

tile.json