• This repository has been archived on 02/Dec/2021
  • Stars
    star
    973
  • Rank 47,051 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create magical move transitions between scenes in react-native 🐰🎩✨

Important react-native-shared-element update!

A follow up project called react-native-shared-element has been created which can be considered the successor to react-native-magic-move. It it an all native solution that provides superior performance (no more passes over the react-native bridge) and transitions. It however does not support some of the more exotic transition types (flip, shrinkAndGrow) that Magic Move does. It also doesn't support the web-platform yet and requires native extensions to run. New users are advised to use react-native-shared-element when possible. As for Magic Move, no more new developments will be started for Magic Move, merely critical bug-fixes. This notification will be updated as development on react-native-shared-element progresses.

react-native-magic-move

Create magical move transitions between scenes in react-native 🐰🎩✨

Try it with Expo

MagicMoveGif

Usage

Installation

$ yarn add react-native-magic-move

Link the native extensions (* recommended but not required)

$ react-native link react-native-magic-move 

* The native extensions are recommended to get the best performance, but they are not required. This makes it possible to use react-native-magic-move with expo or react-native-web. If you're having trouble installing the native extensions, please see this guide on how to install them manually.

Wrap your app with the <MagicMove.Provider> context.

import * as MagicMove from 'react-native-magic-move';

const App = () => (
  <MagicMove.Provider>
    {...}
  </MagicMove.Provider>
);

Add the <MagicMove.{View|Image|Text}> component to your views. Whenever the Magic Move component is mounted while another Magic Move component with the same id is already mounted, then a magic transition between the components is performed.

import * as MagicMove from 'react-native-magic-move';

const Scene1 = () => (
  <MagicMove.Scene>
    <MagicMove.View id="logo" style={{
        width: 100,
        height: 100,
        backgroundColor: "green",
        borderRadius: 50
      }} />
  </MagicMove.Scene>
);

const Scene2 = () => (
  <MagicMove.Scene>
    <MagicMove.View id="logo" style={{
        width: 200,
        height: 200,
        backgroundColor: "purple",
        borderRadius: 0
      }} />
  </MagicMove.Scene>
);

react-navigation

When you are using react-navigation (or react-native-router-flux), then also install the following binding:

Documentation

Components

The following magic-move components are supported out of the box.

  • MagicMove.View
  • MagicMove.Text
  • MagicMove.Image

You can also create your own custom MagicMove components.

const MyMagicMoveComponent = MagicMove.createMagicMoveComponent(MyComponent);

// When creating a custom image component (e.g. FastImage) also specify the `image` attribute
// so that the `move` transition treats this as an image.
const MagicMoveFastImage = MagicMove.createMagicMoveComponent(FastImage, {ComponentType: 'image'});

// Full signature
/* MagicMove.createMagicMoveComponent(Component, {
  AnimatedComponent,
  ComponentType,
  ...props
});*/

Props

Property Type Default Description
id string (required) Unique id of the magic-move instance
transition function MagicMove.Transition.move Transition effect, see below
duration number 400 Length of the animation (milliseconds)
delay number 0 Amount of msec to wait before starting the animation
easing function Easing.inOut(Easing.ease) Easing function to define the curve
disabled bool false Disables transitions to this component
zIndex number 0 Z-index to control the drawing order of the rendered animation. A component with a greater z-index is always drawn in front of a component with a lower z-index.
useNativeDriver boolean true Use the native-driver
debug boolean false Enables debug-mode to analyze animations
useNativeClone boolean Use this prop to disable native clone optimisations for this component (when applicable).
imageSizeHint {width: number, height: number} Optional size of the image that may be provided as a hint to the transition function

Transitions

The following transition functions are available out of the box.

Transition Description
MagicMove.Transition.move (default) Moves the component while adjusting for border-radii and size. Takes the image resizeMode into account to create a seamless image transition without any stretching.
MagicMove.Transition.morph Morphs the shape, size and colours of the target to look like the source
MagicMove.Transition.dissolve Cross fade the source into the target
MagicMove.Transition.flip Flip the source to reveal the target on the backside (auto choose axis)
MagicMove.Transition.flip.x Flip the source to reveal the target on the backside (over x-axis)
MagicMove.Transition.flip.y Flip the source to reveal the target on the backside (over y-axis)
MagicMove.Transition.flip.xy Flip the source to reveal the target on the backside (over x- and y-axes)
MagicMove.Transition.shrinkAndGrow Shrink and let the source disappear while letting the target appear and grow
MagicMove.Transition.squashAndStretch Scale the target to the size of the source and squash and stretch to give it the illusion of momentum and mass

