-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add AnimatedFAB improvements #2907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lukewalczak
merged 52 commits into
callstack:main
from
Drakeoon:feat/animated-extended-fab-improvements
Nov 3, 2021
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
6365c2c
feat: introduce first iteration of AnimatedFAB component
lukewalczak ca0617d
refactor: remove useless code
lukewalczak b05e782
refactor: don't move fab when switching animation direction prop
lukewalczak c397460
refactor: interpolate animation on fab text
lukewalczak f0ae001
refactor: code and example clean up
lukewalczak 554e79a
refactor: use one animated value
lukewalczak 0049b6d
feat: configure shadow for Android
lukewalczak 396e775
refactor: introduce isIOS
lukewalczak fb69d42
refactor: fixes after merge
lukewalczak 06414ee
refactor: adjust android example
lukewalczak 9f77407
refactor: small changes
lukewalczak 4e99ffd
fix: add support for animateFor: left property
Drakeoon 7adecfc
test: add snapshot tests for AnimatedFAB component
Drakeoon 20b5913
test: add snapshot tests for new properties
Drakeoon c84999c
feat: tweak example to match MD docs
Drakeoon 7c7cc82
feat: improve AnimatedFAB example for iOS
Drakeoon c0de872
feat: improve AnimateFAB visuals
Drakeoon 684c918
feat: improve example to showcase animateFrom prop
Drakeoon 3221e19
feat: add support for RTL and fix animateFrom prop
Drakeoon 77db8d4
fix: align iOS behavior for AnimatedFAB example
Drakeoon 20e1481
feat: improve AnimatedFAB example
Drakeoon 67e1ef5
feat: implement consistent styles with a dirty approach
Drakeoon d241783
chore: refactor innerWrapper styles
Drakeoon f2030fc
chore: refactor icon styles
Drakeoon 3ebb9e6
chore: refactor reversed properties for direction
Drakeoon 7cff972
chore: refactor remaining transforms
Drakeoon acaa3d2
fix: improve shadow behavior
Drakeoon b0a45f3
feat: add config controls to AnimatedFABExample
Drakeoon 24f8aeb
refactor: split AnimatedFABExample into separete files
Drakeoon 033d87a
refactor: improve FlatList performance
Drakeoon ccb2383
refactor: extract controls to separate component
Drakeoon ac234a9
feat: introduce first iteration of AnimatedFAB component
lukewalczak 2404d9b
refactor: remove useless code
lukewalczak 0aa14fc
refactor: don't move fab when switching animation direction prop
lukewalczak dd61dc7
refactor: interpolate animation on fab text
lukewalczak e7047e0
refactor: code and example clean up
lukewalczak 1f585a9
refactor: use one animated value
lukewalczak 1f7f13b
feat: configure shadow for Android
lukewalczak 0069512
refactor: introduce isIOS
lukewalczak 73a71fc
refactor: fixes after merge
lukewalczak f01ca7d
refactor: adjust android example
lukewalczak a573c04
refactor: small changes
lukewalczak 5af9ef8
Merge branch 'feat/animated-extended-fab' of github.com:callstack/rea…
Drakeoon fcaefef
feat: hide AnimatedFab for production
lukewalczak 39f8ede
Merge branch 'feat/animated-extended-fab' of github.com:callstack/rea…
Drakeoon ceb03cb
refactor: apply small feedback notes
Drakeoon f240cff
Merge branch 'main' into feat/animated-extended-fab-improvements
Drakeoon c897aa0
refactor: apply small feedback notes
Drakeoon 7aa93e7
refactor: move dynamic styles to a separate utils file
Drakeoon 6a56b0d
refactor: move AnimatedFAB files to a separate folder
Drakeoon c968eda
refactor: export missing types from the package
Drakeoon d05dc7b
chore: enable AnimateFAB in production
Drakeoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,66 @@ | ||
| import React from 'react'; | ||
| import { | ||
| StyleProp, | ||
| ViewStyle, | ||
| Animated, | ||
| StyleSheet, | ||
| Platform, | ||
| } from 'react-native'; | ||
| import { AnimatedFAB } from 'react-native-paper'; | ||
|
|
||
| type CustomFABProps = { | ||
| animatedValue: Animated.Value; | ||
| visible: boolean; | ||
| extended: boolean; | ||
| label: string; | ||
| animateFrom: 'left' | 'right'; | ||
| iconMode?: 'static' | 'dynamic'; | ||
| style?: StyleProp<ViewStyle>; | ||
| }; | ||
|
|
||
| const CustomFAB = ({ | ||
| animatedValue, | ||
| visible, | ||
| extended, | ||
| label, | ||
| animateFrom, | ||
| style, | ||
| iconMode, | ||
| }: CustomFABProps) => { | ||
| const [isExtended, setIsExtended] = React.useState(true); | ||
|
|
||
| const isIOS = Platform.OS === 'ios'; | ||
|
|
||
| React.useEffect(() => { | ||
| if (!isIOS) { | ||
| animatedValue.addListener(({ value }: { value: number }) => { | ||
| setIsExtended(value <= 0); | ||
| }); | ||
| } else setIsExtended(extended); | ||
| }, [animatedValue, extended, isIOS]); | ||
|
|
||
| const fabStyle = { [animateFrom]: 16 }; | ||
|
|
||
| return ( | ||
| <AnimatedFAB | ||
| icon={'plus'} | ||
| label={label} | ||
| extended={isExtended} | ||
| uppercase={true} | ||
| onPress={() => console.log('Pressed')} | ||
| visible={visible} | ||
| animateFrom={animateFrom} | ||
| iconMode={iconMode} | ||
| style={[styles.fabStyle, style, fabStyle]} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default CustomFAB; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| fabStyle: { | ||
| bottom: 16, | ||
| position: 'absolute', | ||
| }, | ||
| }); |
126 changes: 126 additions & 0 deletions
126
example/src/Examples/AnimatedFABExample/CustomFABControls.tsx
This file contains hidden or 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,126 @@ | ||
| import React from 'react'; | ||
| import { StyleSheet, View, FlatList } from 'react-native'; | ||
| import { Colors, Paragraph, RadioButton } from 'react-native-paper'; | ||
| import type { | ||
| AnimatedFABAnimateFrom, | ||
| AnimatedFABIconMode, | ||
| } from 'react-native-paper'; | ||
|
|
||
| export type Controls = { | ||
| iconMode: AnimatedFABIconMode; | ||
| animateFrom: AnimatedFABAnimateFrom; | ||
| }; | ||
|
|
||
| export const initialControls: Controls = { | ||
| iconMode: 'static', | ||
| animateFrom: 'right', | ||
| }; | ||
|
|
||
| type Props = { | ||
| controls: Controls; | ||
| setControls(controls: React.SetStateAction<Controls>): void; | ||
| }; | ||
|
|
||
| type ControlValue = AnimatedFABIconMode | AnimatedFABAnimateFrom; | ||
|
|
||
| type CustomControlProps = { | ||
| name: string; | ||
| options: ControlValue[]; | ||
| value: ControlValue; | ||
| onChange(newValue: ControlValue): void; | ||
| }; | ||
|
|
||
| const CustomControl = ({ | ||
| name, | ||
| options, | ||
| value, | ||
| onChange, | ||
| }: CustomControlProps) => { | ||
| const _renderItem = React.useCallback( | ||
| ({ item }) => ( | ||
| <View style={styles.controlItem}> | ||
| <Paragraph>{item}</Paragraph> | ||
|
|
||
| <RadioButton | ||
| value="dynamic" | ||
| status={value === item ? 'checked' : 'unchecked'} | ||
| onPress={() => onChange(item)} | ||
| /> | ||
| </View> | ||
| ), | ||
| [value, onChange] | ||
| ); | ||
|
|
||
| const _keyExtractor = React.useCallback((item) => item, []); | ||
|
|
||
| return ( | ||
| <View style={styles.controlWrapper}> | ||
| <Paragraph>{name}</Paragraph> | ||
|
|
||
| <FlatList | ||
| horizontal | ||
| data={options} | ||
| renderItem={_renderItem} | ||
| keyExtractor={_keyExtractor} | ||
| contentContainerStyle={styles.controlItemsList} | ||
|
Drakeoon marked this conversation as resolved.
|
||
| /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| const CustomFABControls = ({ | ||
| setControls, | ||
| controls: { animateFrom, iconMode }, | ||
| }: Props) => { | ||
| const setIconMode = (newIconMode: AnimatedFABIconMode) => | ||
| setControls((state) => ({ ...state, iconMode: newIconMode })); | ||
|
|
||
| const setAnimateFrom = (newAnimateFrom: AnimatedFABAnimateFrom) => | ||
| setControls((state) => ({ ...state, animateFrom: newAnimateFrom })); | ||
|
|
||
| return ( | ||
| <View style={styles.controlsWrapper}> | ||
| <CustomControl | ||
| name="iconMode" | ||
| options={['static', 'dynamic']} | ||
| value={iconMode} | ||
| onChange={setIconMode} | ||
| /> | ||
|
|
||
| <CustomControl | ||
| name="animateFrom" | ||
| options={['left', 'right']} | ||
| value={animateFrom} | ||
| onChange={setAnimateFrom} | ||
| /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default CustomFABControls; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| controlsWrapper: { | ||
| flex: 1, | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| right: 0, | ||
| backgroundColor: Colors.white, | ||
| paddingVertical: 12, | ||
| paddingHorizontal: 16, | ||
| }, | ||
| controlWrapper: { | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| }, | ||
| controlItemsList: { | ||
| flex: 1, | ||
| justifyContent: 'flex-end', | ||
| }, | ||
| controlItem: { | ||
| marginLeft: 16, | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| }, | ||
| }); | ||
This file contains hidden or 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 @@ | ||
| export { default } from './AnimatedFABExample'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.