React native Datepicker的占位符随react native中的选定日期而更改,我希望使占位符保持不变,而不是更改

React native Datepicker的占位符随react native中的选定日期而更改,我希望使占位符保持不变,而不是更改,react-native,native-base,React Native,Native Base,我是新手,需要帮助 我在react native中使用了一个native base的日期选择器,我在其占位符处放置了一个图标,当我单击日期选择器并选择日期时,占位符图标会随着所选日期的变化而变化,因此我想使占位符只显示图标而不是所选日期,因此我如何实现这一点。 我的日期选择器代码 import React, { Component } from 'react'; import { Alert, Image, ScrollView, View, AppRegistry, StyleSheet, A

我是新手,需要帮助

我在react native中使用了一个native base的日期选择器,我在其占位符处放置了一个图标,当我单击日期选择器并选择日期时,占位符图标会随着所选日期的变化而变化,因此我想使占位符只显示图标而不是所选日期,因此我如何实现这一点。 我的日期选择器代码

import React, { Component } from 'react';
import { Alert, Image, ScrollView, View, AppRegistry, StyleSheet, AsyncStorage, SafeAreaView, FlatList, ActivityIndicator, TouchableOpacity, Platform  } from 'react-native';
import { fetchUpdateAsync } from 'expo/build/Updates/Updates';
import DateTimePicker from "react-native-modal-datetime-picker";
import DateSelect from 'react-native-datepicker';
import { TextInput } from 'react-native-gesture-handler';
import moment from "moment";
import { Container, Header, Label, Button, Content, Item, Input, Textarea, DatePicker, Body, Title, Text, Icon, Picker, Form } from 'native-base';

var datepicker='';
var leavetype='';
var reason='';
var access_token_receieved='';
var chosenDate='';
var newDate='';
class RequestLeave extends Component {
    state = {choosenLabel: '', choosenindex: ''}
    constructor(props) {
        super(props);
        this.state = { 
            chosenDate:'',
            date: '',
            selected: undefined,
            datepicker:'',
            reason:'',
            leavetype:'',
         };
        this.setDate = this.setDate.bind(this);
    } 
    setDate(newDate)
    {
      this.chosenDate= new Date(),
      this.setState({ chosenDate: newDate });
    }
    onIconclick(){
      //this.setDate();
      chosenDate= new Date()
      this.setState({ chosenDate: newDate });
    }
    onValueChange(value) 
    {
        this.setState({choosenLabel: itemValue, choosenIndex: itemIndex})
    }
    componentDidMount() {
      AsyncStorage.getItem("token").then(async (res) => {
        access_token_receieved = await res;
        console.log('Access_Token from storage');
        console.log(access_token_receieved);
      });
        var that = this;
        var date = new Date().getDate(); //Current Date
        var month = new Date().getMonth() + 1; //Current Month
        var year = new Date().getFullYear(); //Current Year
        var hours = new Date().getHours(); //Current Hours
        var min = new Date().getMinutes(); //Current Minutes
        var sec = new Date().getSeconds(); //Current Seconds
        that.setState({
          //Setting the value of the date time
          date:
            date + '/' + month + '/' + year,
        });
    }
    fetchData(access_token_receieved) 
    {
      console.log('inside render');
      console.log('token inside :'+access_token_receieved);
      leavetype= this.state.choosenLabel;
      datepicker= this.state.chosenDate.toString().substr(3, 12);
      datepicker=moment(datepicker).format("DD-MM-YYYY");
      const { reason } = this.state;
      console.log(leavetype);
      console.log(datepicker);
      console.log(reason);
      console.log(access_token_receieved);
      var that = this;
      var url ='apiurl';
      console.log('url: '+url);
      fetch(url,{
          method: 'POST',
          headers: {
            Accept: 'application/json',
            'Content-Type':'application/json',
            'Authorization': 'Bearer '+ access_token_receieved,
          },
          body: JSON.stringify({
            "datepicker":datepicker,
            "leavetype": leavetype,
            "reason": reason
          })
        })
        .then(response => {

            if(response.status == 200){
              Alert.alert('Leave Request send');
              //this.setTimeout(() => this.props.navigator.navigate('LeaveScreen'), 5000);
              setTimeout(
                () => { this.props.navigation.navigate('LeaveScreen') },
                2000
              )
            } else{
              Alert.alert('Leave Request not send');
            }
            console.log('result: '+response.status);
        })
        .catch(function (error) {
          console.log("-------- error ------- "+error);
         alert("result:"+error)
        });
    }
    render() { 
      const { selectedStartDate } = this.state;
      const startDate = selectedStartDate ? selectedStartDate.toString() : '';
      const { navigation } = this.props.navigation; 
      return (
        <ScrollView style={styles.body}>

      <Text style={styles.taskItemHeader}>REQUEST LEAVE</Text>  
      <View style={styles.container}>
        <TouchableOpacity style={styles.buttonContainerRight}>
          <View >
          <Form>
            <Picker
              style={styles.taskItemContent}
              mode="dropdown"
              iosIcon={<Icon name="arrow-down" />}
              headerBackButtonText="Baaack!"
              selectedValue={this.state.choosenLabel}
              onValueChange={(itemValue, itemIndex) =>  
                this.setState({choosenLabel: itemValue, choosenIndex: itemIndex})} 
            >
            <Picker.Item label="Leave Type"/>
            <Picker.Item label="Casual Leave" value="1" />
            </Picker>
            </Form>
          </View>
        </TouchableOpacity> 
      </View>

      <View style={styles.container1}>
        <View style={styles.buttonContainerRight}>
          <View style={styles.middlecontainer}>
            <View style={styles.calenderContainerLeft}>
                <DatePicker
                style={styles.datepickerstyle}
                date={this.state.date}
                showIcon={false}
                hideText={true} 
                format="DD-MM-YYYY"
                showIcon = {true}
                modalTransparent={false}
                animationType={"fade"}
                placeHolderText={<Icon type="FontAwesome" name='calendar' style={styles.iconstyle} onPress={() => this.setDate}/>}
                onDateChange={this.setDate}
                disabled={false}
              />
            </View>
            <View style={styles.calenderContainerRight}>
              <Text onPress={this.setDate}>
            <Text note numberOfLines={1} style={styles.dateItemContent} disabled>{this.state.chosenDate.toString().substr(4, 11)}</Text>
            </Text>
            </View>
          </View>
        </View>  
      </View>


      <View style={styles.container}>
        <View style={styles.textinputContainerRight}>
          <TextInput style={styles.taskItemContent} multiline={true} placeholder='Reason for Leave..'></TextInput>
          </View> 
      </View>

      <View style={styles.btncontainer}>
        <TouchableOpacity style={styles.buttoncontainer} onPress={() => this.fetchData(access_token_receieved)}>
          <View>
            <Body style={styles.bodyStyle}>
              <Text note numberOfLines={1} style={styles.buttontemContent}>APPLY</Text>
            </Body>
          </View>
        </TouchableOpacity>
      </View>


      </ScrollView>
    );

  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems:'center',
    alignContent:'center',
    justifyContent:'center',
    paddingBottom:15,
},

container1: {
  flex: 1,
  flexDirection: 'row',
  alignItems:'center',
  alignContent:'center',
  justifyContent:'center',
  paddingBottom:15,
},

middlecontainer: {
  flex: 1,
  flexDirection: 'row',
  justifyContent: 'center',
  alignContent: 'center',
  paddingBottom:15,
},

btncontainer: {
  flex: 1,
  flexDirection: 'row',
  alignContent:'center',
  alignItems: 'center',
  justifyContent: 'center',
  paddingBottom:15,
},

buttoncontainer: {
  flex: 1,
  backgroundColor:'#a0bfff',
    alignContent:'center',
    justifyContent:'center',
    marginLeft:15,
    marginTop:0,
    marginRight:15,
    marginBottom:0,
    height:60,
    borderRadius:10,
    shadowColor: "#000",
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 0,
    },
    shadowOpacity: 0.50,
    shadowRadius: 12.35,
    elevation: 10,
},

containerLast: {
  flex: 1,
  flexDirection: 'row',
  alignItems: 'center',
  justifyContent: 'center',
  paddingBottom:25,
},
iconstyle:{
  fontSize: 35,
  color: '#a0bfff',
},
taskItemContent: { 
  color: 'black',
  fontSize: 15,
  marginLeft:10,
},
dateItemContent:{
  color: 'black',
  fontSize: 15,
  marginLeft:10,
},

datepickerstyle:{color:'white'},

buttontemContent: { 
  color: 'white',
  fontWeight:'bold',
  fontSize: 15,
  alignItems:'center',
},

bodyStyle:{
  borderWidth:0,
  justifyContent:'center',
},

textbodyStyle:{
  borderWidth:0,
  justifyContent:'center',
  alignContent:'flex-start',
},

taskItemHeader: { 
  color: 'black',
  fontSize: 25,
  alignContent:'flex-start',
  paddingBottom:15,
  paddingLeft:15,
},
buttonContainerLeft: {
    flex: 1,
    alignItems:'center',
    alignContent:'center',
    justifyContent:'center',
    marginLeft:15,
    marginTop:0,
    marginRight:0,
    marginBottom:0,
    backgroundColor: '#ffffff',
    height:120,

    borderRadius:8,
    shadowColor: "#000",
shadowColor: "#000",
shadowOffset: {
  width: 0,
  height: 0,
},
shadowOpacity: 0.50,
shadowRadius: 12.35,
elevation: 10,
},
buttonContainerRight: {
    flex: 1,
    alignContent:'center',
    justifyContent:'center',
    marginLeft:15,
    marginTop:0,
    marginRight:15,
    marginBottom:0,
    backgroundColor: '#ffffff',
    height:60,
    borderRadius:8,
    shadowColor: "#000",
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 0,
    },
    shadowOpacity: 0.50,
    shadowRadius: 12.35,
    elevation: 10,
},

