📕
Dan Fitz's Notes
  • README
  • Ai
    • Supervised Machine Learning
      • Introduction To Machine Learning
      • Regression With Multiple Input Variables
      • Classification
  • Csharp
    • C Sharp Advanced
      • Generics
      • Delegates
      • Lambda Expressions
      • Events
    • C Sharp Fundamentals
      • Intro To C
      • Primitive Types And Expressions
      • Non Primitive Types
      • Control Flow
      • Arrays And Lists
      • Working With Dates
      • Working With Text
      • Working With Files
      • Debugging Applications
    • C Sharp Intermediate
      • Classes
      • Association Between Classes
      • Inheritance
      • Polymorphism
      • Interfaces
  • Java
    • Inheritance Data Structures Java
      • Inheritance Polymorphism Using Overriding And Access Modifiers
      • Abstract Classes And Debugging
      • File I O And Exceptions
      • Collections Maps And Regular Expressions
    • Intro To Java
      • Introduction To Java Classes And Eclipse
      • Unit Testing Arrays And Array Lists
      • Static Variables Methods And Polymorphism Using Overloading
  • Javascript
    • Algorithms Data Structures
      • Big O Notation
      • Analyzing Performance Of Arrays And Objects
      • Problem Solving Approach
      • Problem Solving Patterns
      • Recursion
      • Searching Algorithms
      • Bubble Selection And Insertion Sort
      • Merge Sort
      • Quick Sort
      • Radix Sort
      • Data Structures Introduction
      • Singly Linked Lists
      • Doubly Linked Lists
      • Stacks And Queues
      • Binary Search Trees
      • Tree Traversal
      • Binary Heaps
    • Complete Nodejs
      • Understanding Node.js
      • REST AP Is And Mongoose
      • API Authentication And Security
      • Node.js Module System
      • File System And Command Line Args
      • Debugging Node.js
      • Asynchronous Node.js
      • Web Servers
      • Accessing API From Browser
      • Application Deployment
      • Mongo DB And Promises
    • Complete React Native
      • Working With Content
      • Building Lists
      • Navigating Users Between Screens
      • State Management
      • Handling Screen Layout
      • Setting Up An App
      • More On Navigation
      • Advanced Statement Management With Context
      • Building A Custom Express API
      • In App Authentication
    • Epic React
      • React Fundamentals
      • React Hooks
      • Advanced React Hooks
      • Advanced React Patterns
      • React Performance
    • Fireship Firestore
      • Firestore Queries And Data Modeling Course
      • Model Relational Data In Firestore No SQL
    • Functional Light Javascript
      • Intro
      • Function Purity
      • Argument Adapters
      • Point Free
      • Closure
      • Composition
      • Immutability
      • Recursion
      • List Operations
      • Transduction
      • Data Structure Operations
      • Async
    • Js Weird Parts
      • Execution Contexts And Lexical Environments
      • Types And Operators
      • Objects And Functions
      • Object Oriented Java Script And Prototypal Inheritance
      • Defining Objects
    • Mastering Chrome Dev Tools
      • Introduction
      • Editing
      • Debugging
      • Networking
      • Auditing
      • Node.js Profiling
      • Performance Monitoring
      • Image Performance
      • Memory
    • React Complete Guide
      • What Is React
      • React Basics
      • Rendering Lists And Conditionals
      • Styling React Components
      • Debugging React Apps
      • Component Deep Dive
      • Building A React App
      • Reaching Out To The Web
      • Routing
    • React Testing
      • Intro To Jest Enzyme And TDD
      • Basic Testing
      • Redux Testing
      • Redux Thunk Testing
    • Serverless Bootcamp
      • Introduction
      • Auction Service Setup
      • Auction Service CRUD Operations
      • Auction Service Processing Auctions
    • Testing Javascript
      • Fundamentals Of Testing
      • Static Analysis Testing
      • Mocking Fundamentals
      • Configuring Jest
      • Test React Components With Jest And React Testing Library
    • Typescript Developers Guide
      • Getting Started With Type Script
      • What Is A Type System
      • Type Annotations In Action
      • Annotations With Functions And Objects
      • Mastering Typed Arrays
      • Tuples In Type Script
      • The All Important Interface
      • Building Functionality With Classes
    • Web Performance With Webpack
      • Intro
      • Code Splitting
      • Module Methods Magic Comments
  • Other
    • Algo Expert
      • Defining Data Structures And Complexity Analysis
      • Memory
      • Big O Notation
      • Logarithm
      • Arrays
      • Linked Lists
      • Hash Tables
      • Stacks And Queues
      • Strings
      • Graphs
      • Trees
    • Aws Solutions Architect
      • AWS Fundamentals IAM EC 2
    • Fundamentals Math
      • Numbers And Negative Numbers
      • Factors And Multiples
      • Fractions
    • Mysql Bootcamp
      • Overview And Installation
      • Creating Databases And Tables
      • Inserting Data
      • CRUD Commands
      • The World Of String Functions
      • Refining Our Selections
      • The Magic Of Aggregate Functions
    • Random Notes
      • Understanding React Hooks
  • Python
    • Data Analysis Using Python
      • Loading Querying And Filtering Data Using The Csv Module
      • Loading Querying Joining And Filtering Data Using Pandas
      • Summarizing And Visualizing Data
    • Intro To Python
      • Course Introduction Intro To Programming And The Python Language Variables Conditionals Jupyter Notebook And IDLE
      • Intro To Lists Loops And Functions
      • More With Lists Strings Tuples Sets And Py Charm
      • Dictionaries And Files
