React Native: предупреждение «Виртуализированные списки никогда не должны быть вложены в простые ScrollViews ..» - PullRequest
1 голос
/ 30 апреля 2020

У меня проблема с моими <ScrollView> и <GooglePlacesAutocomplete> компонентами.

Ссылка на GIF текущего выпуска

После просмотра короткого GIF вы можете заметить, что я получаю предупреждение:

VirtualizedLists никогда не следует вкладывать в простые ScrollViews с той же ориентацией - используйте вместо этого другой контейнер с поддержкой VirtualizedList.

Кроме того, когда я пытаюсь нажать на Даллас, Техас, США, ничего не происходит.
Если бы я должен был удалить компонент <ScrollView>, то, когда я щелкаю по месту, он проходит без проблем.

Вот мой код:

    import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete'; 

    [...] //code removed from brevity

    return(
    <SafeAreaView style={styles.fullPage}>   
    <ScrollView
     stickyHeaderIndices={[0]} >
        <Header/> 
        <View style={styles.container}>

            <Text>Search for fun near you</Text>

            <View style = {styles.firstLine}>
                <Text>On </Text>

                <TouchableOpacity onPress={showDatepicker}><MaterialCommunityIcons name="alarm" color={'orange'} size={25} spin={true} /></TouchableOpacity>
                    {show && (
                    <DateTimePicker
                        testID="dateTimePicker"
                        timeZoneOffsetInMinutes={0}
                        value={date}
                        mode={mode}
                        display="default"
                        onChange={onChange}
                    />)}

            </View>
                <Text style={styles.txt}>Date: {date.toDateString()}</Text>
            <View style = {styles.secondLine}>
                <Text>Within </Text>
                <ModalDropdown 
                    defaultValue='Pick a mile' options={["5", '10','20','50', '75']}
                    onSelect= {(index,value)=>{
                        setMiles(value);
                    }}
                    style = {styles.mileageDropdown}>  
                </ModalDropdown>
                <Text> miles of </Text>

            </View>

            <View style = {styles.thirdLine}>
            <GooglePlacesAutocomplete
                         placeholder='Insert place to find'
                         minLength={2}
                         keyboardAppearance={'light'}
                         fetchDetails={false} 
                         onPress={(data, details = null) => { // 'details' is provided when fetchDetails = true
                             {setPlace(data.description)}
                            }}                 
                            styles={{
                            textInputContainer: {
                                backgroundColor: 'rgba(0,0,0,0)',
                                borderTopWidth: 0,
                                borderBottomWidth:0,
                                width: '100%',
                                },
                             textInput: {
                                fontSize: 16
                                },
                            }}

                            query={{
                                key: 'SomeAPIkey',
                                language: 'en', // language of the results
                              }}
                        />
            </View>      

            <View style={styles.btn}>
                <TouchableOpacity onPress={handlePress} style={styles.btnSearch}><Text style={styles.txtbtn}>Search</Text></TouchableOpacity>
            </View>
            </View>




            {arr.map((item, key)=>(  
                <Card key={key}>                
                         <View style={styles.cardFirstLine}><Text>{item.user}</Text><Text style={{marginLeft:40}}>{item.location}</Text></View>
                         <View><Text>{item.datePosted}</Text></View>
                         <View style={styles.cardImage}></View>
                         <View><Text>{item.description}</Text></View>
                         <View><Text>{item.eventDate}</Text></View>
                         <View><Text>{item.comments}</Text></View>         
                </Card>
                ))}

     </ScrollView>
    </SafeAreaView>
)}              

        const styles = StyleSheet.create({
            fullPage:{
                flex:1,
            },
            container:{
                paddingTop:65,
                margin: 10,
                alignItems: 'center'
            },
            firstLine:{
                flexDirection: "row",
                alignContent: "center",
                padding: 10,
                alignItems : 'center'
            },
            secondLine:{
                flexDirection: "row",
                padding: 10,
                alignItems : 'center'
            },
            thirdLine:{
                flexDirection: "row",
                padding: 10,
                alignItems : 'center',
                justifyContent: 'center',
            },
            datepicker:{
                paddingLeft:10,
                paddingTop:5
            },
            mileageDropdown:{
                borderColor: 'black',
                borderWidth: StyleSheet.hairlineWidth,
                padding:5,
                paddingTop:5
            },
            btn:{
                paddingTop:10
            },
            btnSearch:{ 
                backgroundColor: 'purple',
                padding:20,
                margin:20,
                width: 100,
                justifyContent: 'center',
                alignItems: 'center',
                borderRadius : 5,
            },
            txtbtn:{
                fontWeight: 'bold',
                fontSize: 14,
                color: 'orange'
            },
            place:{
                marginTop: 30,
                padding: 10,
                borderColor: "red",
                borderWidth: StyleSheet.hairlineWidth
            },
            displayImage:{
                width:200,
                height:200,
                padding:40,
                borderBottomWidth: StyleSheet.hairlineWidth,
                borderColor: "red",
            },  
            txt:{
                borderBottomWidth: StyleSheet.hairlineWidth,
                borderColor: 'black',

            },
            cardFirstLine:{
                padding: 5,
                flexDirection:'row',
            },
            cardImage:{
                paddingTop: 15,
                borderWidth: StyleSheet.hairlineWidth,
                borderColor: 'black',
                width: '75%',
                height:100,

            }
        }); 

Я просмотрел большинство сообщений StackOverflow по этому поводу, но мне не удалось решить проблему с моей стороны.
Может кто-нибудь помочь мне понять, что не так с этим интерфейсом?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...