-
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 branch 'main' into chirag-center-prompt
- Loading branch information
Showing
66 changed files
with
977 additions
and
416 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
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
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,7 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import styles from '../styles/styles'; | ||
|
||
const CardOverlay = () => <View style={styles.cardOverlay} />; | ||
|
||
export default CardOverlay; |
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,58 @@ | ||
import React, {PureComponent} from 'react'; | ||
import {Text, View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import Picker from './Picker'; | ||
import styles from '../styles/styles'; | ||
|
||
const propTypes = { | ||
/** Picker label */ | ||
label: PropTypes.string, | ||
|
||
/** Should the picker appear disabled? */ | ||
isDisabled: PropTypes.bool, | ||
}; | ||
|
||
const defaultProps = { | ||
label: '', | ||
isDisabled: false, | ||
}; | ||
|
||
class ExpensiPicker extends PureComponent { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
isOpen: false, | ||
}; | ||
} | ||
|
||
render() { | ||
const { | ||
label, isDisabled, ...pickerProps | ||
} = this.props; | ||
return ( | ||
<View | ||
style={[ | ||
styles.expensiPickerContainer, | ||
this.state.isOpen && styles.borderColorFocus, | ||
isDisabled && styles.inputDisabled, | ||
]} | ||
> | ||
{label && ( | ||
<Text style={[styles.expensiPickerLabel, styles.textLabelSupporting]}>{label}</Text> | ||
)} | ||
<Picker | ||
onOpen={() => this.setState({isOpen: true})} | ||
onClose={() => this.setState({isOpen: false})} | ||
disabled={isDisabled} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...pickerProps} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
ExpensiPicker.propTypes = propTypes; | ||
ExpensiPicker.defaultProps = defaultProps; | ||
|
||
export default ExpensiPicker; |
139 changes: 139 additions & 0 deletions
139
src/components/ExpensiTextInput/BaseExpensiTextInput.js
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,139 @@ | ||
import React, {Component} from 'react'; | ||
import { | ||
Animated, TextInput, View, TouchableWithoutFeedback, | ||
} from 'react-native'; | ||
import ExpensiTextInputLabel from './ExpensiTextInputLabel'; | ||
import {propTypes, defaultProps} from './propTypes'; | ||
import themeColors from '../../styles/themes/default'; | ||
import styles from '../../styles/styles'; | ||
|
||
const ACTIVE_LABEL_TRANSLATE_Y = -10; | ||
const ACTIVE_LABEL_TRANSLATE_X = (translateX = -22) => translateX; | ||
const ACTIVE_LABEL_SCALE = 0.8668; | ||
|
||
const INACTIVE_LABEL_TRANSLATE_Y = 0; | ||
const INACTIVE_LABEL_TRANSLATE_X = 0; | ||
const INACTIVE_LABEL_SCALE = 1; | ||
|
||
class BaseExpensiTextInput extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const hasValue = props.value.length > 0; | ||
|
||
this.state = { | ||
isFocused: false, | ||
labelTranslateY: new Animated.Value(hasValue ? ACTIVE_LABEL_TRANSLATE_Y : INACTIVE_LABEL_TRANSLATE_Y), | ||
labelTranslateX: new Animated.Value(hasValue | ||
? ACTIVE_LABEL_TRANSLATE_X(props.translateX) : INACTIVE_LABEL_TRANSLATE_X), | ||
labelScale: new Animated.Value(hasValue ? ACTIVE_LABEL_SCALE : INACTIVE_LABEL_SCALE), | ||
}; | ||
|
||
this.input = null; | ||
this.onFocus = this.onFocus.bind(this); | ||
this.onBlur = this.onBlur.bind(this); | ||
} | ||
|
||
onFocus() { | ||
if (this.props.onFocus) { this.props.onFocus(); } | ||
this.setState({isFocused: true}); | ||
if (this.props.value.length === 0) { | ||
this.animateLabel( | ||
ACTIVE_LABEL_TRANSLATE_Y, | ||
ACTIVE_LABEL_TRANSLATE_X(this.props.translateX), | ||
ACTIVE_LABEL_SCALE, | ||
); | ||
} | ||
} | ||
|
||
onBlur() { | ||
if (this.props.onBlur) { this.props.onBlur(); } | ||
this.setState({isFocused: false}); | ||
if (this.props.value.length === 0) { | ||
this.animateLabel(INACTIVE_LABEL_TRANSLATE_Y, INACTIVE_LABEL_TRANSLATE_X, INACTIVE_LABEL_SCALE); | ||
} | ||
} | ||
|
||
animateLabel(translateY, translateX, scale) { | ||
Animated.parallel([ | ||
Animated.spring(this.state.labelTranslateY, { | ||
toValue: translateY, | ||
duration: 80, | ||
useNativeDriver: true, | ||
}), | ||
Animated.spring(this.state.labelTranslateX, { | ||
toValue: translateX, | ||
duration: 80, | ||
useNativeDriver: true, | ||
}), | ||
Animated.spring(this.state.labelScale, { | ||
toValue: scale, | ||
duration: 80, | ||
useNativeDriver: true, | ||
}), | ||
]).start(); | ||
} | ||
|
||
render() { | ||
const { | ||
label, | ||
value, | ||
placeholder, | ||
hasError, | ||
containerStyles, | ||
inputStyle, | ||
ignoreLabelTranslateX, | ||
innerRef, | ||
...inputProps | ||
} = this.props; | ||
|
||
const hasLabel = Boolean(label.length); | ||
return ( | ||
<View style={[styles.componentHeightLarge, ...containerStyles]}> | ||
<TouchableWithoutFeedback onPress={() => this.input.focus()}> | ||
<View | ||
style={[ | ||
styles.expensiTextInputContainer, | ||
!hasLabel && styles.pv0, | ||
this.state.isFocused && styles.borderColorFocus, | ||
hasError && styles.borderColorDanger, | ||
]} | ||
> | ||
{hasLabel ? ( | ||
<ExpensiTextInputLabel | ||
label={label} | ||
labelTranslateX={ | ||
ignoreLabelTranslateX | ||
? new Animated.Value(0) | ||
: this.state.labelTranslateX | ||
} | ||
labelTranslateY={this.state.labelTranslateY} | ||
labelScale={this.state.labelScale} | ||
/> | ||
) : null} | ||
<TextInput | ||
ref={(ref) => { | ||
if (typeof innerRef === 'function') { innerRef(ref); } | ||
this.input = ref; | ||
}} | ||
// eslint-disable-next-line | ||
{...inputProps} | ||
value={value} | ||
placeholder={(this.state.isFocused || !label) ? placeholder : null} | ||
placeholderTextColor={themeColors.placeholderText} | ||
underlineColorAndroid="transparent" | ||
style={inputStyle} | ||
onFocus={this.onFocus} | ||
onBlur={this.onBlur} | ||
/> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
BaseExpensiTextInput.propTypes = propTypes; | ||
BaseExpensiTextInput.defaultProps = defaultProps; | ||
|
||
export default BaseExpensiTextInput; |
Oops, something went wrong.