You can also create your own transition functions, see src/transitions for examples.

Scenes

Use <MagicMove.Scene> to mark the start of a scene within the rendering hierarchy. This is important so that Magic Move can correctly assess the destination-position of an animation. MagicMove.Scene is implemented using a regular View and supports all its properties.

Property Type Default Description
disabled bool false Disable transitions to this scene.
active bool This special prop is intended for integrating magic-move with 3rd party navigators such as react-navigation. Do not use it unless you know what you are doing. By setting it to true or false the navigation package can control which scene is active and which is no longer active. See react-navigation-magic-move for an example on how to use it.
debug boolean false Enables debug-mode to analyze animations
onWillAppear function Callback that is called when the scene is about to appear
onWillDisappear function Callback that is called when the scene is about to disappear

Context

When a magic-move is performend, a temporary clone of the source and/or target component is rendered onto the screen. Now imagine you have some animations that run when your component is mounted (e.g. Animatable.View), that would also mean these animations are run on the cloned component. This is probably not what you want and you might want to hide those components entirely in the cloned component. To do so you can use the <MagicMove.Context> API. It allows you to detect whether the component is rendered as a clone and whether it is the source or target of a magic move animation.

Example

<MagicMove.View>
  <MagicMove.Context>
    {({isClone, isTarget}) => (
      <Animatable.View animation={isClone ? undefined : 'zoomIn'} />
    )}
  </MagicMove.Context>
</MagicMove.View>

Resources

React Europe Talk

react-native-magic-move-presentation

react-navigation-magic-move

examples/expo/src

Disclaimer 🐰🎩

Magic-move creates the illusion of transitioning/morphing components from one scene to another. It however doesn't actually move components to different scenes. As with real magic tricks, there will be situations where the illusion will not work for you. And as with magic tricks, you may need to "set the stage" (e.g. change some stuff in your app) to create the transition that you want. So now that you've received this reality check βœ…, go forth and create some bad-ass illusions.

License

MIT

Cool?

Do you think this cool and useful? Consider buying me a coffee!
Buy Me A Coffee

More Repositories

1

react-native-shared-element

Native shared element transition "primitives" for react-native πŸ’«
TypeScript
2,190
star
2

react-native-bundle-visualizer

See what packages are increasing your react-native bundle size πŸ“¦
TypeScript
1,466
star
3

react-navigation-shared-element

React Navigation bindings for react-native-shared-element πŸ’«
TypeScript
1,266
star
4

autolayout.js

Apple's Auto Layout and Visual Format Language for javascript (using cassowary constraints)
JavaScript
1,034
star
5

firestorter

Use Google Firestore in React with zero effort, using MobX 🀘
TypeScript
378
star
6

famous-flex

Animatable layouts, FlexScrollView & widgets for famo.us.
JavaScript
279
star
7

kiwi.js

Fast TypeScript implementation of the Cassowary constraint solving algorithm πŸ––
JavaScript
250
star
8

react-navigation-magic-move

Bindings for using react-navigation with react-native-magic-move 🐰🎩✨
JavaScript
135
star
9

react-tag-cloud

Create beautiful tag/word clouds using React ☁️
TypeScript
118
star
10

famous-map

Map integration for famo.us (Google Maps, Leaflet, Open Layers 3 & Mapbox GL)
JavaScript
109
star
11

visualformat-editor

Editor & previewer for Apple's Visual Format Language (built with autolayout.js)
JavaScript
90
star
12

node-web-bluetooth

Web Bluetooth API and interactive device picker for node.js
JavaScript
75
star
13

react-navigation-shared-element-demo

A simple app that demonstrates how to use react-navigation-shared-element in react-native
JavaScript
65
star
14

famous-autolayout

Apple's Auto Layout and Visual Format language for famo.us
JavaScript
55
star
15

famous-flex-chat

Chat-demo for famo.us using true-size chat bubbles, snap to bottom, sticky headers & pull-to-refresh
JavaScript
52
star
16

pnglib-es6

Create png images in pure javascript (modern & fast ES6 version using typed Arrays)
JavaScript
45
star
17

famous-boxlayout

Layout-view for quickly setting margins or creating flexible layouts
JavaScript
28
star
18

famous-animatedIcon

Material design'ish button-animation using famo.us
JavaScript
27
star
19

famous-flex-datepicker

Date/time picker demo for famo.us
JavaScript
26
star
20

