Convert Figma logo to code with AI

fram-x logoFluidTransitions

Fluid Transitions for React Navigation

2,932
194
2,932
75

Top Related Projects

A complete native navigation solution for React Native

React Native's Animated library reimplemented

Routing and navigation for your React Native apps

Experimental implementation of high performance interactable views in React Native

Declarative API exposing platform native touch and gesture system to React Native.

Quick Overview

FluidTransitions is a React Native library that provides fluid transitions between screens in navigation. It allows developers to create smooth, animated transitions between different views or screens in their mobile applications, enhancing the overall user experience.

Pros

  • Seamless and visually appealing transitions between screens
  • Easy integration with React Navigation
  • Customizable transition effects
  • Supports both iOS and Android platforms

Cons

  • May introduce performance overhead for complex transitions
  • Limited documentation and examples
  • Not actively maintained (last commit was in 2019)
  • Potential compatibility issues with newer versions of React Native

Code Examples

  1. Basic Screen Transition:
import { FluidNavigator } from 'react-navigation-fluid-transitions';

const Navigator = FluidNavigator({
  Screen1: { screen: Screen1 },
  Screen2: { screen: Screen2 },
});
  1. Custom Transition:
import { Transition } from 'react-navigation-fluid-transitions';

<Transition shared="image">
  <Image source={require('./image.jpg')} />
</Transition>
  1. Animated Values:
import { FluidTransitioned } from 'react-navigation-fluid-transitions';

<FluidTransitioned
  animated={['opacity', 'transform']}
  style={{ opacity: this.state.opacity }}
>
  <Text>Animated Text</Text>
</FluidTransitioned>

Getting Started

  1. Install the library:
npm install react-navigation-fluid-transitions
  1. Import and use in your React Native app:
import { FluidNavigator } from 'react-navigation-fluid-transitions';

const Navigator = FluidNavigator({
  Home: { screen: HomeScreen },
  Details: { screen: DetailsScreen },
});

export default class App extends React.Component {
  render() {
    return <Navigator />;
  }
}
  1. Add transitions to your components:
import { Transition } from 'react-navigation-fluid-transitions';

<Transition shared="hero">
  <Image source={require('./hero.jpg')} />
</Transition>

Competitor Comparisons

A complete native navigation solution for React Native

Pros of react-native-navigation

  • More comprehensive navigation solution with a wider range of features
  • Better performance due to native implementation
  • Larger community and more frequent updates

Cons of react-native-navigation

  • Steeper learning curve and more complex setup
  • Less flexibility for custom transitions and animations
  • Potential compatibility issues with some third-party libraries

Code Comparison

FluidTransitions:

<FluidNavigator>
  <Transition.Scene name="screen1" component={Screen1} />
  <Transition.Scene name="screen2" component={Screen2} />
</FluidNavigator>

react-native-navigation:

Navigation.setRoot({
  root: {
    stack: {
      children: [
        { component: { name: 'Screen1' } },
        { component: { name: 'Screen2' } }
      ]
    }
  }
});

FluidTransitions focuses on smooth transitions between screens, offering a simpler API for creating fluid animations. It's ideal for projects that prioritize custom transitions and ease of use.

react-native-navigation provides a more robust navigation solution with native performance, making it suitable for larger, complex applications. However, it requires more setup and may be overkill for simpler projects.

Choose FluidTransitions for custom animations and ease of use, or react-native-navigation for comprehensive navigation features and native performance in larger applications.

React Native's Animated library reimplemented

Pros of react-native-reanimated

  • More comprehensive animation library with a wider range of capabilities
  • Better performance for complex animations due to its native driver
  • Larger community and more frequent updates

Cons of react-native-reanimated

  • Steeper learning curve, especially for beginners
  • Requires additional setup and configuration
  • May be overkill for simple transitions

Code Comparison

FluidTransitions:

<Transition shared="avatar">
  <Image source={avatarSource} style={styles.avatar} />
</Transition>

react-native-reanimated:

import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';

const animation = useSharedValue(0);
const animatedStyle = useAnimatedStyle(() => {
  return { transform: [{ scale: withSpring(animation.value) }] };
});

FluidTransitions focuses on simplifying screen transitions, while react-native-reanimated offers a more powerful and flexible animation system. FluidTransitions is easier to use for basic transitions, but react-native-reanimated provides greater control and performance for complex animations. The choice between the two depends on the project's specific animation requirements and the developer's familiarity with animation concepts.

