gpt4 book ai didi

react-native - VirtualizedLists 不应该嵌套在具有相同方向的普通 ScrollViews 内 - 使用另一个 VirtualizedList-backed 容器代替

转载 作者:行者123 更新时间:2023-12-03 14:08:27 26 4
gpt4 key购买 nike

我正在使用 react-native-google-places-autocomplete用于谷歌地方自动完成文本输入的包。但是在这里我每次点击地址后都会收到警告。

警告::

VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.



我应该使用的另一个 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>

当我点击自动完成时它会出现。

请建议我摆脱这个问题的解决方案,或者建议我一些其他包,它比这更好。

此警告来自此包的主文件。

最佳答案

我在使用 native ('来自 react-native')ScrollView 和 ListItem(来自 react-native-elements)时遇到了同样的问题。解决了它用 View 组件包装的问题:

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

关于react-native - VirtualizedLists 不应该嵌套在具有相同方向的普通 ScrollViews 内 - 使用另一个 VirtualizedList-backed 容器代替,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59098956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com