Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Card Body #1255

Open
HridayK97 opened this issue Oct 1, 2020 · 17 comments
Open

Custom Card Body #1255

HridayK97 opened this issue Oct 1, 2020 · 17 comments
Assignees

Comments

@HridayK97
Copy link

💬 Question

Looking at the documentation, it seems like the Card component is designed for only as the main content. Is there a way to enable a custom flex content inside as well? I tried using a custom layout with as the child, but the layout is not showing up correctly, and flex is not having the expected behavior.

UI Kitten and Eva version

Package Version
@eva-design/eva 2.0.0
@ui-kitten/components 5.0.0
@artyorsh
Copy link
Collaborator

artyorsh commented Oct 8, 2020

What do you mean with custom flex? Could you please also provide a sample code?

@parkerqueen
Copy link

parkerqueen commented Oct 11, 2020

@artyorsh

If you run the code below, you'd see the child components of Card do not follow the flexDirection: 'row' property but rather stubbornly get rendered in a column.

import React from 'react';
import { Image, StyleSheet, View } from 'react-native';
import { Card, Text } from '@ui-kitten/components';

export const WriterItem = (props) => {
    return (
        <Card style={styles.card}>
            <View>
                <Image source={props.source} style={styles.cover}></Image>
            </View>
            <Text category="h5">The Vampire</Text>
        </Card>
    );
};

const styles = StyleSheet.create({
    card: {
        width: '95%',
        display: 'flex',
        flexDirection: 'row',
    },
    cover: {
        width: 60,
        height: 60,
    },
});

@eyalyoli
Copy link

eyalyoli commented Nov 1, 2020

I'm having wired behavior same as @parkerqueen with flex props on a card. It doesn't respect all flex related props!

@artyorsh
Copy link
Collaborator

artyorsh commented Nov 2, 2020

This all happens due to this line.
I agree that this is not expected behavior and as a workaround which covers every styling use cases my only suggestion would be using the structure like this:

const MyCard = ({ contentContainerStyle, children, ...props }) => (
  <Card {...props}>
    <View style={[{ marginHorizontal: -24, marginVertical: -16 }, contentContainerStyle]}>
      {children}
    </View>
  </Card>
);

Also covers #1037. See an example

@eyalyoli
Copy link

eyalyoli commented Nov 3, 2020

What you suggested dosen't work on android. At least flex direction had no effect.
I found out that when you set a fixed height & width for the root body view, it solves the problems of flex direction.
I tried using '100%' on height & width it doesn't work. And you can't use flex=1 for cards body 🤦.
So it is a fixed size only.

@artyorsh
Copy link
Collaborator

artyorsh commented Nov 3, 2020

@eyalyoli I had just launched the example by the link I shared to clarify this and it worked. Could you please try that?

@eyalyoli
Copy link

eyalyoli commented Nov 3, 2020

@artyorsh sorry for not beign specific. Using your code and chaning it to:

<MyCard 
            style={{ marginVertical: 8, flex:1 }}
            contentContainerStyle={{ flex:1, flexDirection: 'row', justifyContent:'center', alignItems:'center' }}>
...
</MyCard>

flex on the card takes effect, but not on the body. This works as if card's body had no height. But when you set height=400 you'll get the needed results. I was wrong, the same issue effects web view.

Hope you could help with that.

@artyorsh
Copy link
Collaborator

artyorsh commented Nov 3, 2020

@eyalyoli could you please clarify then which result you need to achieve?

@eyalyoli
Copy link

eyalyoli commented Nov 3, 2020

This is the behaviour of card (top) vs view (bottom) with the same prop styling:
image

I tried to make the view in the same structure as the card. The problem is that flex: 1 is not working as you would think in a View.
Card code:

<MyCard
            style={{ marginVertical: 8, flex: 1 }}
            contentContainerStyle={{
              flex: 1,
              flexDirection: 'row',
              justifyContent: 'center',
              alignItems: 'center',
            }}>
            <Image
              style={{ width: 80, height: 80 }}
              source={{
                uri:
                  'https://akveo.github.io/react-native-ui-kitten/images/Artboard-1.png',
              }}
            />
            <Text style={{ margin: 12 }} category="h5">
              Title
            </Text>
            <Text style={{ margin: 12 }}>
              Text Text
            </Text>
</MyCard>

View code:

 <View style={{ marginVertical: 8, flex: 1 }}> //this is the card
            <View //this is the root view that used in the card
              style={{
                flex: 1,
                flexDirection: 'row',
                justifyContent: 'center',
                alignItems: 'center',
                borderWidth: 2,
              }}>
              <Image
                style={{ width: 80, height: 80 }}
                source={{
                  uri:
                    'https://akveo.github.io/react-native-ui-kitten/images/Artboard-1.png',
                }}
              />
              <Text style={{ margin: 12 }} category="h5">
                Title
              </Text>
              <Text style={{ margin: 12 }}>
              Text Text
            </Text>
            </View>
</View>

This is just an example of a more complex case in which I have an image as a header & other information in the body of a card and I need to make it scale dynamiclly with different screen sizes (using flex).

@eyalyoli
Copy link

@artyorsh should I reopen this as a bug?
I noticed that when flex in footer seems to work fine.

@eyalyoli
Copy link

Ok, for everyone who needs complex card content that is very responsive to screen size, I managed to do so using my own card implementation.

<View
      style={[
        {
          borderRadius: 15,
          borderWidth: 1,
          margin: 20,
          borderColor: theme["color-basic-300"],
          overflow: "hidden",
          flex: 1,
        },
        style,
      ]}
    >
      <View>{header()}</View>
      <View> // 1
        <View>{children}</View>
        <Divider />
        <View>{footer()}</View>
      </View>
    </View>

You can do whatever you need with the sizes and flexboxes, I wrapped the footer and the chidren with a view (marked 1) becuase my header is just an image.
This will look very similar to kitten's card component.

@jackstudd
Copy link

jackstudd commented Mar 16, 2021

Any updates ? Adding a props we can pass to the card's body container would solve the issue

@iMarvinS
Copy link

Is there any progress on this issue? This is a very strange behaviour which breaks most of my layouts...

@siarheipashkevich
Copy link

Any updates?

@c-goettert
Copy link

I am still facing these issues..

@DamianUS
Copy link

+1, the header does not respect flex properties either.

@thomaslc66
Copy link

Holly....
Was starting to use this UI library.
Saw this issue, from 2020 with still no solution and not resolved.
Will switch to something else directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.