Skip to content
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

Create custom TextInput #3414

Merged
merged 57 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1d1847a
create custom textinput
kakajann Jun 8, 2021
39a395c
merge from main
kakajann Jun 20, 2021
32ac54d
restyling
kakajann Jun 20, 2021
9bb3acc
change password screen implementation and small refactors
kakajann Jun 20, 2021
0001f43
login screen implementation
kakajann Jun 20, 2021
2e21718
payment page implementation
kakajann Jun 25, 2021
e95de93
merge from main
kakajann Jun 25, 2021
587328d
update all textinputs to expensitextinput
kakajann Jun 25, 2021
1a9687c
resolve conflicts
kakajann Jun 27, 2021
c9ed8ee
make ExpensiTextInput cross-platform
kakajann Jun 27, 2021
edbfcea
picker styles and implementations
kakajann Jul 2, 2021
3ac6d2c
picker proptypes refactoring
kakajann Jul 2, 2021
57de005
expensiTextInput desktop hotfixes
kakajann Jul 2, 2021
f2e5667
resolve conflicts
kakajann Jul 2, 2021
dc7b471
fix autoFocus issue
kakajann Jul 2, 2021
28fa320
Merge branch 'main' of github.com:studio-504/Expensify.cash into form…
kakajann Jul 11, 2021
b3303c3
picker pressable issue
kakajann Jul 11, 2021
0db97b8
merge from main to resolve conflicts
kakajann Jul 11, 2021
8bdc856
fix lint issue
kakajann Jul 11, 2021
f0a779e
resolve conflicts
kakajann Jul 16, 2021
229e704
add custom translate x prop to expensiInput for label transformation
kakajann Jul 20, 2021
4edf386
Trigger Build
kakajann Jul 20, 2021
54e20a0
Merge branch 'main' into form-styles
kakajann Jul 21, 2021
d5a0b00
resolve conflicts for the 9th time
kakajann Jul 22, 2021
7495a56
resolve conflicts for the 10th time
kakajann Jul 22, 2021
f7a4b49
resolve conflicts
kakajann Jul 26, 2021
dc9ab22
revert podfile.lock
kakajann Jul 26, 2021
048436f
android related bugfixes
kakajann Jul 26, 2021
90db061
merge from main
kakajann Jul 29, 2021
9cfd7e3
add size prop to ExpensiPicker
kakajann Jul 29, 2021
7271cf1
change ExpensiPicker default prop
kakajann Jul 29, 2021
388d015
fix desktop related issue
kakajann Jul 29, 2021
1c582ce
use addOutlineWidth instead of outline: none
kakajann Jul 30, 2021
b6e36ea
remove android generated file
kakajann Jul 30, 2021
4662b06
merge defaultProps and propTypes files for ExpensiPicker
kakajann Jul 30, 2021
27c967b
remove toggleFocus on ExpensiPicker and use inline setState on onOpen…
kakajann Jul 30, 2021
f3c1c79
more refactors on ExpensiPicker
kakajann Jul 30, 2021
19f3257
prop type refactoring for ExpensiTextInput
kakajann Jul 30, 2021
221565d
refactor ExpensiTextInputLabel
kakajann Jul 30, 2021
f6fc27a
refactor ExpensiTextInputWrapper
kakajann Jul 30, 2021
598f0cc
change containerStyles comment
kakajann Jul 30, 2021
9a74f0a
more refactors for ExpensiTextInputWrapper
kakajann Jul 30, 2021
bd5c05b
refactor ExpensiTextInput
kakajann Jul 31, 2021
83c7d18
more refactors for ExpensiTextInput
kakajann Jul 31, 2021
abf866f
use themeColors instead of hex
kakajann Jul 31, 2021
739ce4d
styles refactor
kakajann Jul 31, 2021
2f0281a
refactor ExpensiPicker styles
kakajann Jul 31, 2021
b2067e4
resolve conflicts
kakajann Jul 31, 2021
3c2cd72
forward ExpensiTextInput ref for external usage
kakajann Aug 3, 2021
bc5ce35
more style refactors
kakajann Aug 3, 2021
ca971f3
remove redundant prop destructing from ExpensiPicker
kakajann Aug 4, 2021
7976869
change Picker with ExpensiPicker
kakajann Aug 4, 2021
dd461b5
ExpensiTextInput refactors
kakajann Aug 4, 2021
31a9efd
fix a propType typo
kakajann Aug 4, 2021
adeddc7
dry inputIOS and inputAndroid
kakajann Aug 6, 2021
534651e
remove propTypes from style component
kakajann Aug 9, 2021
8a0df8f
resolve conflict
kakajann Aug 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.expensify.chat.generated;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure if this generated file should be included in version control. And I mean that earnestly – I don't know if it should be included or not, but I would think no.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, but I think we should add it to .gitignore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, feel free to add android/app/src/main/java/com/expensify/chat/generated/* to the .gitignore


