react-native-picker / picker

Picker is a cross-platform UI component for selecting an item from a list of options.
MIT License
1.49k stars 280 forks source link

Cannot trigger focus using ref #423

Open aaronvega-msft opened 2 years ago

aaronvega-msft commented 2 years ago
    dropdownRef: React.RefObject<Picker<string>>;
    textBoxRef: React.RefObject<TextInput>;

    constructor(props: any) {
        super(props);
        this.dropdownRef = React.createRef();
        this.textBoxRef = React.createRef();
    }

    async componentDidMount() {
        setTimeout(() => {
            this.dropdownRef.current?.focus();

            setTimeout(() => {
                this.textBoxRef.current?.focus();
            }, 3000);

        }, 3000);
    }

    render() {
        return <View>
            <View >
                <View >
                    <Picker
                        ref={this.dropdownRef}
                    >
                        <Picker.Item label={"Apples"} value={1} key={1} />
                        <Picker.Item label={"Oranges"} value={2} key={2} />
                    </Picker>
                </View>
                <View>
                    <TextInput
                        ref={this.textBoxRef}
                    />
                </View>
            </View>
        </View>
    }   

Focus does not land on picker when its ref gets called in componentDidMount. Is there a fix for this?

Using:

josh-thompson13 commented 1 year ago

Its currently only available for Android ... no idea why. This definitely needs to be fixed though.

UncleKhab commented 1 month ago

Having the same issue on Android using Version 4.7.7