0

In my React Native app, I have a card with a bunch of buttons at the bottom of it -- see image below.

enter image description here

I want to leave the first two icons where they are, on the left but move the (X) button all the way to the right. How do I accomplish this?

Here's what I have right now which is not working:

<Card style={styles.listItem}>
   <Card.Content>
      <Paragraph>{item.description}</Paragraph>
   </Card.Content>
   <Card.Actions>
      <Button><Icon name="checkcircleo" /> </Button> 
      <Button><Icon name="clockcircleo" /> </Button>
      <Button style={{ alignItems: 'stretch' }}><Icon name="closecircle" /> </Button>
   </Card.Actions>
</Card>
Sam
  • 26,817
  • 58
  • 206
  • 383

3 Answers3

10

To align the last button to the right, add { marginLeft: 'auto' } style to it.

To align all buttons to the right, add { justifyContent: 'flex-end' } style to Card.Actions.

ondrej.par
  • 191
  • 3
  • 10
0

Try adding alignSelf: "flex-end" to the button style:

<Card style={styles.listItem}>
    <Card.Content>
        <Paragraph>{item.description}</Paragraph>
    </Card.Content>

    <Card.Actions>
        <Button>
            <Icon name="checkcircleo" />
        </Button> 

        <Button>
            <Icon name="clockcircleo" />
        </Button>

        <Button style={{ alignSelf: "flex-end" }}>
            <Icon name="closecircle" />
        </Button>
    </Card.Actions>
</Card>
emeraldsanto
  • 4,330
  • 1
  • 12
  • 25
0

You can group the first two buttons by flex and flex direction:'row' and you can use the justifyContent:space-between on the group button and the cross button.

Here is an example of how it can be achieved. :

<Card.Actions>
<View style={{flexDirection:'row',justifyContent:'space-between'}} >
      <View style={{flexDirection:'row'}}>
        <Button>
            <Icon name="checkcircleo" />
        </Button> 

        <Button>
            <Icon name="clockcircleo" />
        </Button>
      </View>
<View>
        <Button style={{ alignSelf: "flex-end" }}>
            <Icon name="closecircle" />
        </Button>
</View>
</View>
    </Card.Actions>

Here is the example of the expo snack : expo-snack

Do check out.

Feel free for doubts

Gaurav Roy
  • 11,175
  • 3
  • 24
  • 45
  • This didn't work for me. I wonder if it's because I'm using `react-native-paper` and my `Card` is actually imported from `react-native-paper` and not the standard one in `React Native`. – Sam May 16 '20 at 21:56