import java.util.Arrays;
import java.util.List;
import org.unimodules.core.interfaces.Package;

public class BasePackageList {
public List<Package> getPackageList() {
return Arrays.<Package>asList(
new expo.modules.haptics.HapticsPackage()
);
}
}
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ SPEC CHECKSUMS:
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
EXHaptics: 337c160c148baa6f0e7166249f368965906e346b
FBLazyVector: 7b423f9e248eae65987838148c36eec1dbfe0b53
FBReactNativeSpec: 884d4cc2b011759361797a4035c47e10099393b5
FBReactNativeSpec: c783a75db87c963c60afcd461fc38358805fe5ba
Firebase: 54cdc8bc9c9b3de54f43dab86e62f5a76b47034f
FirebaseABTesting: 4cb61aeeb50f60680af1c01fff781dfaf9293916
FirebaseAnalytics: 4751d6a49598a2b58da678cc07df696bcd809ab9
Expand Down
9 changes: 3 additions & 6 deletions src/components/AddPlaidBankAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import {
ActivityIndicator,
View,
TextInput,
} from 'react-native';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
Expand All @@ -22,6 +21,7 @@ import withLocalize, {withLocalizePropTypes} from './withLocalize';
import Button from './Button';
import Picker from './Picker';
import Text from './Text';
import ExpensiTextInput from './ExpensiTextInput';

