wix / react-native-ui-lib

UI Components Library for React Native
https://wix.github.io/react-native-ui-lib/
MIT License
6.45k stars 706 forks source link

DateTimePicker - update the value on the fly #972

Closed danilovq closed 3 years ago

danilovq commented 3 years ago

I am not sure is it a bug or feature request, but I am trying to set DateTimePicker value depends on the my component state. It seems, that the DateTimePicker component ignores the value prop when it's already initialized.

Here is the code snippet:

import React, {Component} from 'react';
import {Button, DateTimePicker, View} from 'react-native-ui-lib';

export default class Example extends Component {

    constructor(props) {
        super(props)
        this.state = {
            date: new Date(),
        };
    }

    render() {
        return (
            <View flexG center>
                <DateTimePicker
                    containerStyle={{marginVertical: 20}}
                    title={'Date'}
                    placeholder={'Select a date'}
                    dateFormat={"DD.MM.YYYY"}
                    value={this.state.date}
                />
                <Button label={"Set another value"} onPress={() => this.setState({date: new Date("2020-07-01T00:00:00")})}/>
            </View>
        );
    }
}
Inbal-Tish commented 3 years ago

@danilovq Yes. The 'value' prop is, as mentioned, the initial value. If you want to update it we your screen's state change you should pass the 'key' prop as well to get a new instance of the component (as it is an uncontrolled component).

ethanshar commented 3 years ago

@Inbal-Tish Maybe we should consider renaming the prop name to initialValue for v6

Inbal-Tish commented 3 years ago

@ethanshar The 'value' prop name is based on the community's DateTimePicker prop. I thought of keeping it the same for smoother migration.

ethanshar commented 3 years ago

And the community component is controlled or uncontrolled?

Inbal-Tish commented 3 years ago

Controlled

ethanshar commented 3 years ago

Do you think it's possible to keep it controlled? Controlled considered best practice in general, we should aim for that for v6..

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ethanshar commented 3 years ago

@Inbal-Tish This one has been resolved, right?

Inbal-Tish commented 3 years ago

Yes

abbas-twocx commented 1 year ago

how can I change the theme colour of the icon of Datetimepicker RNUILIB, @Inbal-Tish @ethanshar