Git Product home page Git Product logo

Comments (7)

mmazzarolo avatar mmazzarolo commented on July 22, 2024

Hi!
First of all, you should have only a single picker here (just put it in the render, after the rows):

return (
  <View>
    <ScrollView>
      {this.renderRows()}
    </ScrollView>
    <DateTimePicker
      isVisible={this.state.isDateTimePickerVisible}
      onConfirm={this._handleDatePicked}
      onCancel={this._hideDateTimePicker}
    />
  </View>
);

Also, any reason you're not using a listview instead of the scrollview? :)

from react-native-modal-datetime-picker.

RailtonMatthew avatar RailtonMatthew commented on July 22, 2024

With a single picker how can I set the default date for each row? I will have a long list so want to be able to scroll.

Railton.

from react-native-modal-datetime-picker.

mmazzarolo avatar mmazzarolo commented on July 22, 2024

FYI, this is not really related to the component itself, it is a "react" question 👍

Anyway, your best option in my opinion is to set the DateTimePicker date dynamically before showing it.
For example you can add to the state a variable with the date being edited:

state: {
  isDateTimePickerVisible: false,
  dateBeingEdited: null
}

// In the render
<DateTimePicker
  date={this.state.dateBeingEdited}
  isVisible={this.state.isDateTimePickerVisible}
  onConfirm={this._handleDatePicked}
  onCancel={this._hideDateTimePicker} 
/>

And act before showing/hiding the component:

_showDateTimePicker = (date) => this.setState({ dateBeingEdited: date, isDateTimePickerVisible: true})

_hideDateTimePicker = () => this.setState({ isDateTimePickerVisible: false })

However you should really take a look at the react-native official listview implementation, it would help you in handling better you'r list! 🍔

from react-native-modal-datetime-picker.

RailtonMatthew avatar RailtonMatthew commented on July 22, 2024

Thanks Matteo, that works! I will look into the use of listview.

Railton.

from react-native-modal-datetime-picker.

mmazzarolo avatar mmazzarolo commented on July 22, 2024

Glad it worked :)

from react-native-modal-datetime-picker.

harishsn avatar harishsn commented on July 22, 2024

Hi This is not working.

if i click on the list item the time is still the same supplied by new Date() for all list items. Component is not updating.

what did i miss?

Here is my code

this.state={
     initialTime : new Date()
}

_showDateTimePicker = (date) => this.setState({initialTime: date, isDateTimePickerVisible: true })

<ListItem  key={ event.id } onPress={()=>{
        	         this._showDateTimePicker(new Date(event.slot)) }>
<Text>{event.name}</Text>
</ListItem>

<DateTimePicker
	mode='time'
        date={this.state.initialTime}
	titleIOS='Time slot'
        isVisible={this.state.isDateTimePickerVisible}
       onConfirm={this._handleDatePicked}
       onCancel={this._hideDateTimePicker} />

from react-native-modal-datetime-picker.

cubesdev8 avatar cubesdev8 commented on July 22, 2024

how can we use two " time picker " in single screen?

from react-native-modal-datetime-picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.