textinputContainerRight: {
  flex: 1,
  alignContent:'flex-start',
  marginLeft:15,
  marginTop:0,
  marginRight:15,
  marginBottom:0,
  backgroundColor: '#ffffff',
  height:160,
  borderRadius:8,
  shadowColor: "#000",
  shadowColor: "#000",
  shadowOffset: {
    width: 0,
    height: 0,
  },
  shadowOpacity: 0.50,
  shadowRadius: 12.35,
  elevation: 10,
},

viewstyle1:{
  alignItems:'flex-start',
  alignContent:'center',
  justifyContent:'center',
},
viewstyle2:{
  alignItems:'flex-end',
  alignContent:'center',
  justifyContent:'center',
},

calenderContainerRight: {
  flex: 1,
  justifyContent:'center',
  alignItems:'flex-end',
  marginLeft:15,
  marginTop:0,
  marginRight:5,
  marginBottom:0,
  height:60,
  borderRadius:8,
},

calenderContainerLeft: {
  flex: 1,
  justifyContent:'center',
  marginLeft:5,
  marginTop:0,
  marginBottom:0,
  height:60,
  borderRadius:8,
},

calenderContainerRight1: {
  flex: 1,
  alignItems:'center',
  alignContent:'center',
  alignContent:'center',
  height:60,
  borderRadius:8,
},

