Skip to content

Commit

Permalink
docs: Rewrite Layout Transition documentation page (#6144)
Browse files Browse the repository at this point in the history
To be up to date we rewritten [Layout
Transition](https://docs.swmansion.com/react-native-reanimated/docs/layout-animations/layout-transitions),
implemented InteractiveExample with selectable transition and added new,
refreshed videos.


- [x] Jumping, Curved and Entry/Exit Transition are available on web

- [x] This needs latest react-native-reanimated@nightly

- [x] It includes new updated Fading default `duration` from this
[PR](#6174).

- [x] check default duration in transitions




Before:



https://github.com/software-mansion/react-native-reanimated/assets/59940332/9d845bcf-776c-4514-aa99-c825fb4ceef6


After:


https://github.com/software-mansion/react-native-reanimated/assets/59940332/1e721176-273f-4740-b0a5-27f69f4a6140


How interactivExample works:


https://github.com/software-mansion/react-native-reanimated/assets/59940332/cbe09f76-9579-4b13-9c4d-cbbd23911934
  • Loading branch information
patrycjakalinska authored Jul 24, 2024
1 parent 6bc1c75 commit dae7a1e
Show file tree
Hide file tree
Showing 16 changed files with 787 additions and 132 deletions.
397 changes: 270 additions & 127 deletions packages/docs-reanimated/docs/layout-animations/layout-transitions.mdx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/docs-reanimated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"react-draggable": "^4.4.5",
"react-native": "^0.71.4",
"react-native-gesture-handler": "^2.16.2",
"react-native-reanimated": "^3.15.0-nightly-20240715-16047317c",
"react-native-reanimated": "^3.15.0-nightly-20240722-a15e0edec",
"react-native-svg": "^13.14.0",
"react-native-web": "^0.18.12",
"source-map": "^0.7.4",
Expand Down
207 changes: 207 additions & 0 deletions packages/docs-reanimated/src/examples/LayoutTransitions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import React, { useState, useRef, Dispatch } from 'react';
import {
View,
Text,
SafeAreaView,
StyleSheet,
TouchableOpacity,
} from 'react-native';
import Animated, {
LinearTransition,
SequencedTransition,
FadingTransition,
FadeOut,
JumpingTransition,
CurvedTransition,
EntryExitTransition,
FlipOutYLeft,
FlipInEasyY,
Easing,
} from 'react-native-reanimated';
import { FormControl, MenuItem, Select } from '@mui/material';

const INITIAL_LIST = [
{ id: 1, emoji: '🍌', color: '#b58df1' },
{ id: 2, emoji: '🍎', color: '#ffe780' },
{ id: 3, emoji: '🥛', color: '#fa7f7c' },
{ id: 4, emoji: '🍙', color: '#82cab2' },
{ id: 5, emoji: '🍇', color: '#fa7f7c' },
{ id: 6, emoji: '🍕', color: '#b58df1' },
{ id: 7, emoji: '🍔', color: '#ffe780' },
{ id: 8, emoji: '🍟', color: '#b58df1' },
{ id: 9, emoji: '🍩', color: '#82cab2' },
];

interface TRANSITION {
label: string;
value: any;
}

const LAYOUT_TRANSITIONS = [
{ label: 'Linear Transition', value: LinearTransition },
{ label: 'Sequenced Transition', value: SequencedTransition },
{ label: 'Fading Transition', value: FadingTransition },
{ label: 'Jumping Transition', value: JumpingTransition },
{
label: 'Curved Transition',
value: CurvedTransition.easingX(Easing.sin).easingY(Easing.exp),
},
{
label: 'Entry/Exit Transition',
value: EntryExitTransition.entering(FlipInEasyY).exiting(FlipOutYLeft),
},
];

interface SelectProps {
value: string;
onChange: any;
options: TRANSITION[];
disabled?: boolean;
disabledOptions?: string[];
}

const SelectStyling = {
fontSize: 14,
color: 'text.secondary',
backgroundColor: 'background.default',
borderRadius: 0,
'& fieldset': {
borderColor: 'text.secondary',
},
};

export function SelectOption({
value,
onChange,
options,
disabled,
disabledOptions,
}: SelectProps) {
return (
<View style={{ width: '30%' }}>
<FormControl sx={{ minWidth: 85 }} size="small">
<Select
value={value}
sx={SelectStyling}
onChange={(e) => onChange(e.target)}
disabled={disabled}>
{options.map((option) => (
<MenuItem
key={option.label}
value={option.value}
disabled={disabledOptions?.includes(option.label)}
sx={{ color: 'text.secondary' }}>
{option.label}
</MenuItem>
))}
</Select>
</FormControl>
</View>
);
}

export default function App() {
const [items, setItems] = useState(INITIAL_LIST);
const [selected, setSelected] = useState(LAYOUT_TRANSITIONS[0]);

const removeItem = (idToRemove) => {
const updatedItems = items.filter((item) => item.id !== idToRemove);
setItems(updatedItems);
};

const onSelect = (item) => {
setSelected(item);
setItems(INITIAL_LIST);
};

return (
<SafeAreaView style={styles.container}>
<View style={styles.dropdownContainer}>
<SelectOption
value={selected.value}
onChange={onSelect}
options={LAYOUT_TRANSITIONS}
/>
</View>
<View>
<Items selected={selected} items={items} onRemove={removeItem} />
</View>
</SafeAreaView>
);
}

function Items({ selected, items, onRemove }) {
return (
<View style={styles.gridContainer}>
{items.map((item) => (
<Animated.View
key={item.id}
layout={selected.value}
exiting={FadeOut}
style={[styles.tileContainer, { backgroundColor: item.color }]}>
<Tile emoji={item.emoji} onRemove={() => onRemove(item.id)} />
</Animated.View>
))}
</View>
);
}

function Tile({ emoji, onRemove }) {
return (
<TouchableOpacity onPress={onRemove} style={styles.tile}>
<Animated.Text style={styles.tileLabel}>{emoji}</Animated.Text>
</TouchableOpacity>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
padding: 32,
width: 'auto',
display: 'flex',
minHeight: 300,
},
gridContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start',
justifyContent: 'center',
paddingHorizontal: 32,
},
dropdownContainer: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
marginBottom: 16,
},
tileContainer: {
width: '20%',
margin: '1%',
borderRadius: 16,
minHeight: 80,
justifyContent: 'center',
alignItems: 'center',
},
tile: {
flex: 1,
height: '100%',
width: ' 100%',
justifyContent: 'center',
alignItems: 'center',
},
tileLabel: {
color: '#f8f9ff',
fontSize: 24,
},
wrapper: {
width: '100%',
position: 'absolute',
display: 'flex',
alignItems: 'center',
},
animatedView: {
width: '100%',
overflow: 'hidden',
},
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit dae7a1e

Please sign in to comment.