-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Rewrite Layout Transition documentation page (#6144)
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
1 parent
6bc1c75
commit dae7a1e
Showing
16 changed files
with
787 additions
and
132 deletions.
There are no files selected for viewing
397 changes: 270 additions & 127 deletions
397
packages/docs-reanimated/docs/layout-animations/layout-transitions.mdx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
packages/docs-reanimated/src/examples/LayoutTransitions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+1.48 MB
packages/docs-reanimated/static/recordings/layout_transitions/android_curved_transition.mov
Binary file not shown.
Binary file added
BIN
+1.74 MB
...ges/docs-reanimated/static/recordings/layout_transitions/android_entryexit_transition.mov
Binary file not shown.
Binary file added
BIN
+2.5 MB
packages/docs-reanimated/static/recordings/layout_transitions/android_fading_transition.mov
Binary file not shown.
Binary file added
BIN
+1.64 MB
packages/docs-reanimated/static/recordings/layout_transitions/android_jumping_transition.mov
Binary file not shown.
Binary file added
BIN
+1.85 MB
packages/docs-reanimated/static/recordings/layout_transitions/android_linear_transition.mov
Binary file not shown.
Binary file added
BIN
+1.7 MB
...ges/docs-reanimated/static/recordings/layout_transitions/android_sequenced_transition.mov
Binary file not shown.
Binary file added
BIN
+1.73 MB
packages/docs-reanimated/static/recordings/layout_transitions/ios_curved_transition.mov
Binary file not shown.
Binary file added
BIN
+2.2 MB
packages/docs-reanimated/static/recordings/layout_transitions/ios_entryexit_transition.mov
Binary file not shown.
Binary file added
BIN
+2.44 MB
packages/docs-reanimated/static/recordings/layout_transitions/ios_fading_transition.mov
Binary file not shown.
Binary file added
BIN
+1.98 MB
packages/docs-reanimated/static/recordings/layout_transitions/ios_jumping_transition.mov
Binary file not shown.
Binary file added
BIN
+2.21 MB
packages/docs-reanimated/static/recordings/layout_transitions/ios_linear_transition.mov
Binary file not shown.
Binary file added
BIN
+2.5 MB
packages/docs-reanimated/static/recordings/layout_transitions/ios_sequenced_transition.mov
Binary file not shown.
Oops, something went wrong.