Routing and navigation for your React Native apps

Pros of react-navigation

  • More comprehensive navigation solution with support for various navigation patterns (stack, tab, drawer)
  • Larger community and ecosystem, resulting in better documentation and third-party integrations
  • Regular updates and maintenance, ensuring compatibility with the latest React Native versions

Cons of react-navigation

  • Steeper learning curve due to its extensive API and configuration options
  • Can be overkill for simple navigation requirements or small projects
  • Performance may be slightly impacted in complex navigation scenarios with many screens

Code Comparison

FluidTransitions:

<FluidNavigator>
  <Scene name="screen1" component={Screen1} />
  <Scene name="screen2" component={Screen2} />
</FluidNavigator>

react-navigation:

const Stack = createStackNavigator();

<NavigationContainer>
  <Stack.Navigator>
    <Stack.Screen name="Screen1" component={Screen1} />
    <Stack.Screen name="Screen2" component={Screen2} />
  </Stack.Navigator>
</NavigationContainer>

FluidTransitions focuses specifically on smooth transitions between screens, while react-navigation provides a more comprehensive navigation solution. FluidTransitions offers a simpler API for basic navigation needs, whereas react-navigation requires more setup but provides greater flexibility and features for complex navigation structures.

Experimental implementation of high performance interactable views in React Native

Pros of react-native-interactable

  • More focused on gesture-based interactions and animations
  • Provides a highly performant native driver for smooth animations
  • Offers a wide range of customizable gestures and behaviors

Cons of react-native-interactable

  • Less emphasis on screen transitions and navigation animations
  • Requires more setup and configuration for complex interactions
  • Limited to specific interaction types, less flexible for general transitions

Code Comparison

FluidTransitions:

<Transition shared="avatar">
  <Image source={avatarSource} style={styles.avatar} />
</Transition>

react-native-interactable:

<Interactable.View
  snapPoints={[{x: 0}, {x: 200}]}
  horizontalOnly={true}>
  <Image source={avatarSource} style={styles.avatar} />
</Interactable.View>

FluidTransitions focuses on declarative transitions between screens or components, while react-native-interactable emphasizes interactive, gesture-driven animations within a single view. FluidTransitions uses a simpler API for defining shared elements and transitions, whereas react-native-interactable requires more configuration for specific interaction behaviors.

Both libraries serve different purposes: FluidTransitions excels at screen transitions and navigation animations, while react-native-interactable shines in creating highly interactive and responsive UI elements within a single screen or component.

Declarative API exposing platform native touch and gesture system to React Native.

Pros of react-native-gesture-handler

  • More comprehensive gesture handling capabilities, including advanced touch interactions and custom gestures
  • Better performance due to native implementation of gesture recognition
  • Actively maintained with frequent updates and a large community

Cons of react-native-gesture-handler

  • Steeper learning curve, especially for complex gesture implementations
  • Requires additional setup and configuration compared to FluidTransitions
  • May introduce more complexity for simple transition animations

Code Comparison

FluidTransitions:

<Transition shared="avatar">
  <Image source={avatarSource} style={styles.avatar} />
</Transition>

react-native-gesture-handler:

<PanGestureHandler
  onGestureEvent={this._onPanGestureEvent}
  onHandlerStateChange={this._onPanHandlerStateChange}>
  <Animated.View style={animatedStyles}>
    <Image source={avatarSource} style={styles.avatar} />
  </Animated.View>
</PanGestureHandler>

While FluidTransitions focuses on simplifying transition animations between screens, react-native-gesture-handler provides more granular control over touch interactions and gestures. The code comparison shows that FluidTransitions requires less setup for basic transitions, while react-native-gesture-handler offers more flexibility for complex gesture-based animations at the cost of additional implementation complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Fluid Transitions for React Navigation

Introduction

This project aims to implement a simple yet powerful set of constructs for building fluid transitions between elements when navigating with React Navigation.

The library is JavaScript only - no linking required.

Snack

The library implements a new navigator component called FluidNavigator with the same interface and routing configuration as the StackNavigator. The library has a component called Transition which can be used to build different types of transitions that will automatically be run when navigating between screens using the regular navigation actions.

