skip to Main Content

I have been simply trying to render a card from react-native-elements UI library. Here is the documentation that I’ve been looking through and literally copied and pasted from: https://reactnativeelements.com/docs/1.2.0/card

Here is my Deal component:

import { View } from 'react-native'
import { Card, ListItem } from 'react-native-elements'

const Deal = () => {
    const users = [
        {
            name: 'brynn',
            avatar: 'https://www.w3schools.com/howto/img_avatar2.png',
        },
    ]
    return (
        <View>
            <Card containerStyle={{ padding: 0 }}>
                {users.map((u, i) => {
                    return (
                        <ListItem
                            key={i}
                            roundAvatar
                            title={u.name}
                            leftAvatar={{ source: { uri: u.avatar } }}
                        />
                    )
                })}
            </Card>
        </View>
    )
}

export default Deal

Here is my SecondScreen component in which I am trying to render Deal:

import { StyleSheet, Text, View } from 'react-native'
import Step from '../components/Step'
import MyCarousel from '../components/MyCarousel'
import Ratings from '../components/Ratings'
import Deal from '../components/Deal'

export default function SecondScreen({ route, navigation }) {
    const { image } = route.params

    return (
        <>
            <View>
                <Text
                    style={{ fontSize: '16px', marginLeft: 10, marginTop: 15 }}
                >
                    Daily Deals
                </Text>
                <View
                    style={{
                        borderBottomColor: 'black',
                        borderBottomWidth: StyleSheet.hairlineWidth,
                    }}
                />
                <View style={{ marginTop: 10 }}>
                    <Deal />
                </View>
            </View>
        </>
    )
}

Here is what it renders at the end:

enter image description here

Any help would be appreciated!

Edit: I have decided to use another component in the meantime. This seems like possibly deprecated component or something.

2

Answers


  1. Try adding flex or height for <View />

    <View style={{ flex: 1, marginTop: 10 }}>
        <Deal />
    </View>
    
    Login or Signup to reply.
  2. Inside your Deal component, you have a <View /> wrapper around the <Card /> component. The one inside Deal file, NOT the one wrapping it in SecondScreen file.

    Have you tried removing that excess <View />?

    If you want to keep that <View />, have you tried giving that specific <View /> a style={{ height: 100px }} or style={{ flex: 1 }} property?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search