-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33329 from Expensify/jasperhuangg-cherry-pick-sta…
…ging-33325-1 🍒 Cherry pick PR #33325 to staging 🍒
- Loading branch information
Showing
11 changed files
with
241 additions
and
206 deletions.
There are no files selected for viewing
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
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,132 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {PureComponent} from 'react'; | ||
import {Animated, Easing, View} from 'react-native'; | ||
import compose from '@libs/compose'; | ||
import Icon from './Icon'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import PressableWithFeedback from './Pressable/PressableWithFeedback'; | ||
import Tooltip from './Tooltip/PopoverAnchorTooltip'; | ||
import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||
import withStyleUtils, {withStyleUtilsPropTypes} from './withStyleUtils'; | ||
import withTheme, {withThemePropTypes} from './withTheme'; | ||
import withThemeStyles, {withThemeStylesPropTypes} from './withThemeStyles'; | ||
|
||
const AnimatedIcon = Animated.createAnimatedComponent(Icon); | ||
AnimatedIcon.displayName = 'AnimatedIcon'; | ||
|
||
const AnimatedPressable = Animated.createAnimatedComponent(PressableWithFeedback); | ||
AnimatedPressable.displayName = 'AnimatedPressable'; | ||
|
||
const propTypes = { | ||
// Callback to fire on request to toggle the FloatingActionButton | ||
onPress: PropTypes.func.isRequired, | ||
|
||
// Current state (active or not active) of the component | ||
isActive: PropTypes.bool.isRequired, | ||
|
||
// Ref for the button | ||
buttonRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
|
||
...withLocalizePropTypes, | ||
...withThemePropTypes, | ||
...withThemeStylesPropTypes, | ||
...withStyleUtilsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
buttonRef: () => {}, | ||
}; | ||
|
||
class FloatingActionButton extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.animatedValue = new Animated.Value(props.isActive ? 1 : 0); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (prevProps.isActive === this.props.isActive) { | ||
return; | ||
} | ||
|
||
this.animateFloatingActionButton(); | ||
} | ||
|
||
/** | ||
* Animates the floating action button | ||
* Method is called when the isActive prop changes | ||
*/ | ||
animateFloatingActionButton() { | ||
const animationFinalValue = this.props.isActive ? 1 : 0; | ||
|
||
Animated.timing(this.animatedValue, { | ||
toValue: animationFinalValue, | ||
duration: 340, | ||
easing: Easing.inOut(Easing.ease), | ||
useNativeDriver: false, | ||
}).start(); | ||
} | ||
|
||
render() { | ||
const rotate = this.animatedValue.interpolate({ | ||
inputRange: [0, 1], | ||
outputRange: ['0deg', '135deg'], | ||
}); | ||
|
||
const backgroundColor = this.animatedValue.interpolate({ | ||
inputRange: [0, 1], | ||
outputRange: [this.props.theme.success, this.props.theme.buttonDefaultBG], | ||
}); | ||
|
||
const fill = this.animatedValue.interpolate({ | ||
inputRange: [0, 1], | ||
outputRange: [this.props.theme.textLight, this.props.theme.textDark], | ||
}); | ||
|
||
return ( | ||
<Tooltip text={this.props.translate('common.new')}> | ||
<View style={this.props.themeStyles.floatingActionButtonContainer}> | ||
<AnimatedPressable | ||
ref={(el) => { | ||
this.fabPressable = el; | ||
if (this.props.buttonRef) { | ||
this.props.buttonRef.current = el; | ||
} | ||
}} | ||
accessibilityLabel={this.props.accessibilityLabel} | ||
role={this.props.role} | ||
pressDimmingValue={1} | ||
onPress={(e) => { | ||
// Drop focus to avoid blue focus ring. | ||
this.fabPressable.blur(); | ||
this.props.onPress(e); | ||
}} | ||
onLongPress={() => {}} | ||
style={[this.props.themeStyles.floatingActionButton, this.props.StyleUtils.getAnimatedFABStyle(rotate, backgroundColor)]} | ||
> | ||
<AnimatedIcon | ||
src={Expensicons.Plus} | ||
fill={fill} | ||
/> | ||
</AnimatedPressable> | ||
</View> | ||
</Tooltip> | ||
); | ||
} | ||
} | ||
|
||
FloatingActionButton.propTypes = propTypes; | ||
FloatingActionButton.defaultProps = defaultProps; | ||
|
||
const FloatingActionButtonWithLocalize = withLocalize(FloatingActionButton); | ||
|
||
const FloatingActionButtonWithLocalizeWithRef = React.forwardRef((props, ref) => ( | ||
<FloatingActionButtonWithLocalize | ||
// eslint-disable-next-line | ||
{...props} | ||
buttonRef={ref} | ||
/> | ||
)); | ||
|
||
FloatingActionButtonWithLocalizeWithRef.displayName = 'FloatingActionButtonWithLocalizeWithRef'; | ||
|
||
export default compose(withThemeStyles, withTheme, withStyleUtils)(FloatingActionButtonWithLocalizeWithRef); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.