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

Fix for: Editing workspace name to 1to3 characters adding extra line in the optional message when inviting users in Spanish #17878

Merged
merged 30 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2663cd8
Added autoGrowHeight feature
Ollyws Apr 24, 2023
3996bfe
Added autoGrowHeight prop
Ollyws Apr 24, 2023
63da719
Added paddingRight to baseTextInput
Ollyws Apr 24, 2023
d1e8606
Changed AND to ternary
Ollyws Apr 24, 2023
fb35aa7
Added autoGrowHeight to baseTextInputPropTypes
Ollyws Apr 24, 2023
9c8cc25
Changed to set multiline true when autoGrowHeight
Ollyws Apr 24, 2023
51a725d
Updated comment for onLayout
Ollyws Apr 24, 2023
49e44c7
Removed multiline prop from TextInput
Ollyws Apr 24, 2023
b598295
Added isMultiline variable
Ollyws Apr 24, 2023
f5490c1
Simplified onLayout
Ollyws Apr 24, 2023
8306310
Added AutoGrowHeightInput to stories
Ollyws Apr 25, 2023
971dce9
Added layout const
Ollyws Apr 25, 2023
208e9db
Only add zerowidth space if last char is linebreak
Ollyws Apr 25, 2023
a8f6a16
Changed props.multiline to isMultiline
Ollyws Apr 26, 2023
094db19
Export AutoGrowHeightInput
Ollyws Apr 26, 2023
5d1f2ce
Merge branch 'main' into issue-17202
Ollyws May 1, 2023
7c380e7
Add autoGrowHeight prop to TextInput
Ollyws May 1, 2023
d4b545a
Moved MiniReportActionContextMenu to top of view
Ollyws May 2, 2023
7082422
Revert move MiniReportActionContextMenu
Ollyws May 2, 2023
fc49ff6
Add scrollPadding for autoGrowHeight
Ollyws May 3, 2023
f1b6854
Merge branch 'main' into issue-17202
Ollyws May 3, 2023
40aeb20
Added minHeight to autoGrowHeight textInput
Ollyws May 3, 2023
3266612
Added getAutoGrowHeightInputStyle to StyleUtils
Ollyws May 3, 2023
2344a77
Implemented getAutoGrowHeightInputStyle
Ollyws May 3, 2023
f125bd6
Added autoGrowHeightInputContainer
Ollyws May 3, 2023
6c17fb7
Implemented autoGrowHeightInputContainer
Ollyws May 3, 2023
4959935
remove scrollPaddingTop and add textInput height
Ollyws May 4, 2023
4b4dab1
Added scrollPaddingTop to textInputContainer
Ollyws May 4, 2023
f58ea34
removed duplicate minHeight
Ollyws May 4, 2023
af4d0c7
Removed zero width space
Ollyws May 4, 2023
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
46 changes: 32 additions & 14 deletions src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';
import React, {Component} from 'react';
import {
Animated, View, TouchableWithoutFeedback, AppState, Keyboard,
Animated, View, TouchableWithoutFeedback, AppState, Keyboard, StyleSheet,
} from 'react-native';
import Str from 'expensify-common/lib/str';
import RNTextInput from '../RNTextInput';
Expand Down Expand Up @@ -219,21 +219,36 @@ class BaseTextInput extends Component {
!this.props.hideFocusedState && this.state.isFocused && styles.borderColorFocus,
(this.props.hasError || this.props.errorText) && styles.borderColorDanger,
], (finalStyles, s) => ({...finalStyles, ...s}), {});
const maxHeight = StyleSheet.flatten(this.props.containerStyles).maxHeight;
const isMultiline = this.props.multiline || this.props.autoGrowHeight;