const propTypes = {
...withLocalizePropTypes,
Expand Down Expand Up @@ -175,12 +175,9 @@ class AddPlaidBankAccount extends React.Component {
</View>
{!_.isUndefined(this.state.selectedIndex) && (
<View style={[styles.mb5]}>
<Text style={[styles.formLabel]}>
{this.props.translate('addPersonalBankAccountPage.enterPassword')}
</Text>
<TextInput
<ExpensiTextInput
label={this.props.translate('addPersonalBankAccountPage.enterPassword')}
secureTextEntry
style={[styles.textInput, styles.mb2]}
value={this.state.password}
autoCompleteType="password"
textContentType="password"
Expand Down
9 changes: 9 additions & 0 deletions src/components/ExpensiPicker/defaultProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const expensiPickerDefaultProps = {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
label: '',
value: '',
placeholder: {},
useDisabledStyles: false,
size: 'normal',
};

export default expensiPickerDefaultProps;
52 changes: 52 additions & 0 deletions src/components/ExpensiPicker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, {PureComponent} from 'react';
import {Text, View} from 'react-native';
import Picker from '../Picker';
import styles from '../../styles/styles';
import propTypes from './propTypes';
import defaultProps from './defaultProps';

class ExpensiPicker extends PureComponent {
constructor() {
super();
this.state = {
isOpen: false,
};
}

toggleFocus = open => this.setState({
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
isOpen: open,
})

render() {
const {
label, value, placeholder, useDisabledStyles, ...pickerProps
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
} = this.props;
const {isOpen} = this.state;
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
return (
<View
style={[
styles.expensiPickerContainer,
isOpen && styles.expensiPickerContainerOnFocus,
useDisabledStyles && styles.expensiPickerContainerDisabled,
]}
>
{label && (
<Text style={styles.expensiPickerLabel}>{label}</Text>
)}
<Picker
placeholder={placeholder}
value={value}
onOpen={() => this.toggleFocus(true)}
onClose={() => this.toggleFocus(false)}
// eslint-disable-next-line react/jsx-props-no-spreading
{...pickerProps}
/>
</View>
);
}
}

ExpensiPicker.propTypes = propTypes;
ExpensiPicker.defaultProps = defaultProps;

export default ExpensiPicker;
23 changes: 23 additions & 0 deletions src/components/ExpensiPicker/propTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import PropTypes from 'prop-types';
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

const propTypes = {
label: PropTypes.string,
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
value: PropTypes.string,

/** Something to show as the placeholder before something is selected */
placeholder: PropTypes.shape({
/** The value of the placeholder item, usually an empty string */
value: PropTypes.string,

/** The text to be displayed as the placeholder */
label: PropTypes.string,
}),

/** Picker disabled style */
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
useDisabledStyles: PropTypes.boolean,
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

/** Picker size */
size: PropTypes.oneOf(['normal', 'small']),
};

export default propTypes;
12 changes: 12 additions & 0 deletions src/components/ExpensiTextInput/ExpensiTextInputDefaultProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const expensiTextInputDefaultProps = {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
label: '',
placeholder: '',
error: false,
onFocusExtra: null,
onBlurExtra: null,
containerStyles: [],
translateX: -22,
androidStyle: [],
};

export default expensiTextInputDefaultProps;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import PropTypes from 'prop-types';
import {Animated} from 'react-native';

const expensiTextInputLabelPropTypes = {
label: PropTypes.string,
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

/** Label vertical translate */
labelTranslateY: PropTypes.instanceOf(Animated.Value).isRequired,

/** Label horizontal translate */
labelTranslateX: PropTypes.instanceOf(Animated.Value).isRequired,

/** Label scale */
labelScale: PropTypes.instanceOf(Animated.Value).isRequired,
};

export default expensiTextInputLabelPropTypes;
31 changes: 31 additions & 0 deletions src/components/ExpensiTextInput/ExpensiTextInputLabel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, {PureComponent} from 'react';
import {Animated} from 'react-native';
import styles from '../../../styles/styles';
import expensiTextInputLabelPropTypes from './ExpensiTextInputLabelPropTypes';

class ExpensiTextInputLabel extends PureComponent {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
render() {
const {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
label, labelTranslateX, labelTranslateY, labelScale,
} = this.props;
return (
<Animated.Text
style={[
styles.expensiTextInputLabel,
styles.expensiTextInputLabelDesktop,
styles.expensiTextInputLabelTransformation(
labelTranslateY,
labelTranslateX,
labelScale,
),
]}
>
{label}
</Animated.Text>
);
}
}

ExpensiTextInputLabel.propTypes = expensiTextInputLabelPropTypes;

export default ExpensiTextInputLabel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, {PureComponent} from 'react';
import {Animated} from 'react-native';
import styles from '../../../styles/styles';
import expensiTextInputLabelPropTypes from './ExpensiTextInputLabelPropTypes';

class ExpensiTextInputLabel extends PureComponent {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
render() {
const {
label, labelTranslateX, labelTranslateY, labelScale,
} = this.props;
return (
<Animated.Text
style={[
styles.expensiTextInputLabel,
styles.expensiTextInputLabelTransformation(
labelTranslateY,
labelTranslateX,
labelScale,
),
]}
>
{label}
</Animated.Text>
);
}
}

ExpensiTextInputLabel.propTypes = expensiTextInputLabelPropTypes;

export default ExpensiTextInputLabel;
32 changes: 32 additions & 0 deletions src/components/ExpensiTextInput/ExpensiTextInputPropTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import PropTypes from 'prop-types';
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

const expensiTextInputPropTypes = {
/** Input label */
label: PropTypes.string,

/** Input value */
value: PropTypes.string.isRequired,

/** Input value placeholder */
placeholder: PropTypes.string,

/** Callback that is called when the text input is focused. */
onFocusExtra: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onFocusExtra: PropTypes.func,
onFocus: PropTypes.func,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this and onBlurExtra everywhere to just onFocus and onBlur, respectively.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of need it.

onFocus is used in ExpensiTextInput component to change border color.
onFocusExtra is to do something custom in SomeOtherComponent

example usage here: (src/pages/settings/PasswordPage.js)

<ExpensiTextInput
    label={`${this.props.translate('passwordPage.newPassword')}*`}
    secureTextEntry
    autoCompleteType="password"
    textContentType="password"
    value={this.state.newPassword}
    onChangeText={newPassword => this.setState({newPassword})}
    onFocusExtra={() => this.setState({isPasswordRequirementsVisible: true})}
    onBlurExtra={() => this.setState({isPasswordRequirementsVisible: false})}
/>

Do you have suggestion about how to refactor?


/** Callback that is called when the text input is blurred. */
onBlurExtra: PropTypes.func,
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

/** Input with error */
error: PropTypes.bool,

/** Styles for the outermost container for this component. */
containerStyles: PropTypes.arrayOf(PropTypes.object),

/** label translate x */
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
translateX: PropTypes.number,

/** android specific styles */
androidStyle: PropTypes.arrayOf(PropTypes.object),
};

export default expensiTextInputPropTypes;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import PropTypes from 'prop-types';
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

const expensiTextInputWrapperPropTypes = {
/** Input label */
children: PropTypes.node.isRequired,

/** Has Label */
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
hasLabel: PropTypes.bool.isRequired,

/** On press to wrapper */
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
onPress: PropTypes.func.isRequired,

/** Is input in focus? */
isFocused: PropTypes.bool.isRequired,

/** Has error? */
error: PropTypes.bool.isRequired,

/** Styles for the outermost container for this component. */
containerStyles: PropTypes.arrayOf(PropTypes.object),
};

export default expensiTextInputWrapperPropTypes;
38 changes: 38 additions & 0 deletions src/components/ExpensiTextInput/ExpensiTextInputWrapper/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, {PureComponent} from 'react';
import {TouchableWithoutFeedback, View} from 'react-native';
import expensiTextInputWrapperPropTypes from './ExpensiTextInputWrapperPropTypes';
import styles from '../../../styles/styles';

const defaultProps = {
containerStyles: [],
};

class ExpensiTextInputWrapper extends PureComponent {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
render() {
const {
children, onPress, containerStyles, isFocused, error, hasLabel,
} = this.props;

return (
<View style={[styles.expensiTextInputWrapper, ...containerStyles]}>
<TouchableWithoutFeedback onPress={onPress}>
<View
style={[
styles.expensiTextInputContainer,
!hasLabel && styles.expensiTextInputContainerWithoutLabel,
isFocused && styles.expensiTextInputContainerOnFocus,
error && styles.expensiTextInputContainerOnError,
]}
>
{children}
</View>
</TouchableWithoutFeedback>
</View>
);
}
}

ExpensiTextInputWrapper.propTypes = expensiTextInputWrapperPropTypes;
ExpensiTextInputWrapper.defaultProps = defaultProps;

export default ExpensiTextInputWrapper;
23 changes: 23 additions & 0 deletions src/components/ExpensiTextInput/index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import styles from '../../styles/styles';
import ExpensiTextInput from './index.ios';
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
import expensiTextInputPropTypes from './ExpensiTextInputPropTypes';
import expensiTextInputDefaultProps from './ExpensiTextInputDefaultProps';

const ExpensiTextInputAndroid = ({
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
androidStyles,
translateX,
...props
}) => (
<ExpensiTextInput
androidStyles={styles.expensiTextInputAndroid(Math.abs(translateX))}
translateX={translateX}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
);

ExpensiTextInputAndroid.propTypes = expensiTextInputPropTypes;
ExpensiTextInputAndroid.defaultProps = expensiTextInputDefaultProps;
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

export default ExpensiTextInputAndroid;
Loading