textContainerRight: {
  flex: 1,
  alignItems:'center',
  alignContent:'center',
  justifyContent:'center',
  marginLeft:15,
  marginTop:0,
  marginRight:15,
  marginBottom:0,
  backgroundColor: '#ffffff',
  height:120,
  borderRadius:8,
  shadowColor: "#000",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 0,
},
shadowOpacity: 0.50,
shadowRadius: 12.35,
elevation: 10,
},

btn:{
  borderRadius:0,

},
body:{
  paddingTop:15,
  paddingBottom:30,
  backgroundColor: '#efefef',
}
});
export default RequestLeave
import React,{Component}来自'React';
从“react native”导入{Alert、Image、ScrollView、View、AppRegistry、StyleSheet、AsyncStorage、SafeAreaView、FlatList、ActivityIndicator、TouchableOpacity、Platform};
从“expo/build/Updates/Updates”导入{fetchUpdateAsync};
从“反应本机模式日期时间选择器”导入日期时间选择器;
从“反应本机日期选择器”导入日期选择;
从“反应本机手势处理程序”导入{TextInput};
从“时刻”中导入时刻;
从“本机库”导入{容器、标题、标签、按钮、内容、项、输入、文本区域、日期选择器、正文、标题、文本、图标、选择器、表单};
var datepicker='';
变量类型=“”;
var理性=“”;
var-access\u-token\u-received='';
var chosenDate='';
var newDate='';
类RequestLeave扩展组件{
状态={choosenLabel:'',choosenindex:''}
建造师(道具){
超级(道具);
this.state={
chosenDate:“”,
日期:'',
已选择:未定义,
日期选择器:“”,
原因:'',
类型:“”,
};
this.setDate=this.setDate.bind(this);
} 
设置日期(newDate)
{
this.chosenDate=新日期(),
this.setState({chosenDate:newDate});
}
onIconclick(){
//这个.setDate();
chosenDate=新日期()
this.setState({chosenDate:newDate});
}
onValueChange(值)
{
this.setState({choosenLabel:itemValue,choosenIndex:itemIndex})
}
componentDidMount(){
AsyncStorage.getItem(“令牌”)。然后(async(res)=>{
access_token_received=等待res;
log('Access_Token from storage');
console.log(已接收访问令牌);
});
var=这个;
var date=new date().getDate();//当前日期
var month=new Date().getMonth()+1;//当前月份
var year=新日期().getFullYear();//当前年份
var hours=new Date().getHours();//当前小时数
var min=new Date().getMinutes();//当前分钟数
var sec=new Date().getSeconds();//当前秒数
那是一个州({
//设置日期时间的值
日期:
日期+'/'+月+'/'+年,
});
}
获取数据(访问\u令牌\u已接收)
{
console.log(“内部渲染”);
console.log('内部令牌:'+访问\u令牌\u接收);
leavetype=this.state.choosenLabel;
datepicker=this.state.chosenDate.toString().substr(3,12);
datepicker=时刻(datepicker).format(“DD-MM-YYYY”);
const{reason}=this.state;
console.log(levetype);
日志(日期选择器);
控制台日志(原因);
console.log(已接收访问令牌);
var=这个;
var url='apiurl';
log('url:'+url);
获取(url{
方法:“POST”,
标题:{
接受:'application/json',
“内容类型”:“应用程序/json”,
“授权”:“持有人”+访问令牌,
},
正文:JSON.stringify({
“日期选择器”:日期选择器,
“leavetype”:leavetype,
“理由”:理由
})
})
。然后(响应=>{
如果(response.status==200){
警报。警报(“请假请求发送”);
//this.setTimeout(()=>this.props.navigator.navigate('LeaveScreen'),5000);
设置超时(
()=>{this.props.navigation.navigate('LeaveScreen')},
2000
)
}否则{
警报。警报(“休假请求未发送”);
}
console.log('result:'+response.status);
})
.catch(函数(错误){
console.log(“-----error------”+error);
警报(“结果:+错误)
});
}
render(){
const{selectedStartDate}=this.state;
const startDate=selectedStartDate?selectedStartDate.toString():“”;
const{navigation}=this.props.navigation;
返回(
请假
this.setState({choosenLabel:itemValue,choosenIndex:itemIndex})}
>
}
onDateChange={this.setDate}
禁用={false}
/>
{this.state.chosenDate.toString().substr(4,11)}
this.fetchData(access\u token\u received)}>
申请
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
flexDirection:'行',
对齐项目:'中心',
对齐内容:'中心',
辩护内容:'中心',
填充底部:15,
},
集装箱1:{
弹性:1,
flexDirection:'行',
对齐项目:'中心',
对齐内容:'中心',
辩护内容:'中心',
填充底部:15,
},
中间集装箱:{
弹性:1,
flexDirection:'行',
为内容辩护:“中心”,
对齐内容:“中心”,
填充底部:15,
},
BTN容器:{
弹性:1,
flexDirection:'行',
对齐内容:'中心',
对齐项目:“居中”,
为内容辩护:“中心”,
填充底部:15,
},
按钮容器:{
弹性:1,
背景色:'#a0bff