-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #32440 from Expensify/revert-30996-kowczarz/room-n…
…ame-page-migration-fixes (cherry picked from commit ba78fbc)
- Loading branch information
Showing
8 changed files
with
134 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
import _ from 'underscore'; | ||
import TextInput from '@components/TextInput'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import getOperatingSystem from '@libs/getOperatingSystem'; | ||
import * as RoomNameInputUtils from '@libs/RoomNameInputUtils'; | ||
import CONST from '@src/CONST'; | ||
import * as roomNameInputPropTypes from './roomNameInputPropTypes'; | ||
|
||
function RoomNameInput({isFocused, autoFocus, disabled, errorText, forwardedRef, value, onBlur, onChangeText, onInputChange, shouldDelayFocus}) { | ||
const {translate} = useLocalize(); | ||
|
||
/** | ||
* Calls the onChangeText callback with a modified room name | ||
* @param {Event} event | ||
*/ | ||
const setModifiedRoomName = (event) => { | ||
const roomName = event.nativeEvent.text; | ||
const modifiedRoomName = RoomNameInputUtils.modifyRoomName(roomName); | ||
onChangeText(modifiedRoomName); | ||
|
||
// if custom component has onInputChange, use it to trigger changes (Form input) | ||
if (_.isFunction(onInputChange)) { | ||
onInputChange(modifiedRoomName); | ||
} | ||
}; | ||
|
||
const keyboardType = getOperatingSystem() === CONST.OS.IOS ? CONST.KEYBOARD_TYPE.ASCII_CAPABLE : CONST.KEYBOARD_TYPE.VISIBLE_PASSWORD; | ||
|
||
return ( | ||
<TextInput | ||
ref={forwardedRef} | ||
disabled={disabled} | ||
label={translate('newRoomPage.roomName')} | ||
accessibilityLabel={translate('newRoomPage.roomName')} | ||
role={CONST.ACCESSIBILITY_ROLE.TEXT} | ||
prefixCharacter={CONST.POLICY.ROOM_PREFIX} | ||
placeholder={translate('newRoomPage.social')} | ||
onChange={setModifiedRoomName} | ||
value={value.substring(1)} // Since the room name always starts with a prefix, we omit the first character to avoid displaying it twice. | ||
errorText={errorText} | ||
maxLength={CONST.REPORT.MAX_ROOM_NAME_LENGTH} | ||
keyboardType={keyboardType} // this is a bit hacky solution to a RN issue https://github.com/facebook/react-native/issues/27449 | ||
onBlur={(event) => isFocused && onBlur(event)} | ||
autoFocus={isFocused && autoFocus} | ||
autoCapitalize="none" | ||
shouldDelayFocus={shouldDelayFocus} | ||
/> | ||
); | ||
} | ||
|
||
RoomNameInput.propTypes = roomNameInputPropTypes.propTypes; | ||
RoomNameInput.defaultProps = roomNameInputPropTypes.defaultProps; | ||
RoomNameInput.displayName = 'RoomNameInput'; | ||
|
||
const RoomNameInputWithRef = React.forwardRef((props, ref) => ( | ||
<RoomNameInput | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
forwardedRef={ref} | ||
/> | ||
)); | ||
|
||
RoomNameInputWithRef.displayName = 'RoomNameInputWithRef'; | ||
|
||
export default RoomNameInputWithRef; |
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