3

我有以下简单的组件:

function TestComp() {
    const [selection, setselection] = React.useState({ start: 0, end: 0 });

    return (
        <View style={{ justifyContent: "center", flex: 1 }}>
            <TextInput
                selection={selection}
                onSelectionChange={(event) => {
                    const {nativeEvent: { selection: { start, end } }} = event;
                    setselection({ start, end });
                }}
                multiline={true}
            />
        </View>
    );
}

我的问题是selectionthrough的值更新经常会有延迟setselection,这会导致插入符号跳来跳去或触发错误:(setSpan(1 ... 1) ends beyond length 0 我认为这意味着选择设置为大于 TextInput 值)

我应该如何使用选择道具?我的目标是能够在需要时移动光标。

我正在使用博览会,但关闭远程调试不会造成额外的延迟。

跳跃示例:

在此处输入图像描述

4

0 回答 0