rtfToHtml

Parse RTF and write output as an HTML file (written specifically for InDesign generated RTF, but works for any source)
JavaScript
21
star
21

android-tv-browser-autolaunch

Android TV App (react-native) that auto-launches on boot and shows a browser with a hard-coded URL
Objective-C
20
star
22

famous-sizeconstraint

SizeConstraint makes it possible to set the scale, padding, max-size, min-size and aspect-ratio for famo.us renderables
JavaScript
20
star
23

famous-kenburnscontainer

Famo.us view for performing ken-burns style zooming and panning
JavaScript
19
star
24

famous-listview

famous-listview extends famo.us ScrollContainer with insert/remove animations, selection (single/multiple) and support for a placeholder.
JavaScript
18
star
25

famous-lagometer

Lagometer for famo.us showing the FPS, animation-frames times and script times
JavaScript
18
star
26

famous-bkimagesurface

Drop-in replacement for ImageSurface supporting AspectFit & AspectFill
JavaScript
18
star
27

famous-flex-tabbar

TabBar widget demo for famo.us
JavaScript
18
star
28

famous-flex-tabbarcontroller

TabBarController widget demo for famo.us
JavaScript
17
star
29

famous-white-tile-firebase

Popular white tile (piano tiles) game implemention using famo.us and firebase
JavaScript
17
star
30

famous-refresh-loader

Spinning pull to refresh loader for famo.us
JavaScript
15
star
31

famous-autosizetextarea

Auto-sizing TextareaSurface for famo.us
JavaScript
14
star
32

famous-components

Overview of famo.us components
14
star
33

famous-flex-demo

Demo for showcasing famous-flex layout technology
JavaScript
9
star
34

react-native-magic-move-presentation

Presentation App/Slides for the react-native-magic-move presentation given at ReactEurope 2019
JavaScript
9
star
35

react-native-clipped

Clipping effects and animations for react-native 🍠πŸ₯’πŸ•
JavaScript
7
star
36

famous-flex-tablelayout

iOS inspired table-layout for famo.us
JavaScript
7
star
37

expo-firebase-demo

Firebase Demo running on Expo
TypeScript
6
star
38

famous-white-tile

Popular white tile (piano tiles) game implemention using famo.us
JavaScript
5
star
39

famous-autofontsizesurface

Surface that automatically scales the font-size based on the content.
JavaScript
5
star
40

famous-flex-animationcontroller

Animating from one famo.us view to another in awesome ways
JavaScript
5
star
41

ttvflash

TTV Flash Presentatie App
JavaScript
4
star
42

famous-Starterkit

Starterkit for famo.us (app + web) containing examples, instructions & best practises
JavaScript
4
star
43

famous-resizableImage

Resizable image for famo.us
JavaScript
4
star
44

top2000-stemlijst

Importeer jouw Top 2000 stemlijst eenvoudig naar Spotify, Apple Music of Deezer
TypeScript
4
star
45

firestore-cms

A free, flexible and easy to use CMS for Google Firestore πŸŽ‰
JavaScript
4
star
46

famous-sizemodifier

Deprecated - Use famous-sizeconstraint instead
JavaScript
3
star
47

famous-resources

Unofficial list of famo.us resources
2
star
48

expo-git-import-main

TypeScript
2
star
49

wkwebview-crash

Project to intentionally crash WkWebView for testing purposes
Objective-C
2
star
50

famous-lib-tester

Project for testing whether my libraries and famo.us can be build successfully using webpack, browserify, etc...
JavaScript
1
star
51

famous-test-positionabsolute

Test for absolute positioning issue when showing keyboard on mobile (iOS & android)
JavaScript
1
star
52

expo-av-9596-repro

JavaScript
1
star
53

famous-zindex

JavaScript
1
star
54

famous-bling

View templates (with animations) to jumpstart your project or for production use
JavaScript
1
star
55

famous-flex-scrollview-linking

Demo for showcasing FlexScrollView leading & trailing scrollview linking
1
star
56

ijzerenhein-website

My personal public website
JavaScript
1
star
57

famous-physics-playground

Playground for experimenting with physics based animation effects
JavaScript
1
star
58

contributors-code

Life as an open source contributor
1
star
59

expo-av-music-control

Java
1
star
60

famous-flex-truesize-layoutcontroller-demo

JavaScript
1
star
61

scrollview.js

Lightweight & fast javascript scrollview, look no further
JavaScript
1
star
62

famous-playground

General purpose playground repo for famo.us
JavaScript
1
star