Skip to content

Commit c80364e

Browse files
committed
Merged react-motion-gestures
2 parents 967d228 + 2b7543f commit c80364e

29 files changed

+1954
-16767
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/.pnp
66
.pnp.js
77

8+
89
# testing
910
/coverage
1011

@@ -21,3 +22,5 @@
2122
npm-debug.log*
2223
yarn-debug.log*
2324
yarn-error.log*
25+
package-lock.json
26+
.vscode

README.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# React Motion Router
1+
<p align="center">
2+
<img src="logo.png" />
3+
</p>
4+
5+
<h1 align="center">
6+
React Motion Router
7+
</h1>
28

39
Declarative routing library for React ⚛ with page transitions and animations 🚀. Under Development 🧪. Based on React Router and React Navigation.
410

5-
#### [Demo](https://router.nxtetechnologies.com)
11+
#### [Demo](https://router.nxtetechnologies.com)
612

713
# [![version](https://img.shields.io/npm/v/react-motion-router)](https://www.npmjs.com/package/react-motion-router) [![downloads](https://img.shields.io/npm/dm/react-motion-router)](https://www.npmjs.com/package/react-motion-router) [![license](https://img.shields.io/npm/l/react-motion-router)](https://github.com/nxtexe/react-motion-router/blob/main/LICENSE)
814