Powered by GitBook
On this page
  • Layout Systems
  • Box Object Model
  • Flex Box
  • alignItems
  • flexDirection
  • justifyContent
  • flex
  • alignSelf
  • Position
  • Top, bottom, left, and right
  • Order of Processing When Applying Layout Rules
  • SafeAreaView
  1. Javascript
  2. Complete React Native

Handling Screen Layout

The operative question in this section is: how do you style the layout of an app and make it look really nice?

Layout Systems

There are 3 different systems for handling layout styles:

  1. Box object model

    • Handles sizing (height and width) of element plus the space around it (padding, border, and margin)

    • This affects the position of a single element

  2. Flex box

    • Handles the positioning of multiple elements inside a common parent

  3. Position

    • Handles position of single element inside a parent

    • Useful for overriding box object and flex box models

Box Object Model

For the most part, the most useful style properties available to you are the same as the browser with a few additions:

  • marginVertical and paddingVertical

  • marginHorizontal and paddingHorizontal

Flex Box

By default, flex mode is on! However, there are a few unique default style properties set:

  • flexDirection is set to column because we're on mobile.

  • alignItems is set to flex-stretch to automatically make each element stretch the full width of its container (sort of like every element being width: 100%).

alignItems

Popular available values that you place on the parent element:

  • flex-stretch (default)

  • flex-start

  • center

  • flex-end

flexDirection

Available values you place on the parent element:

  • column (default)

  • row

justifyContent

Popular available values that you place on the parent element:

  • flex-start (default)

  • center

  • flex-end

  • space-between

  • space-around

flex

Just like flex in the browser, you set a numeric value on the child element to define how much that child element should stretch in proportion to its siblings. (The stretch goes in the same direction as flexDirection.)

alignSelf

alignSelf overrides whatever alignItems value is in the parent element.

Position

By default, position is set to relative. To remove an element from the element flow, you'd change it to absolute.

Note: Some flex-related styles that have been applied to the parent can still affect the positioning of a position: absolute element. For example, alignItems: flex-end will still push it to the edge of the screen.

Top, bottom, left, and right

top, bottom, left, and right behave normally. It just moves an element X units of spacing away from each edge.

Note: Just like the browser, you can set all these values to 0 on an absolute element to have the element fill its parent container.

Bonus: StyleSheet provides all the properties necessary to do this styling trick. It's in StyleSheet.absoluteFillObject.

StyleSheet.create({
  child: {
    ...StyleSheet.absoluteFillObject,
  },
});

Order of Processing When Applying Layout Rules

Here's the order of processing roughly:

  1. Apply box object model rules (margin, padding, border, etc.).

  2. If position: absolute applied:

    • Apply some flex box rules, completely ignoring siblings.

    • Apply top, left, right, and bottom.

  3. If position: absolute NOT applied:

    • Apply all flex box rules, considering siblings.

    • Place element inside parent.

    • Apply top, left, right, and bottom.

SafeAreaView

react-navigation provides a useful SafeAreaView wrapper component that automatically adds the correct spacing around your screens to prevent content from being cut off depending on the device. (For example, modern iPhones have a status bar at the top. You want your content to begin below that.)

import { SafeAreaView } from 'react-navigation';

// The content in this screen won't get cut off!
const HomeScreen = () => (
  <SafeAreaView>
    <Text>Home Screen</Text>
  </SafeAreaView>
);
PreviousState ManagementNextSetting Up An App

Last updated 3 years ago