Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native FlatList nested inside FlatList with same orientation

I Cant create FlatList nested inside FlatList with same orientation;

the result is that the parent is horizontal but the children are vertical;

this is my code:

renderSlides(question) {
    return <View key={question.item.code}
                 style={{flex: 1,width:350}}>
        <FlatList
            ref='scrollPick'
            data={[{k:'A'},{k:'b'},{k:'c'}}]}
            horizontal={true}
            renderItem={(rate)=>{return (
                <View >
                    <Text>{rate.item.k}</Text>
                </View>);}}
            keyExtractor={ (item, index) => index}
        />
    </View>;
}

render() {
    return (
        <View style={CONTAINERS.MAIN_COLUMN_BLUE}>
            <View style={[NAV.CONTAINER_GENERAL, NAV.CONTAINER_ASSESSMENT, {flex: 1}]}>
                <TopBar barType="ex" title={I18n.t('assessment.title')} navigator={this.props.navigator}
                        closeFunction={this.handleClose}></TopBar>
            </View>
            <FlatList
                ref={(ref) => { this.flatListRef = ref; }}
                horizontal={true}
                data={[{k:'1'},{k:'2'},{k:'3'},{k:'4'},{k:'5'},{k:'6'},{k:'q'}]}
                renderItem={this.renderSlides}
                keyExtractor={(item, index) => index}
                horizontal={true}
                getItemLayout={this.getItemLayout}
                contentContainerStyle={{ flexGrow: 1}}
            />
        </View>
    );
}

enter image description here

Has anyone run into this same problem? ( And I can't use scrollView )

like image 736
Aharon Vishinsky Avatar asked Apr 05 '18 10:04

Aharon Vishinsky


People also ask

Should never be nested inside plain ScrollViews with the same orientation?

VirtualizedLists should never be nested inside plain ScrollViews with the same orientation because it can break windowing and other functionality - use another VirtualizedList-backed container instead.

What is the difference between FlatList and SectionList?

SectionList s are like FlatList s, but they can have section headers to separate groups of rows. SectionList s render each item in their input sections using the renderSectionHeader and renderItem prop.


1 Answers

Finally I have found it!

The First FlatList you import from react-native

import {FlatList} from 'react-native'

And the second (inside-FlatList) you can import from react-native-gesture-handler

import {FlatList as FlatList2} from 'react-native-gesture-handler'

Then you can use the same orientation and it will work.

like image 56
Бабенко Дмитрий Avatar answered Sep 20 '22 02:09

Бабенко Дмитрий