iOS Development

ios – Scrolling Difficulty with react-native-element-dropdown in a Kind

Spread the love


I’m presently utilizing the react-native-element-dropdown library in a kind, and I am dealing with a problem with scrolling when the dropdown is targeted. This is the issue:

After I concentrate on the dropdown, the listing does not transfer with the choose enter, and it stays within the outdated place

export const PurchaseProjectPage = ({route}: PropertyPageProps) => {
  const {goBack, navigate} = useNavigation();
  const scrollViewRef = useRef<ScrollView>(null);

  return (
    <View model={kinds.globalContainer}>
      <KeyboardAvoidingView
        conduct={Platform.OS === 'ios' ? 'padding' : 'peak'}
        model={kinds.contentContainerStyle}>
        <ScrollView
          contentContainerStyle={kinds.containerPurchasePage}
          keyboardShouldPersistTaps="dealt with"
          ref={scrollViewRef}>
          <IText.Textual content
            id="mission.common.data"
            model={kinds.pageTitle}
          />
          <View model={kinds.formatField}>
            <Controller
              identify="filterCriteria.classes"
              management={strategies.management}
              render={({discipline, fieldState: {error}}) => {
                return (
                  <>
                    <ISelect.MultipleSelect
                      {...discipline}
                      choices={propertyType(t)}
                      label={t('property.mission.kind')}
                      placeholder={t('frequent.choose')}
                      scrollViewRef={scrollViewRef}
                    />
                    {error && (
                      <IText.Textual content
                        model={kinds.errorText}
                        content material={error.message}
                      />
                    )}
                  </>
                );
              }}
            />
          </View>

          <View model={kinds.formatField}>
            <Controller
              identify="filterCriteria.metropolis"
              management={strategies.management}
              render={({discipline}) => {
                return (
                  <ISelect.MultipleSelect
                    {...discipline}
                    choices={buildCityOptions(cities)}
                    label={t('property.mission.metropolis')}
                    search
                    placeholder={t('frequent.choose')}
                    scrollViewRef={scrollViewRef}
                  />
                );
              }}
            />
          </View>
      </KeyboardAvoidingView>
    </View>
const MultipleSelect: FC<Props> = ({
  worth,
  onChange,
  choices,
  placeholder,
  search,
  disabled = false,
  label,
  required = false,
  searchQuery,
  scrollViewRef,
}) => {
  const [isClicked, setIsClicked] = useState(true);

  const onfocus = () => {
    scrollViewRef?.present &&
      scrollViewRef.present.scrollTo({y: 300, animated: true});
    setIsClicked(!isClicked);
  };

  const onBack = () => {
    setIsClicked(!isClicked);
  };

  return (
    <>
      <View model={kinds.labelContainer}>
        {!!label && <IText.Textual content content material={label} model={kinds.label} />}
        {required && <IText.Textual content content material={'*'} model={kinds.asterisk} />}
      </View>

      <MultiSelect
        searchQuery={searchQuery}
        model={kinds.dropdown}
        placeholderStyle={kinds.placeholderStyle}
        selectedTextStyle={kinds.selectedTextStyle}
        inputSearchStyle={kinds.inputSearchStyle}
        iconStyle={kinds.iconStyle}
        search={search}
        information={choices}
        labelField="label"
        valueField="worth"
        placeholder={placeholder}
        worth={worth}
        onChange={_value => {
          onChange(_value?.consists of(ALL) ? [] : _value);
        }}
        selectedStyle={kinds.labelSelected}
        activeColor={Colours.Primary.gray}
        disable={disabled}
        alwaysRenderSelectedItem
        onFocus={onfocus}
        onBlur={onBack}
      />
    </>
  );
};

enter picture description right here

I anticipate the dropdown listing to scroll to the highest when it’s targeted, guaranteeing that the chosen choice is seen.

I admire any assist or strategies on the right way to resolve this scrolling problem. Thanks prematurely!

Leave a Reply

Your email address will not be published. Required fields are marked *