Skip to content

Export the setSelection method on TextInput's ref #4603

@TivonJJ

Description

@TivonJJ

Issue

I wanna use TextInput ref to set user selection, The react native has setSelection method, But it's not work on react-native-paper.
I saw the source code it dosent export this method. (

React.useImperativeHandle(ref, () => ({
)

Example

import { View, TextInput } from 'react-native';

 const ReceiveScreen: ScreenPage<{ initialAmount?: number }> = ({ route: { params } }) => {
    const f = useRef<TextInput>(null);
    return (
        <Screen>
            <TextInput value={'Hi this is a input'} ref={f} />
            <Button
                onPress={() => {
                    f.current?.focus();
                    // The TextInput from 'react-native' is work fine, but it's undefined while from 'react-native-paper'
                    f.current?.setSelection(0, 3);
                }}
            >
                Select
            </Button>
        </Screen>
    );
};

💡 I have tried to use setNativeProps instead, but it's not work both on react-native and react-native-paper.
Currently, I am doing it by rewriting the render, I think it's better to export this usefull method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions