Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to select item from react-native-dropdown-picker

am using React-native-dropdown-picker, however am unable to select any item from the dropdown list, the items are being overlapped by the below view. I have tried adding position:'absolute, zIndex:2 but still the itemlist is being overlapped as follows: enter image description here

I have written the code for dropdown component as follows

 return (
    <View>
      <View style={styles.container}>
        {console.log('new array', dateArr)}
        {console.log('arr', arr)}
        <Icon
          name="arrow-left"
          size={20}
          color="#fff"
          style={{marginTop: 12}}
        />
        {console.log('----------date', dateArr)}
        {dateArr != null && (
          <DropDownPicker
            onValueChange={(value) => onValSelect(value)}
            items={dateArr}
            itemStyle={{
              // justifyContent: 'flex-start',
              flexDirection:'row'
            }}
            
            containerStyle={{height: 40,width:'80%',zIndex:2}}
          />
        )}
       
      </View>
      <DaysInAWeek daysInAWeek={daysInAWeek} />
    </View>
  );
}
const styles = StyleSheet.create({
  container: {
    backgroundColor: '#FE017E',
    // height: 56,
    width: '100%',
    flexDirection: 'row',
    padding: 10,
  },
});

onValSelect() is as follows:

 function onValSelect(val) {
    if (val.length > 1) {
      let arr = [];
      for (let i = val[0]; i <= val[1]; i += 86400000) {
        let date = getMonthDate(new Date(i));
        arr.push(date);
      }

      console.log('final arr', arr);
      setDaysInAWeek(arr);
    } else {
      console.log('single date', new Date(val));
      setDaysInAWeek(new Date(val));
    }
  }

please let me know the issue any help would be appreciated.

like image 646
TRINA CHAUDHURI Avatar asked Nov 25 '20 06:11

TRINA CHAUDHURI


3 Answers

If somebody still didn't get this, here something I found This is all related to the parent element, so if DropDownPicker component does not have a parent element with some height then this would not let you select even if you see the options.

just give parent element minHeight:300px or any height you want Example -

<View style={{minHeight: 300}}>
          
             <DropDownPicker
               items={timeslots}
               defaultValue={this.state.selected2}
               containerStyle={{height: 40}}
               style={{backgroundColor: '#fafafa'}}
               itemStyle={{
                 justifyContent: 'flex-start',
               }}
               dropDownStyle={{backgroundColor: '#fafafa'}}
               onChangeItem={(item) => 
                 this.setState({
                   selected2: item.value,
                 });
               }
             />
        
         </View>

like image 146
DEEPAK Avatar answered Nov 15 '22 04:11

DEEPAK


I solved this problem in this way:

const [open, setOpen] = useState(false);
      ...
<View style={[style.viewContainer, Platform.OS === 'android' && open && style.androidContainer]}>
      <DropDownPicker
        open={open}
        setOpen={setOpen}
...

styles:

   viewContainer: { marginHorizontal: 16, zIndex: 1 },
    androidContainer: {
      minHeight: 500,
      marginBottom: -428,
    },
like image 45
Дмитрий Б Avatar answered Nov 15 '22 06:11

Дмитрий Б


 <View style={{ zIndex: 999}}>
       <DropDownPicker
           ...
         />
    
adding Zindex for View worked for me
like image 21
Sjs Ahd Avatar answered Nov 15 '22 06:11

Sjs Ahd