return (
<>
<View>
<View
style={[
!this.props.multiline && styles.componentHeightLarge,
this.props.autoGrowHeight && styles.autoGrowHeightInputContainer(this.state.textInputHeight, maxHeight),
!isMultiline && styles.componentHeightLarge,
...this.props.containerStyles,
]}
>
<TouchableWithoutFeedback onPress={this.onPress} focusable={false}>
<View

// When multiline is not supplied, calculating textinput height using onLayout
onLayout={event => !this.props.multiline && this.setState({height: event.nativeEvent.layout.height})}
// When autoGrowHeight is true we calculate the width for the textInput, so It will break lines properly
// or if multiline is not supplied we calculate the textinput height, using onLayout.
onLayout={(event) => {
if (!this.props.autoGrowHeight && this.props.multiline) {
return;
}

const layout = event.nativeEvent.layout;

this.setState(prevState => ({
width: this.props.autoGrowHeight ? layout.width : prevState.width,
height: !isMultiline ? layout.height : prevState.height,
}));
}}
style={[
textInputContainerStyles,

Expand All @@ -245,7 +260,7 @@ class BaseTextInput extends Component {
<>
{/* Adding this background to the label only for multiline text input,
to prevent text overlapping with label when scrolling */}
{this.props.multiline && <View style={styles.textInputLabelBackground} pointerEvents="none" />}
{isMultiline && <View style={styles.textInputLabelBackground} pointerEvents="none" />}
<TextInputLabel
label={this.props.label}
labelTranslateY={this.state.labelTranslateY}
Expand All @@ -257,7 +272,7 @@ class BaseTextInput extends Component {
<View
style={[
styles.textInputAndIconContainer,
(this.props.multiline && hasLabel) && styles.textInputMultilineContainer,
(isMultiline && hasLabel) && styles.textInputMultilineContainer,
]}
pointerEvents="box-none"
>
Expand Down Expand Up @@ -295,15 +310,18 @@ class BaseTextInput extends Component {
styles.flex1,
styles.w100,
this.props.inputStyle,
(!hasLabel || this.props.multiline) && styles.pv0,
(!hasLabel || isMultiline) && styles.pv0,
this.props.prefixCharacter && StyleUtils.getPaddingLeft(this.state.prefixWidth + styles.pl1.paddingLeft),
this.props.secureTextEntry && styles.secureInput,

// Explicitly remove `lineHeight` from single line inputs so that long text doesn't disappear
// once it exceeds the input space (See https://github.com/Expensify/App/issues/13802)
!this.props.multiline && {height: this.state.height, lineHeight: undefined},
!isMultiline && {height: this.state.height, lineHeight: undefined},

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
this.props.autoGrowHeight && StyleUtils.getAutoGrowHeightInputStyle(this.state.textInputHeight, maxHeight),
]}
multiline={this.props.multiline}
multiline={isMultiline}
maxLength={this.props.maxLength}
onFocus={this.onFocus}
onBlur={this.onBlur}
Expand All @@ -318,7 +336,7 @@ class BaseTextInput extends Component {

// FormSubmit Enter key handler does not have access to direct props.
// `dataset.submitOnEnter` is used to indicate that pressing Enter on this input should call the submit callback.
dataSet={{submitOnEnter: this.props.multiline && this.props.submitOnEnter}}
dataSet={{submitOnEnter: isMultiline && this.props.submitOnEnter}}

/>
{Boolean(this.props.secureTextEntry) && (
Expand Down Expand Up @@ -352,15 +370,15 @@ class BaseTextInput extends Component {
{/*
Text input component doesn't support auto grow by default.
We're using a hidden text input to achieve that.
This text view is used to calculate width of the input value given textStyle in this component.
This text view is used to calculate width or height of the input value given textStyle in this component.
This Text component is intentionally positioned out of the screen.
*/}
{this.props.autoGrow && (
{(this.props.autoGrow || this.props.autoGrowHeight) && (

// Add +2 to width so that the first digit of amount do not cut off on mWeb - https://github.com/Expensify/App/issues/8158.
<Text
style={[...this.props.inputStyle, styles.hiddenElementOutsideOfWindow, styles.visibilityHidden]}
onLayout={e => this.setState({textInputWidth: e.nativeEvent.layout.width + 2})}
style={[...this.props.inputStyle, this.props.autoGrowHeight ? {maxWidth: this.state.width} : {}, styles.hiddenElementOutsideOfWindow, styles.visibilityHidden]}
onLayout={e => this.setState({textInputWidth: e.nativeEvent.layout.width + 2, textInputHeight: e.nativeEvent.layout.height})}
>
{this.state.value || this.props.placeholder}
</Text>
Expand Down
6 changes: 5 additions & 1 deletion src/components/TextInput/baseTextInputPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ const propTypes = {
/** Disable the virtual keyboard */
disableKeyboard: PropTypes.bool,

/** Autogrow input container size based on the entered text */
/** Autogrow input container length based on the entered text */
autoGrow: PropTypes.bool,

/** Autogrow input container height based on the entered text */
autoGrowHeight: PropTypes.bool,

/** Hide the focus styles on TextInput */
hideFocusedState: PropTypes.bool,

Expand Down Expand Up @@ -108,6 +111,7 @@ const defaultProps = {
forceActiveLabel: false,
disableKeyboard: false,
autoGrow: false,
autoGrowHeight: false,
hideFocusedState: false,
innerRef: () => {},
shouldSaveDraft: false,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/WorkspaceInviteMessagePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ class WorkspaceInviteMessagePage extends React.Component {
label={this.props.translate('workspace.inviteMessage.personalMessagePrompt')}
autoCompleteType="off"
autoCorrect={false}
numberOfLines={4}
autoGrowHeight
textAlignVertical="top"
multiline
containerStyles={[styles.workspaceInviteWelcome]}
defaultValue={this.state.welcomeNote}
value={this.state.welcomeNote}
Expand Down
12 changes: 12 additions & 0 deletions src/stories/TextInput.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ AutoGrowInput.args = {
}],
};

const AutoGrowHeightInput = Template.bind({});
AutoGrowHeightInput.args = {
Ollyws marked this conversation as resolved.
Show resolved Hide resolved
label: 'Autogrowheight input',
name: 'AutoGrowHeight',
placeholder: 'My placeholder text',
autoGrowHeight: true,
textInputContainerStyles: [{
maxHeight: 115,
}],
};

const PrefixedInput = Template.bind({});
PrefixedInput.args = {
label: 'Prefixed input',
Expand Down Expand Up @@ -118,6 +129,7 @@ export {
ForceActiveLabel,
PlaceholderInput,
AutoGrowInput,
AutoGrowHeightInput,
PrefixedInput,
MaxLengthInput,
HintAndErrorInput,
Expand Down
19 changes: 19 additions & 0 deletions src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ function getWidthStyle(width) {
};
}

/**
* Returns auto grow height text input style
*
* @param {Number} textInputHeight
* @param {Number} maxHeight
* @returns {Object}
*/
function getAutoGrowHeightInputStyle(textInputHeight, maxHeight) {
if (textInputHeight > maxHeight) {
return styles.overflowAuto;
}

return {
...styles.overflowHidden,
height: maxHeight,
Copy link
Contributor

Choose a reason for hiding this comment

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

padding and borderwidth were not considered in maxHeight. It caused #18918 issue regression which is solved by https://github.com/Expensify/App/pull/19582/files

};
}

/**
* Returns a style with backgroundColor and borderColor set to the same color
*
Expand Down Expand Up @@ -1103,6 +1121,7 @@ export {
getZoomCursorStyle,
getZoomSizingStyle,
getWidthStyle,
getAutoGrowHeightInputStyle,
getBackgroundAndBorderStyle,
getBackgroundColorStyle,
getBackgroundColorWithOpacityStyle,
Expand Down
9 changes: 8 additions & 1 deletion src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,11 @@ const styles = {
backgroundColor: themeColors.buttonDefaultBG,
},

autoGrowHeightInputContainer: (textInputHeight, maxHeight) => ({
height: textInputHeight >= maxHeight ? maxHeight : textInputHeight,
Copy link
Contributor

Choose a reason for hiding this comment

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

👋 Coming from #22583
We were missing a check for the minimum height when setting the input height. It only checked if the calculated height is greater than the maxHeight, but didn't consider the case where the calculated height is less than the minHeight.
We resolved this by calculating the height using

lodashClamp(textInputHeight, minHeight, maxHeight)

minHeight: variables.componentSizeLarge,
}),

textInputContainer: {
flex: 1,
justifyContent: 'center',
Expand All @@ -808,6 +813,7 @@ const styles = {
borderBottomWidth: 2,
borderColor: themeColors.border,
overflow: 'hidden',
scrollPaddingTop: '100%',
},

textInputLabel: {
Expand Down Expand Up @@ -848,6 +854,7 @@ const styles = {
paddingTop: 23,
paddingBottom: 8,
paddingLeft: 0,
paddingRight: 0,
borderWidth: 0,
},

Expand Down Expand Up @@ -2566,7 +2573,7 @@ const styles = {
},

workspaceInviteWelcome: {
minHeight: 115,
maxHeight: 115,
Ollyws marked this conversation as resolved.
Show resolved Hide resolved
},

peopleRow: {
Expand Down