@@ -17,6 +23,7 @@ Declarative routing library for React ⚛ with page transitions and animations
1723
- [Transitions](#transitions)
1824
- [Shared Element Transition](#shared-element-transition)
1925
- [API Documentation](#api-documentation)
26+
- [Stack.Screen](#stackscreen)
2027
- [Router Config](#router-config)
2128
- [Animation Config](#animation-config)
2229
- [Shared Element Config](#sharedelementconfig)
@@ -33,7 +40,7 @@ npm install react-motion-router
3340

3441
#### Basic
3542

36-
Use the `Router` component to place your screens. Pass a React component to the component prop of `Stack.Screen` to be rendered when navigated to.
43+
Use the `Router` component to render your screens. Pass a React component to the component prop of `Stack.Screen` to be rendered when the path prop of the screen has been navigated to.
3744

3845
```
3946
...
@@ -103,11 +110,11 @@ All data passed to the navigate function is accessible on the target screen thro
103110

104111
#### Default Parameters
105112

106-
A default parameter can be passed to the screen by passing a value to the default_params prop on `Stack.Screen` component.
113+
A default parameter can be passed to the screen by passing a value to the defaultParams prop on `Stack.Screen` component.
107114

108115
```
109116
...
110-
<Stack.Screen path="/posts" component={Posts} default_params={{
117+
<Stack.Screen path="/posts" component={Posts} defaultParams={{
111118
post: {
112119
title: "Default Title"
113120
}
@@ -131,6 +138,27 @@ Transitions are a feature baked into react-motion-router; hence the name... To t
131138
</Router>
132139
```
133140

141+
You can subscribe to the transition progress by using the motion consumer component.
142+
143+
```
144+
import {Motion} from 'react-motion-router';
145+
146+
...
147+
<Motion.Consumer>
148+
{(progress) => {
149+
return (
150+
<div>{progress}</div>
151+
);
152+
}}
153+
</Motion.Consumer>
154+
155+
// OR Class.contextType
156+
157+
static contextType = Motion;
158+
```
159+
160+
The progress is updated as the animation plays and can be used to update DOM style attributes or control playback of an animation.
161+
134162
#### Shared Element Transition
135163

136164
To do a shared element transition wrap the component you would like shared between screens and supply it with a unique ID prop.
@@ -173,24 +201,34 @@ That's it! The element will transition from one screen to the next seemlessly. T
173201
This way the X and Y axis are animated independently and can alter the path of the shared element while transitioning.
174202

175203
## API Documentation
204+
#### Stack.Screen
205+
| Property | Type | Description |
206+
| ------ | ------ | ------ |
207+
| path | string | Pathname of the screen.|
208+
| animation | AnimationConfig | Config object used to modify the router's transition behaviour. In and out animation can also be set independently.|
209+
| component | any | A valid React Component to be rendered. |
210+
| defaultParams | Object | A dictionary of parameters that can be accessed by the rendered component. |
176211

177212
#### Router Config
178213

179214
Config object used to modify the behaviour of the Router.
180215
| Property | Type | Description |
181216
| ------ | ------ | ------ |
182-
| default_route | string | If the user navigates directly to a route other than the default and navigate.go_back() is called the app will navigate to the default route instead of closing. |
183-
| page_load_transition | boolean | Set to false if you wish to disable page transitions when the application first loads. |
184-
| animation | AnimationConfig | Config object used to modify the router's transition behaviour. |
217+
| defaultRoute | string | If the user navigates directly to a route other than the default and navigate.goBack() is called the app will navigate to the default route instead of leaving the website. |
218+
| pageLoadTransition | boolean | Set to false if you wish to disable page transitions when the application first loads. |
219+
| animation | AnimationConfig | Config object used to modify the router's global transition behaviour. In and out animation can also be set independently. |
220+
| swipeAreaWidth | number | Area in pixels from the left edge of the screen that gesture navigation can be triggered from. |
221+
| hysteresis | number | Percent from 0-100 which specifies minimum gesture progress before navigation is triggered. |
222+
| minFlingVelocity | number | Minimum average velocity of swipe gesture before navigation is triggered even if hysteresis was not reached. |
185223

186224
#### Animation Config
187225

188226
Config object used to modify the router's transition behaviour.
189227
| Property | Type | Description |
190228
| ------ | ------ | ------ |
191-
| type | "slide" or "fade" | The animation type used for page transitions. |
229+
| type | "slide", "fade", "zoom" or "none" | The animation type used for page transitions. |
192230
| duration | number | The time in milliseconds for how long page transitions are from start to end. |
193-
| direction | "left", "right", "up" or "down" | The direction used for slide transitions. The direction is swapped automatically on back navigation. i.e. The user presses their browser back button or navigation.go_back() is called. |
231+
| direction | "left", "right", "up", "down", "in" or "out" | The direction used for slide transitions. The direction is swapped automatically on back navigation. i.e. The user presses their browser back button or navigation.goBack() is called. |
194232

195233
#### Shared Element Transitions
196234

@@ -204,17 +242,17 @@ Config object used to modify the router's transition behaviour.
204242

205243
| Property | Type | Description |
206244
| ---------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
207-
| transform_origin | TransformOrigin | Changes transform alignment of shared element. |
245+
| transformOrigin | TransformOrigin | Changes transform alignment of shared element. |
208246
| duration | number | The time in milliseconds for how long the shared element transition is from start to end |
209-
| easing_function | CSS &lt;easing-function&gt; | Denotes a mathematical function that describes the rate at which a numerical value changes.<sup>[1](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function)</sup> |
247+
| easingFunction | CSS &lt;easing-function&gt; | Denotes a mathematical function that describes the rate at which a numerical value changes.<sup>[1](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function)</sup> |
210248

211249
It is useful to note that the duration and easing function properties can also be set on the X and Y axis as independent values by specifying an X or Y property on the shared element config object.
212250

213251
```
214252
...
215253
config={{
216254
x: {
217-
easing_function: "ease-in-out",
255+
easingFunction: "ease-in-out",
218256
duration: 500
219257
}
220258
}}

build.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import threading
33
import os
44
from progress.spinner import Spinner
5+
from datetime import datetime
56

67
def compile_func():
78
print("Creating an optimised build of React Motion Router ⚛\n")
@@ -66,7 +67,8 @@ def main():
6667
# load.join(5)
6768

6869
clear()
69-
print("Done!")
70+
end = datetime.now().strftime("%H:%M:%S")
71+
print(f"Done! {end}")
7072
exit(0)
7173

7274

example/src/App.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ function App() {
1212
return (
1313
<div className="App">
1414
<Router config={{
15-
default_route: '/',
16-
page_load_transition: false,
15+
defaultRoute: '/',
16+
pageLoadTransition: false,
1717
animation: {
18-
type: "zoom",
19-
duration: 300,
18+
type: "slide",
19+
direction: "right",
20+
duration: 350,
2021
}
2122
}}>
2223
<Stack.Screen
2324
path={'/slides'}
2425
component={Slides}
25-
default_params={{hero: 0}}
26+
defaultParams={{hero: 0}}
2627
/>
2728
<Stack.Screen
2829
path={'/cards'}
@@ -31,8 +32,7 @@ function App() {
3132
<Stack.Screen
3233
path={"/details"}
3334
component={Details}
34-
default_params={{data: "Default"}}
35-
35+
defaultParams={{data: "Default"}}
3636
/>
3737
<Stack.Screen
3838
path={"/"}
@@ -41,12 +41,12 @@ function App() {
4141
<Stack.Screen
4242
path={"/post"}
4343
component={Post}
44-
default_params={{data: "Default"}}
44+
defaultParams={{data: "Default"}}
4545
/>
4646
<Stack.Screen
4747
path={"/tiles"}
4848
component={Tiles}
49-
default_params={{params: "data"}}
49+
defaultParams={{params: "data"}}
5050
/>
5151
</Router>
5252
</div>

example/src/Components/Navbar.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import React from 'react';
22
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
33
import IconButton from '@mui/material/IconButton';
4+
import { SharedElement } from 'react-motion-router';
45
import '../css/Navbar.css';
56

67
interface NavbarProps {
78
title: string;
8-
on_back?: React.MouseEventHandler<HTMLButtonElement>;
9+
onBack?: React.MouseEventHandler<HTMLButtonElement>;
910
}
1011
export default function Navbar(props: NavbarProps) {
1112
return (
1213
<div className="navbar">
1314
<div className="back">
1415
{
15-
props.on_back ?
16-
<IconButton onClick={props.on_back}>
17-
<ChevronLeftIcon />
16+
props.onBack ?
17+
<IconButton onClick={props.onBack}>
18+
<SharedElement id="back">
19+
<ChevronLeftIcon />
20+
</SharedElement>
1821
</IconButton>
1922
:
2023
undefined

example/src/Screens/Cards.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function Cards(props: CardsProps) {
1616
return (
1717
<div className="cards">
1818
<SharedElement id="navbar">
19-
<Navbar title="Cards Demo" on_back={() => props.navigation.go_back()} />
19+
<Navbar title="Cards Demo" onBack={() => props.navigation.goBack()} />
2020
</SharedElement>
2121
<div className="card-list">
2222
{
@@ -25,6 +25,9 @@ export default function Cards(props: CardsProps) {
2525
<ButtonBase key={index} onClick={() => props.navigation.navigate('/details', {
2626
profile: hero
2727
})}>
28+
<SharedElement id={`${hero.id}-card-bg`}>
29+
<div className="card-bg"></div>
30+
</SharedElement>
2831
<Card sx={{ width: 345 }}>
2932
<SharedElement id={hero.id}>
3033
<CardMedia
@@ -38,7 +41,11 @@ export default function Cards(props: CardsProps) {
3841
<SharedElement id={`title-${hero.id}`}>
3942
<Typography gutterBottom variant="h5" component="h5">{hero.name}</Typography>
4043
</SharedElement>
41-
<p>{hero.description}</p>
44+
<SharedElement id={`description-${hero.id}`}>
45+
<p style={{
46+
fontSize: '16px'
47+
}}>{hero.description}</p>
48+
</SharedElement>
4249
</CardContent>
4350
</Card>
4451
</ButtonBase>

example/src/Screens/Details.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,35 @@ export default function Details(props: DetailsProps) {
1717
if (props.route.params.profile) {
1818
return (
1919
<div className="details" style={{width: "100%", height: "100%"}}>
20-
<IconButton style={{position: "absolute", color: 'white'}} onClick={() => {props.navigation.go_back()}}>
21-
<ClearIcon />
20+
<SharedElement id={`${props.route.params.profile.id}-card-bg`}>
21+
<div className="card-bg"></div>
22+
</SharedElement>
23+
<IconButton style={{
24+
position: "absolute",
25+
color: 'grey',
26+
zIndex: 10000
27+
}} onClick={() => {props.navigation.goBack()}}>
28+
<SharedElement id="back" config={{
29+
type: 'fade-through'
30+
}}>
31+
<ClearIcon />
32+
</SharedElement>
2233
</IconButton>
2334
<div className="profile-info">
24-
<SharedElement config={{
25-
transform_origin: 'bottom bottom',
26-
x: {
27-
duration: 300,
28-
easing_function: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)'
29-
},
30-
y: {
31-
duration: 250,
32-
easing_function: 'ease-out'
33-
}
34-
}} id={props.route.params.profile.id}>
35+
<SharedElement id={props.route.params.profile.id}>
3536
<img src={props.route.params.profile.photo} alt="profile-details" />
3637
</SharedElement>
3738
<div className="text-content">
38-
<SharedElement id={`title-${props.route.params.profile.id}`}>
39+
<SharedElement id={`title-${props.route.params.profile.id}`} config={{
40+
type: 'fade-through'
41+
}}>
3942
<h1>{props.route.params.profile.name}</h1>
4043
</SharedElement>
41-
<p>{props.route.params.profile.description}</p>
44+
<div className="description">
45+
<SharedElement id={`description-${props.route.params.profile.id}`}>
46+
<p>{props.route.params.profile.description}</p>
47+
</SharedElement>
48+
</div>
4249
</div>
4350
</div>
4451
</div>
@@ -47,7 +54,7 @@ export default function Details(props: DetailsProps) {
4754
return (
4855
<div className="details">
4956
<h1>Return Home</h1>
50-
<button onClick={() => {props.navigation.go_back()}}>Back</button>
57+
<button onClick={() => {props.navigation.goBack()}}>Back</button>
5158
</div>
5259
);
5360
}

example/src/Screens/Home.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ export default function Home(props: HomeProps) {
2626
onClick: () => props.navigation.navigate('/cards')
2727
}
2828
]
29+
2930
return (
3031
<div className="home">
31-
<SharedElement id="navbar">
32+
<SharedElement id="navbar" config={{
33+
type: 'fade'
34+
}}>
3235
<Navbar title="Shared Element Demo" />
3336
</SharedElement>
34-
<div className="list">
37+
<div className={`list`}>
3538
{
3639
list.map((item: ListItem, index: number) => {
3740
return <ListItemComponent

example/src/Screens/Post.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class Post extends React.Component<PostProps, {}> {
1515
if (this.props.route.params.post) {
1616
return (
1717
<div className="post">
18-
<button style={{position: "absolute"}} onClick={() => {this.props.navigation.go_back()}}>Back</button>
18+
<button style={{position: "absolute"}} onClick={() => {this.props.navigation.goBack()}}>Back</button>
1919
<div className="picture">
2020
<SharedElement id={this.props.route.params.post.id}>
2121
<img src={this.props.route.params.post.picture} alt="post" />

0 commit comments

Comments
 (0)