NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Dynamic Card Support in Native base 2.0.0

Open singhiam opened this issue 9 years ago • 7 comments

Hi,

I have upgraded Native base to latest one but I am unable to repeat Cards. Please help me to solve this.

Thanks,

singhiam avatar Feb 16 '17 10:02 singhiam

It is very similar to List, in the way they are iterated. Please check here

sankhadeeproy007 avatar Feb 16 '17 10:02 sankhadeeproy007

@sanketsahusoft can you provide code snippet for dynamic List of Cards.

iiitmahesh avatar Mar 28 '17 07:03 iiitmahesh

I think you meant @sankhadeeproy007

sanketsahu avatar Mar 28 '17 08:03 sanketsahu

oh its typo mistake. yep I meant @sankhadeeproy007

iiitmahesh avatar Mar 28 '17 10:03 iiitmahesh

@sankhadeeproy007 passing an array to dataArray and a function to renderRow in a <Card> component throws Warning: Failed prop type: Invalid prop `dataArray` of type `array` supplied to `Card`, expected `object and Warning: Failed prop type: Invalid prop `renderRow` of type `function` supplied to `Card`, expected `object respectively.

Those are only warnings, so it's still displayed correctly, but before 2.0 I was not getting those warnings.

stefano-DM avatar Mar 30 '17 14:03 stefano-DM

Same warning as @stefano-DM for dataArray (array) and renderRow (function) Can someone share a working dynamic card snippet? (Nativebase >= 2.0)

rithvikvibhu avatar Apr 08 '17 11:04 rithvikvibhu

I was able to solve this by using <List dataArray{arr} renderRow{(item) => ... }> //Card stuff goes here </List>.

I think <Card dataArray & renderRow> expects object as seen from here and here.

But with giving data to <List> this problem can be easily escaped.

const StudentCard = props => {
    const { data, gotoStudent } = props

    return (
        <List dataArray={data} renderRow={(item) =>
            <Card>
                <CardItem header>
                    <Text style={{fontWeight: 'bold'}}>
                        {item['school_name']}
                    </Text>
                </CardItem>
                <CardItem cardBody>
                    <Col>
                        <Text>
                            {item['student_name']}
                        </Text>
                    </Col>
                    <Col>
                        <Text>
                            {item['school_number']}/{item['student_number']}/{item['examYear']}
                        </Text>
                    </Col>
                </CardItem>
                <CardItem footer>
                    <Text>
                        {item['examType']}
                    </Text>
                </CardItem>
            </Card>
        }>
        </List>
    )
}

Got the idea from this dude's code

maotora avatar Jun 24 '17 08:06 maotora