-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix Agents - Input field does not auto scroll down when entering next line #94565
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
base: main
Are you sure you want to change the base?
Changes from all commits
6b295b6
4dfc3dc
d6b476e
71bb7ad
dca8f12
ccc44e9
4fc18dc
447aa6e
a916982
b9e0aa2
0c08359
99365b1
7bb2269
fee353d
843ee58
d630f62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import CollapsibleHeaderOnKeyboard from '@components/CollapsibleHeaderOnKeyboard'; | ||
| import FormProvider from '@components/Form/FormProvider'; | ||
| import InputWrapper from '@components/Form/InputWrapper'; | ||
| import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; | ||
|
|
@@ -7,15 +8,19 @@ import TextInput from '@components/TextInput'; | |
|
|
||
| import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode'; | ||
| import useKeyboardShortcut from '@hooks/useKeyboardShortcut'; | ||
| import useKeyboardState from '@hooks/useKeyboardState'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import {updateAgentPrompt} from '@libs/actions/Agent'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
| import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||
|
|
||
| import PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE from '@pages/settings/Agents/const'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
|
|
@@ -28,9 +33,12 @@ import {Platform, View} from 'react-native'; | |
| type EditPromptPageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.AGENTS.EDIT_PROMPT>; | ||
|
|
||
| function EditPromptPage({route}: EditPromptPageProps) { | ||
| const StyleUtils = useStyleUtils(); | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const shouldUseScrollableLayout = useIsInLandscapeMode(); | ||
| const {isKeyboardActive} = useKeyboardState(); | ||
| const isInLandscapeMode = useIsInLandscapeMode(); | ||
| const shouldShrinkPromptInput = isInLandscapeMode && isKeyboardActive; | ||
| const accountID = route.params.accountID; | ||
| const [agentPrompt] = useOnyx(`${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${accountID}`); | ||
|
|
||
|
|
@@ -71,27 +79,28 @@ function EditPromptPage({route}: EditPromptPageProps) { | |
| testID={EditPromptPage.displayName} | ||
| includeSafeAreaPaddingBottom | ||
| offlineIndicatorStyle={styles.mtAuto} | ||
| shouldEnableMaxHeight={shouldUseScrollableLayout} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EditPromptPage is a bit different, as I wanted the input to take the rest of the height in landscape mode, whereas in AddAgentPage in landscape mode the input height is a static value, it was intentional to remove it only in EditPromptPage |
||
| > | ||
| <HeaderWithBackButton | ||
| title={translate('editAgentPromptPage.title')} | ||
| onBackButtonPress={() => Navigation.goBack()} | ||
| /> | ||
| <CollapsibleHeaderOnKeyboard alwaysCollapseHeaderOnKeyboard> | ||
| <HeaderWithBackButton | ||
| title={translate('editAgentPromptPage.title')} | ||
| onBackButtonPress={() => Navigation.goBack()} | ||
| /> | ||
| </CollapsibleHeaderOnKeyboard> | ||
| <FormProvider | ||
| formID={ONYXKEYS.FORMS.EDIT_AGENT_PROMPT_FORM} | ||
| validate={validate} | ||
| onSubmit={handleSubmit} | ||
| submitButtonText={translate('common.save')} | ||
| style={[styles.flex1, styles.ph5]} | ||
| shouldUseScrollView={shouldUseScrollableLayout} | ||
| submitFlexEnabled={shouldUseScrollableLayout ? undefined : false} | ||
| shouldUseScrollView={false} | ||
| submitFlexEnabled={false} | ||
| enabledWhenOffline | ||
| shouldHideFixErrorsAlert | ||
| shouldValidateOnChange | ||
| shouldValidateOnBlur | ||
| keyboardSubmitBehavior={CONST.KEYBOARD_SUBMIT_BEHAVIOR.SUBMIT_ONLY} | ||
| > | ||
| <View style={[styles.flex1, shouldUseScrollableLayout && styles.minHeight42]}> | ||
| <View style={shouldShrinkPromptInput ? StyleUtils.getHeight(PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE) : [styles.flex1]}> | ||
| <InputWrapper | ||
| InputComponent={TextInput} | ||
| inputID={INPUT_IDS.PROMPT} | ||
|
|
@@ -100,9 +109,8 @@ function EditPromptPage({route}: EditPromptPageProps) { | |
| role={CONST.ROLE.PRESENTATION} | ||
| defaultValue={Str.htmlDecode(agentPrompt?.prompt ?? '')} | ||
| multiline | ||
| containerStyles={[styles.flex1]} | ||
| containerStyles={[styles.h100]} | ||
|
GCyganek marked this conversation as resolved.
|
||
| touchableInputWrapperStyle={[styles.flex1]} | ||
| textInputContainerStyles={[styles.flex1]} | ||
| inputStyle={[styles.flex1, styles.textAlignVerticalTop]} | ||
| /> | ||
| </View> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import variables from '@styles/variables'; | ||
|
|
||
| const MAX_PROMPT_LINES_WITH_KEYBOARD = 2; | ||
| const PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE = variables.componentSizeLarge + variables.lineHeightXLarge * (MAX_PROMPT_LINES_WITH_KEYBOARD - 1); | ||
|
|
||
| export default PROMPT_MAX_HEIGHT_ON_KEYBOARD_OPEN_LANDSCAPE_MODE; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type {FormRef} from '@components/Form/types'; | ||
|
|
||
| import type {RefObject} from 'react'; | ||
|
|
||
| function scrollToMultilineInput(formWrapperRef: RefObject<FormRef | null>, shouldScrollToMultilineInput: boolean) { | ||
| if (!shouldScrollToMultilineInput || !formWrapperRef.current) { | ||
| return; | ||
| } | ||
| formWrapperRef.current.scrollToEnd(); | ||
| } | ||
|
|
||
| export default scrollToMultilineInput; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type {FormRef} from '@components/Form/types'; | ||
|
|
||
| import type {RefObject} from 'react'; | ||
|
|
||
| // This function is only needed on iOS where there is no auto scroll to the multiline text input on focus. | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| function scrollToMultilineInput(formWrapperRef: RefObject<FormRef | null>, shouldScrollToMultilineInput: boolean) {} | ||
|
|
||
| export default scrollToMultilineInput; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MIN_HEADER_HEIGHT_ON_COLLAPSEchanges collapse behavior for all existing consumers.The old floor was
Math.max(0, ...), the new one is Math.max(16, ...). This affects every existing consumer ofCollapsibleHeaderOnKeyboardthat doesn't passalwaysCollapseHeaderOnKeyboard..Is it fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. It's just that designers didn't like cases where we did not have any padding above the input on header collapse, so I decided to fix all such cases like this, because I was getting new cases with inputs shown without top padding on header collapse on this PR