React Native Styling: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Line 35: Line 35:


=Flex Box=
=Flex Box=
==Introduction==
===flex: 0 auto;===
This is the same as flex: initial; and the shorthand for the default value: flex: 0 1 auto. It sizes the item based on its width/height properties (or its content if not set).<br>
<br>
It makes the flex item inflexible when there is some free space left, but allows it to shrink to its minimum when there is not enough space. The alignment abilities or auto margins can be used to align flex items along the main axis.
===flex: auto;===
This is equivalent to flex: 1 1 auto. Beware, this is not the default value. It sizes the item based on its width/height properties, but makes it fully flexible so that they absorb any extra space along the main axis.<br>
<br>
If all items are either flex: auto, flex: initial, or flex: none, any remaining space after the items have been sized will be distributed evenly to the items with flex: auto.
===flex: none;===
This is equivalent to flex: 0 0 auto. It sizes the item according to its width/height properties, but makes it fully inflexible.<br>
<br>
This is similar to flex: initial except it is not allowed to shrink, even in an overflow situation.
===flex: <positive-number>===
Equivalent to flex: 1 0px. It makes the flex item flexible and sets the flex basis to zero, resulting in an item that receives the specified proportion of the remaining space.<br>
<br>
If all items in the flex container use this pattern, their sizes will be proportional to the specified flex factor.
==Approach==
First approach was to create style for the app and surround the existing approach with views.
Adding display:flex will makle
<syntaxhighlight lang="jsx">
<syntaxhighlight lang="jsx">
</syntaxhighlight>
</syntaxhighlight>

Revision as of 13:41, 14 December 2020

Overview

Resources

Go to https://github.com/danielstern/styling-react-native. Really like Daniel.

Stylesheet.create()

Camel Case is used and an object created. There are no px suffixes for pixel values. Should work on all devices. The names do not necessary align with Android or IoS name. Only works on React components and not standard tags like div

const styles = Stylesheet.create({
   container: {
      backgroundColor: "white",
      height: 470.
   }
})


The snippet for this is rnss

Fixed Dimension

A brief example of fixed dimensions shows how to build a POC for a specified device. Whilst no good for release it is a lot quicker to build for one offs.

Images

Images need either a width of a height to show in react native. Without no image is shown. In the course they used this. I do like the hairlineWidth

...
export const Logo = () => (
    <Image source={img} style={styles.logo} />
)

const styles = StyleSheet.create({
    logo: {
        height: 110,
        borderBottomColor: 'darksteelblue',
        borderBottomWidth: StyleSheet.hairlineWidth
    }
});

Flex Box

Introduction

flex: 0 auto;

This is the same as flex: initial; and the shorthand for the default value: flex: 0 1 auto. It sizes the item based on its width/height properties (or its content if not set).

It makes the flex item inflexible when there is some free space left, but allows it to shrink to its minimum when there is not enough space. The alignment abilities or auto margins can be used to align flex items along the main axis.

flex: auto;

This is equivalent to flex: 1 1 auto. Beware, this is not the default value. It sizes the item based on its width/height properties, but makes it fully flexible so that they absorb any extra space along the main axis.

If all items are either flex: auto, flex: initial, or flex: none, any remaining space after the items have been sized will be distributed evenly to the items with flex: auto.

flex: none;

This is equivalent to flex: 0 0 auto. It sizes the item according to its width/height properties, but makes it fully inflexible.

This is similar to flex: initial except it is not allowed to shrink, even in an overflow situation.

flex: <positive-number>

Equivalent to flex: 1 0px. It makes the flex item flexible and sets the flex basis to zero, resulting in an item that receives the specified proportion of the remaining space.

If all items in the flex container use this pattern, their sizes will be proportional to the specified flex factor.

Approach

First approach was to create style for the app and surround the existing approach with views. Adding display:flex will makle