React Native VirtualizedList不应嵌套在具有相同方向的普通ScrollView内-请改用其他VirtualizedList支持的容器

0ejtzxu1  于 2023-01-27  发布在  React
关注(0)|答案(3)|浏览(576)

我正在使用react-native-google-places-autocomplete软件包进行google place自动完成文本输入。但是在这里我每次点击地址后都会收到警告。

警告:

VirtualizedList不应嵌套在具有相同方向的普通ScrollView中-请改用另一个VirtualizedList支持的容器。
我应该使用的另一个VirtualizedList支持的容器是什么?为什么现在建议不要这样使用它?
我已经为此创建了一个自定义组件,下面我正在添加GooglePlacesInput组件的渲染内的代码::

class GooglePlacesInput extends PureComponent {
  //..... other function

  // render function
  render() {
    const { placeholder, minSearchLen, address, name, enablePoweredByContainer, currentLocation, onChangeText } = this.props;
    return (
      <GooglePlacesAutocomplete
        placeholder={placeholder}
        name={name}
        minLength={minSearchLen}
        autoFocus={false}
        returnKeyType={'search'} // Can be left out for default return key https://facebook.github.io/react-native/docs/textinput.html#returnkeytype
        keyboardAppearance={'light'} // Can be left out for default keyboardAppearance https://facebook.github.io/react-native/docs/textinput.html#keyboardappearance
        listViewDisplayed="false"   // true/false/undefined
        fetchDetails={true}
        getDefaultValue={() => address}
        renderDescription={row => row.description} // custom description render
        onPress={(data, details = null) => this.onPressAddress(data, details)}
        onNotFound={() => { }}
        query={{ key: GOOGLE_API_KEY }}
        currentLocation={currentLocation} // Will add a 'Current location' button at the top of the predefined places list
        currentLocationLabel="Current location"
        nearbyPlacesAPI="GooglePlacesSearch"
        textInputProps={{
          onChangeText: onChangeText,
        }}
        enablePoweredByContainer={enablePoweredByContainer}
        isRowScrollable={false}
        styles={{
          textInputContainer: {
            backgroundColor: 'rgba(0,0,0,0)',
            borderTopWidth: 0,
            borderBottomWidth: 0,
            width: '100%',
            marginBottom: 20,
          },
          textInput: {
            paddingHorizontal: 18,
            height: 40,
            color: Colors.grey,
            fontSize: 16,
          },
          predefinedPlacesDescription: {
            color: '#1faadb',
          },
        }}
      />
    );
  }
}

// default props values
GooglePlacesInput.defaultProps = {
  name: 'address',
  placeholder: 'Enter Address',
  minSearchLen: 2,
  address: '',
  enablePoweredByContainer: true,
  currentLocation: false,
  onChangeText: '',
};

export { GooglePlacesInput };

在另一个组件中调用它,如下所示:

<Content
contentContainerStyle={[flexGrow1, p10]}
>
  <View style={[alignItemsCenter, pt20, pb30]}>
    <ImageView source={Images.mapIcon} style={{ height: Base.getPixel('4.5rem'), width: Base.getPixel('4.5rem') }} />
  </View>
  <Formik
    initialValues={this.initialValues}
    onSubmit={(data) => this.onSubmitForm(data)}
    ref={el => (this.form = el)}
    validationSchema={validationSchema}
    isSubmitting={true}
    render={({ handleSubmit, values, setValues, setFieldValue, errors, touched, ...props }) => {
      return (
        <Form>
          <GooglePlacesInput
            onPress={(data, detail) => this.onPressOfAddress(data, detail)}
            address={values.address}
            name="address"
            onChangeText={(value) => setFieldValue('address', value)}
          />
          <Button onPress={() => popScreen(this.props.componentId)} block large variant="danger">CANCEL</Button>
        </Form>
      );
    }}
  />
</Content>

当我点击自动完成时,它出现了。
请给我建议解决这个问题的办法,或者给我建议一些其他的包,它的东西比这个更好。
此警告来自此程序包的主文件。

iqih9akk

iqih9akk1#

我在使用native('from react-native')ScrollView和ListItem(from react-native-elements)时也遇到了同样的问题。

<View>
    <ScrollView>
        <View> {
            data.map((l, i) => (
                <ListItem key={i}/>
            ))}
        </View>
    </ScrollView>
</View>
3zwtqj6y

3zwtqj6y2#

这并不能解决问题,但如果您不认为真的有问题,它可以消除警告。
将其添加到文件的顶部。

import { YellowBox } from 'react-native';

YellowBox.ignoreWarnings(['VirtualizedLists should never be nested']);
rsl1atfo

rsl1atfo3#

UPDATE忽略警告

import { LogBox } from 'react-native';

LogBox.ignoreLogs(['VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.']);

相关问题