Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 3 additions & 15 deletions src/components/RoomNameInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,17 @@ const defaultProps = {
class RoomNameInput extends Component {
constructor(props) {
super(props);
this.state = {
roomName: props.initialValue,
};

this.setModifiedRoomName = this.setModifiedRoomName.bind(this);
}

/**
* Sets the modified room name in the state and calls the onChangeText callback
* Calls the onChangeText callback with a modified room name
* @param {Event} event
*/
setModifiedRoomName(event) {
const nativeEvent = event.nativeEvent;
const roomName = nativeEvent.text;
const target = nativeEvent.target;
const selection = target.selectionStart;
const roomName = event.nativeEvent.text;
const modifiedRoomName = this.modifyRoomName(roomName);
this.setState({roomName: modifiedRoomName}, () => {
if (!selection) {
return;
}
target.selectionEnd = selection;
});
this.props.onChangeText(modifiedRoomName);
}

Expand Down Expand Up @@ -108,7 +96,7 @@ class RoomNameInput extends Component {
prefixCharacter={CONST.POLICY.ROOM_PREFIX}
placeholder={this.props.translate('newRoomPage.social')}
onChange={this.setModifiedRoomName}
value={this.state.roomName.substring(1)}
defaultValue={this.props.initialValue.substring(1)} // Since the room name always starts with a prefix, we omit the first character to avoid displaying it twice.
errorText={this.props.errorText}
autoCapitalize="none"
/>
Expand Down
1 change: 0 additions & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class WorkspaceNewRoomPage extends React.Component {
<ScrollView style={styles.flex1} contentContainerStyle={styles.p5}>
<View style={styles.mb5}>
<RoomNameInput
initialValue={this.state.roomName}
policyID={this.state.policyID}
errorText={this.state.errors.roomName}
onChangeText={roomName => this.clearErrorAndSetValue('roomName', roomName)}
Expand Down