React native react本机日历在状态更改时更新CalanderList开始月份

React native react本机日历在状态更改时更新CalanderList开始月份,react-native,react-native-calendars,React Native,React Native Calendars,在下面的日期选择器中,选择日期不会更新日历列表的起始月。我试图这样做,当您在日期选择器上选择一个值时,开始月份将被更新 导入语句: import {Calendar, CalendarList, Agenda} from 'react-native-calendars'; import DatePicker from 'react-native-datepicker'; constructor(props) { super(props); this.state = {

在下面的日期选择器中,选择日期不会更新日历列表的起始月。我试图这样做,当您在日期选择器上选择一个值时,开始月份将被更新

导入语句:

import {Calendar, CalendarList, Agenda} from 'react-native-calendars';
import DatePicker from 'react-native-datepicker';
constructor(props) {
    super(props);
    this.state = {
    chosenDate: new Date(),
    selected: "key1",
    calenderCurrent:'2021-01-01',
    color:'green',
    };
    this.setDate = this.setDate.bind(this);
  }
setDate(newDate) {
    alert(newDate);
    //const frmtdate = moment(newDate).format('YYYY-MM-DD');
   // alert(frmtdate);
    this.setState({ chosenDate: newDate,
      calenderCurrent:'2021-02-02',
    color:'red' });
  }
    <DatePicker
    style={{borderWidth:0}}
    date={this.state.chosenDate} // Initial date from state
    mode="date" // The enum of date, datetime and time
    placeholder="select date"
    format="DD-MM-YYYY"
    confirmBtnText="Confirm"
    cancelBtnText="Cancel"
    customStyles={{
    dateIcon: {
    position: 'absolute',
    left: 0,
    top: 4,
    marginLeft: 0,
    },
    dateInput: {
      marginLeft: 36,
      borderWidth:0,
    },
   }}
   onDateChange={(date) => {
   this.setDate(date)
   }} 
   />
   <CalendarList            
   onVisibleMonthsChange={(months) => {console.log('now these months are visible', months);}}
   pastScrollRange={0}
   futureScrollRange={2}
   scrollEnabled={true}
   showScrollIndicator={true}
   markedDates={{
      '2021-01-20': {textColor: this.state.color},
      '2020-12-22': {startingDay: true, endingDay: false, color: 'green', textColor: 'white'},
      '2020-12-23': {selected: true, startingDay: false,endingDay: true, color: 'green', textColor: 'white'},
      '2020-12-24': {disabled: true, startingDay: true, color: 'green', endingDay: true}
   }}
   markingType={'period'}
   current={this.state.calenderCurrent}
   />

构造函数和函数:

import {Calendar, CalendarList, Agenda} from 'react-native-calendars';
import DatePicker from 'react-native-datepicker';
constructor(props) {
    super(props);
    this.state = {
    chosenDate: new Date(),
    selected: "key1",
    calenderCurrent:'2021-01-01',
    color:'green',
    };
    this.setDate = this.setDate.bind(this);
  }
setDate(newDate) {
    alert(newDate);
    //const frmtdate = moment(newDate).format('YYYY-MM-DD');
   // alert(frmtdate);
    this.setState({ chosenDate: newDate,
      calenderCurrent:'2021-02-02',
    color:'red' });
  }
    <DatePicker
    style={{borderWidth:0}}
    date={this.state.chosenDate} // Initial date from state
    mode="date" // The enum of date, datetime and time
    placeholder="select date"
    format="DD-MM-YYYY"
    confirmBtnText="Confirm"
    cancelBtnText="Cancel"
    customStyles={{
    dateIcon: {
    position: 'absolute',
    left: 0,
    top: 4,
    marginLeft: 0,
    },
    dateInput: {
      marginLeft: 36,
      borderWidth:0,
    },
   }}
   onDateChange={(date) => {
   this.setDate(date)
   }} 
   />
   <CalendarList            
   onVisibleMonthsChange={(months) => {console.log('now these months are visible', months);}}
   pastScrollRange={0}
   futureScrollRange={2}
   scrollEnabled={true}
   showScrollIndicator={true}
   markedDates={{
      '2021-01-20': {textColor: this.state.color},
      '2020-12-22': {startingDay: true, endingDay: false, color: 'green', textColor: 'white'},
      '2020-12-23': {selected: true, startingDay: false,endingDay: true, color: 'green', textColor: 'white'},
      '2020-12-24': {disabled: true, startingDay: true, color: 'green', endingDay: true}
   }}
   markingType={'period'}
   current={this.state.calenderCurrent}
   />

反应巴别塔代码:

import {Calendar, CalendarList, Agenda} from 'react-native-calendars';
import DatePicker from 'react-native-datepicker';
constructor(props) {
    super(props);
    this.state = {
    chosenDate: new Date(),
    selected: "key1",
    calenderCurrent:'2021-01-01',
    color:'green',
    };
    this.setDate = this.setDate.bind(this);
  }
setDate(newDate) {
    alert(newDate);
    //const frmtdate = moment(newDate).format('YYYY-MM-DD');
   // alert(frmtdate);
    this.setState({ chosenDate: newDate,
      calenderCurrent:'2021-02-02',
    color:'red' });
  }
    <DatePicker
    style={{borderWidth:0}}
    date={this.state.chosenDate} // Initial date from state
    mode="date" // The enum of date, datetime and time
    placeholder="select date"
    format="DD-MM-YYYY"
    confirmBtnText="Confirm"
    cancelBtnText="Cancel"
    customStyles={{
    dateIcon: {
    position: 'absolute',
    left: 0,
    top: 4,
    marginLeft: 0,
    },
    dateInput: {
      marginLeft: 36,
      borderWidth:0,
    },
   }}
   onDateChange={(date) => {
   this.setDate(date)
   }} 
   />
   <CalendarList            
   onVisibleMonthsChange={(months) => {console.log('now these months are visible', months);}}
   pastScrollRange={0}
   futureScrollRange={2}
   scrollEnabled={true}
   showScrollIndicator={true}
   markedDates={{
      '2021-01-20': {textColor: this.state.color},
      '2020-12-22': {startingDay: true, endingDay: false, color: 'green', textColor: 'white'},
      '2020-12-23': {selected: true, startingDay: false,endingDay: true, color: 'green', textColor: 'white'},
      '2020-12-24': {disabled: true, startingDay: true, color: 'green', endingDay: true}
   }}
   markingType={'period'}
   current={this.state.calenderCurrent}
   />

{
此.setDate(日期)
}} 
/>
{console.log('现在这些月份可见',月份);}
pastScrollRange={0}
未来滚动范围={2}
scrollEnabled={true}
showScrollIndicator={true}
标记日期={{
'2021-01-20':{textColor:this.state.color},
'2020-12-22':{开始日期:真,结束日期:假,颜色:'绿色',文本颜色:'白色',
'2020-12-23':{所选:真,开始日期:假,结束日期:真,颜色:'绿色',文本颜色:'白色',
'2020-12-24':{禁用:正确,开始日期:正确,颜色:绿色,结束日期:正确}
}}
markingType={'period'}
当前={this.state.calenderCurrent}
/>