React Ape

React Ape

  • Docs
  • Contributing
  • Blog
  • GitHub
  • React

›The Basics

The Basics

  • Getting Started
  • Learning the Basics
  • Height and Width

Guides

  • Components and APIs
  • Navigation on Apps
  • Custom Components

Contributing

  • How to Contribute

Components

  • Image
  • Text
  • View

APIs

  • Dimensions
  • Platform
  • StyleSheet
  • Navigation

Props

  • Image Style Props
  • Text Style Props
  • View Style Props
Edit

Height and Width

Height and Width

A component's height and width determine its size on the screen.

Fixed Dimensions

The simplest way to set the dimensions of a component is by adding a fixed width and height to style. All dimensions in React Ape are unitless, and represent density-independent pixels.

Setting dimensions this way is common for components that should always render at exactly the same size, regardless of screen dimensions.

import React, { Component } from 'react';
import { View, render } from 'react-ape';

class DimensionsBasics extends Component {
  render() {
    return (
      <View>
        <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
        <View style={{width: 100, height: 100, backgroundColor: 'skyblue'}} />
        <View style={{width: 150, height: 150, backgroundColor: 'steelblue'}} />
      </View>
    );
  }
}

render(<DimensionsBasics />, document.getElementById('root'));