React Native Dropdown Picker , view full dropdown list

473 views Asked by At

I cannot scroll the page , so i need to view all the dropdown items in the menu, how do i do it ? here is my code. Any one solution : One i need a way to scroll down the page or I need to view all the items in dropdown at once.

<DropDownPicker
          open={open1}
          value={value1}
          items={items1}
          setOpen={setOpen1}
          setValue={setValue1}
          setItems={setItems1}
          containerStyle={{
            height: 40,
            width: "100%",
            marginBottom: 20,
            zIndex: 3,
          }}
          style={styles.dropdown}
          itemStyle={styles.dropdownItem}
          dropDownStyle={styles.dropdownDropdown}
          dropDownContainerStyle={{
            height: "600%",
          }}
        />

The height 600% is not working with any values its max is only 500%, Please help me, thanks : )

1

There are 1 answers

2
prabu naresh On

Adjust the Dropdown Height:

<DropDownPicker
  // ... other props ...
  dropDownItemStyle={{ 
    justifyContent: 'flex-start', // Adjust the alignment of items if needed
    height: 60, // Adjust this height as needed
  }}
/>

Implement Scrollable Dropdown:

import { ScrollView } from 'react-native';

<DropDownPicker
  // ... other props ...
  customDropDown={() => (
    <ScrollView>
      <DropDownPicker
        open={open1}
        value={value1}
        items={items1}
        setOpen={setOpen1}
        setValue={setValue1}
        setItems={setItems1}
        containerStyle={{
          height: 40,
          width: "100%",
          marginBottom: 20,
          zIndex: 3,
        }}
        style={styles.dropdown}
        itemStyle={styles.dropdownItem}
        dropDownStyle={styles.dropdownDropdown}
        dropDownContainerStyle={{
          height: 300, // Adjust the height to your preference
        }}
      />
    </ScrollView>
  )}
/>

In this approach, the customDropDown property is used to wrap the DropDownPicker inside a ScrollView to enable scrolling within the dropdown.