HStack

Use the HStack component to align items horizontally. For example, you can use this to stack Avatars or any other ReactNode item.

Props

xGap

Use this to set the horizontal gap between items or to overlap them.

TypeDefaultDescription
number/It accepts any number, positive or negative. If negative, the items will overlap.

Example

1
2
3
1
2
3
1
2
3
Source code
<View>
  <UIHStack
    xGap={-16}
  >
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#1bbeb0', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>1</Text></View>
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#169f94', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>2</Text></View>
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#11756d', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>3</Text></View>
  </UIHStack>
  <UIHStack
    xGap={16}
  >
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#1bbeb0', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>1</Text></View>
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#169f94', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>2</Text></View>
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#11756d', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>3</Text></View>
  </UIHStack>
  <UIHStack
    xGap={32}
  >
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#1bbeb0', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>1</Text></View>
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#169f94', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>2</Text></View>
    <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#11756d', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>3</Text></View>
  </UIHStack>
</View>

topDown

If active, items will be stacked from top to bottom. It's noticeable only if xGap is negative number.

TypeDefaultDescription
boolean/If active, first item will be at the top and each next item will be below the previous one.
It's not enabled by default. Make sure to enable it in Editor if you want to use it.

Example

3
2
1
Source code
<UIHStack
  xGap={-12}
  topDown
>
  <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#1bbeb0', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>1</Text></View>
  <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#169f94', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>2</Text></View>
  <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#11756d', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>3</Text></View>
</UIHStack>

reverse

Use this to reverse the order of items.

TypeDefaultDescription
boolean/It does not affect the topDown prop, it only reverses the order of items.
It's not enabled by default. Make sure to enable it in Editor if you want to use it.

Example

3
2
1
Source code
<UIHStack
  xGap={-12}
  reverse
>
  <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#1bbeb0', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>1</Text></View>
  <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#169f94', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>2</Text></View>
  <View style={{width: 50, height: 50, borderRadius: 8, backgroundColor: '#11756d', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 16}}>3</Text></View>
</UIHStack>

children

Use this to set ReactNode items.

TypeDefaultDescription
ReactNode/You need to set width and height on item level.

Example

Source code
<UIHstack>
  {/* Your ReactNode item */}
  {/* Your ReactNode item */}
  {/* Your ReactNode item */}
</UIHstack>

Editor

Source code
import React from 'react';
import {View} from 'react-native';

const UIHStack = ({
  xGap,
  children,
}) => {
  const styles = {
    hStack: {
      overflow: 'hidden',
      flexDirection: 'row',
      minWidth: 0,
      minHeight: 0,
      flexShrink: 0,
    },
    hStackItemWrap: {
      marginLeft: xGap,
      minWidth: 0,
      flexShrink: 0,
    },
    hStackItemWrapIsFirst: {
      marginLeft: 0,
    },
  };

  return (
    <View style={styles.hStack}>
      {React.Children.map(children, (child, index) => {
        const isFirst = index === 0;
        return (
          <View key={child?.key} style={[styles.hStackItemWrap, isFirst && styles.hStackItemWrapIsFirst]}>
            {React.cloneElement(child)}
          </View>
        )
      })}
    </View>
  );
};

export default UIHStack;
Usage example
<UIHStack
  xGap={-12}
>
  <View style={{width: 64, height: 64, borderRadius: 16, backgroundColor: '#1bbeb0', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 20}}>1</Text></View>
  <View style={{width: 64, height: 64, borderRadius: 16, backgroundColor: '#169f94', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 20}}>2</Text></View>
  <View style={{width: 64, height: 64, borderRadius: 16, backgroundColor: '#11756d', justifyContent: 'center', alignItems: 'center'}}><Text style={{color: '#ffffff', fontSize: 20}}>3</Text></View>
</UIHStack>