The Navigator's API is identical to the StackNavigator except that it does not support a header component. It can easily be integrated with redux and your existing navigation setups.

Medium article
React Native Animation Challenge #1

Installation

To install the library into your project, run yarn or npm:

yarn add react-navigation-fluid-transitions

or

npm i -S react-navigation-fluid-transitions

Compatible versions with react-navigation:

react-navigation-fluid-transitionsreact-navigation
0.3.x3.x
0.2.x2.x
0.1.x1.x

Future improvements and development will be on react-navigation-fluid-transitions@0.3.x.

Examples

Examples are included in the project and should be runnable from the root of the project folder.

To start the example run the following commands from the terminal:

npm i or yarn

To start the project run

react-native run-ios or react-native run-android

Shared Element Transitions

This example shows how two elements can be set up to automatically transition between each other when navigating between screens. A more detailed edition of this example can be found in the file SharedElements.js.

Note that a shared transition happens between two elements that looks the same. The library animates position and scale between the two hence using different styles and content between the two elements will result in strange transitions.

const Screen1 = (props) => (
  <View style={styles.container}>
    <Text>Screen 1</Text>
    <View style={styles.screen1}>
      <Transition shared='circle'>
        <View style={styles.circle}/>
      </Transition>
    </View>
    <Button
      title='Next'
      onPress={() => props.navigation.navigate('screen2')}
    />
  </View>
);

const Screen2 = (props) => (
  <View style={styles.container}>
    <Text>Screen 2</Text>
    <View style={styles.screen2}>
      <Transition shared='circle'>
        <View style={styles.circle2}/>
      </Transition>
    </View>
    <Button
      title='Back'
      onPress={() => props.navigation.goBack()}
    />
  </View>
);

const Navigator = createFluidNavigator({
  screen1: { screen: Screen1 },
  screen2: { screen: Screen2 },
});

Transitions

The library also supports transitions for elements wrapped in the Transition component. You can provide appear/disappear transitions that will be animated during navigation.

The Transition element supports appear and disappear transitions (appear will be used if disappear is not set), and these can either be one of the predefined transitions - or functions where you provide your own transitions.

<Transition appear='scale' disappear='bottom'>
  <View style={styles.circle}/>
</Transition>

Transition Types

NameDescription
scaleScales the element in and out
topTranslates the element in/out from the top of the screen
bottomTranslates the element in/out from the bottom of the screen
leftTranslates the element in/out from the left of the screen
rightTranslates the element in/out from the right of the screen
horizontalTranslates the element in/out from the left/right of the screen
verticalTranslates the element in/out from the top/bottom of the screen
flipFlips the element in/out

Custom transitions

It is easy to provide custom transitions - just add the transition function to your component's appear or disappear property. The following example creates a transition that will scale in from 88 times the original size of the wrapped component:

<Transition appear={myCustomTransitionFunction}>
  <View style={styles.circle}/>
</Transition>

myCustomTransitionFunction = (transitionInfo) => {
  const { progress, start, end } = transitionInfo;
  const scaleInterpolation = progress.interpolate({
    inputRange: [0, start, end, 1],
    outputRange: [88, 80, 1, 1],
  });
  return { transform: [{ scale: scaleInterpolation }] };
}

Read more about the parameters and functionality for building custom transitions.

Native driver support

For achieving the best experience it's vital to get rid of JS evaluation during animation run. React-native Animated API allows for scaling in both axis using native drivers, but it's not possible to resize width and height (which calls for a layout computation). Thus the native driver is used only when the ratio of source and target component are the same and it's recommended for the best quality of animations.

API

FluidNavigator

Transition

Credit

Some of the concepts in the library builds on ideas from @lintonye's pull request and suggestion found here: Shared element transition #941.

Contributors

Christian Falch (@chrfalch), Yuuki Arisawa (@uk-ar), Joe Goodall (@joegoodall1), sonaye, David Chavez, muhaimincs, KingTayTay, pedrobullo, Nathan James, Filip Engberg, DadImScared, fabriziogiordano, kelset, rewieer, Dan Alloway, Alexander Zizzo, Monica He, Avi Patel, Julian Hundeloh, Luong Dang Hai, Peter Henderson

Sponsors

Fram X - a cross platform app company from Norway.

NPM DownloadsLast 30 Days