hossein-zare / react-native-dropdown-picker

A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.
https://hossein-zare.github.io/react-native-dropdown-picker-website/
MIT License
991 stars 296 forks source link

Loading true and items=[] does not show ActivityIndicator #649

Closed sakshambhatt closed 1 year ago

sakshambhatt commented 1 year ago

Hello, I was unable to see the ActivityIndicator when items was an empty array and loading true while fetching data from API. So, I tried to invoke the component is loading=true and items=[]. It still doesn't show the ActivityIndicator. Could someone please help?

const TzActivityIndication = useCallback(
    ({color, size}: {color: string; size: number}) => (
      <ActivityIndicator color={color} size={size} />
    ),
    [],
  );

return (<DropDownPicker
        open={isOpen}
        setOpen={setIsOpen}
        value={currentTzValue}
        setValue={setCurrentTzValue}
        items={[]}
        loading={true}
        searchable={true}
        listMode="MODAL"
        style={styles.dropdown}
        containerStyle={styles.dropdownContainer}
        itemSeparator={true}
        itemSeparatorStyle={{
          backgroundColor: colors.inputBorderColor,
        }}
        listItemContainerStyle={styles.listItemContainer}
        ActivityIndicatorComponent={TzActivityIndication}
        activityIndicatorColor={colors.secondaryColor}
        activityIndicatorSize={30}
      />)

Screenshot: image

Similar issues: Issue 473, Issue 485

hossein-zare commented 1 year ago

Hi, It worked, Start with a simple picker and add additional props one by one.

sakshambhatt commented 1 year ago

Sorry to have missed your comment. Will try this out today, and share my findings with you

sakshambhatt commented 1 year ago

I have created a simple component, where the data is fetched from an API. While the promise is in progress, loading is true. And once the promise is settled, the loading state becomes false. I have added another ActivityIndicator for reference which works fine. Could you please tell me if I am doing something wrong?

Component github link I am attaching a recording of this component below for your reference: dropdown

Thanks for your help!

hossein-zare commented 1 year ago

Press the picker (Select an item) while loading is true. You'll see an ActivityIndicator.

// Set the open state to TRUE for testing so you don't need to press the picker
const [open, setOpen] = useState(true);

Important! Your items state MUST be empty. You always see the Select an item message whether loading is true.

sakshambhatt commented 1 year ago

Thank you for clearing it up. Here is how the ActivityIndicator looks dd1