Fix cursor position when editing a group chat name (#10872)
This commit is contained in:
@@ -347,6 +347,13 @@ function SettingsHeader({
|
|||||||
|
|
||||||
const groupName = convo.details.name
|
const groupName = convo.details.name
|
||||||
const [newGroupName, setNewGroupName] = useState(groupName)
|
const [newGroupName, setNewGroupName] = useState(groupName)
|
||||||
|
const [editNameInputKey, setEditNameInputKey] = useState(0)
|
||||||
|
|
||||||
|
const openEditNamePrompt = () => {
|
||||||
|
setNewGroupName(groupName)
|
||||||
|
setEditNameInputKey(k => k + 1)
|
||||||
|
editNamePrompt.open()
|
||||||
|
}
|
||||||
|
|
||||||
const lockStatus = convo.details.lockStatus
|
const lockStatus = convo.details.lockStatus
|
||||||
|
|
||||||
@@ -485,10 +492,7 @@ function SettingsHeader({
|
|||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityHint={l`Edit this group chat’s name`}
|
accessibilityHint={l`Edit this group chat’s name`}
|
||||||
hitSlop={HITSLOP_10}
|
hitSlop={HITSLOP_10}
|
||||||
onPress={() => {
|
onPress={openEditNamePrompt}>
|
||||||
setNewGroupName(groupName)
|
|
||||||
editNamePrompt.open()
|
|
||||||
}}>
|
|
||||||
{groupNameComponent}
|
{groupNameComponent}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : (
|
) : (
|
||||||
@@ -538,10 +542,7 @@ function SettingsHeader({
|
|||||||
icon={EditIcon}
|
icon={EditIcon}
|
||||||
label={l`Edit this group chat’s name`}
|
label={l`Edit this group chat’s name`}
|
||||||
text={l`Edit name`}
|
text={l`Edit name`}
|
||||||
onPress={() => {
|
onPress={openEditNamePrompt}
|
||||||
setNewGroupName(groupName)
|
|
||||||
editNamePrompt.open()
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{isJoinLinkEnabled ? (
|
{isJoinLinkEnabled ? (
|
||||||
@@ -597,6 +598,7 @@ function SettingsHeader({
|
|||||||
<EditNamePrompt
|
<EditNamePrompt
|
||||||
control={editNamePrompt}
|
control={editNamePrompt}
|
||||||
value={newGroupName}
|
value={newGroupName}
|
||||||
|
inputKey={editNameInputKey}
|
||||||
onChangeText={setNewGroupName}
|
onChangeText={setNewGroupName}
|
||||||
onConfirm={() => editGroupName({name: newGroupName})}
|
onConfirm={() => editGroupName({name: newGroupName})}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -12,11 +12,18 @@ import {Text} from '#/components/Typography'
|
|||||||
export function EditNamePrompt({
|
export function EditNamePrompt({
|
||||||
control,
|
control,
|
||||||
value,
|
value,
|
||||||
|
inputKey,
|
||||||
onChangeText,
|
onChangeText,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
}: {
|
}: {
|
||||||
control: Dialog.DialogOuterProps['control']
|
control: Dialog.DialogOuterProps['control']
|
||||||
value: string
|
value: string
|
||||||
|
/**
|
||||||
|
* Bump this whenever the prompt is opened to remount the (uncontrolled)
|
||||||
|
* input and reseed it from `value`. Required because the native bottom sheet
|
||||||
|
* keeps its children mounted across opens.
|
||||||
|
*/
|
||||||
|
inputKey: number
|
||||||
onChangeText: (value: string) => void
|
onChangeText: (value: string) => void
|
||||||
onConfirm: () => void
|
onConfirm: () => void
|
||||||
}) {
|
}) {
|
||||||
@@ -38,9 +45,10 @@ export function EditNamePrompt({
|
|||||||
<View style={[a.my_sm]}>
|
<View style={[a.my_sm]}>
|
||||||
<TextField.Root isInvalid={nameTooLong}>
|
<TextField.Root isInvalid={nameTooLong}>
|
||||||
<TextField.Input
|
<TextField.Input
|
||||||
|
key={inputKey}
|
||||||
label={l`Edit group name`}
|
label={l`Edit group name`}
|
||||||
placeholder={l`Group name`}
|
placeholder={l`Group name`}
|
||||||
value={value}
|
defaultValue={value}
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
returnKeyType="done"
|
returnKeyType="done"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
|
|||||||
Reference in New Issue
Block a user