All Projects → FormidableLabs → React Native Responsive Styles

FormidableLabs / React Native Responsive Styles

Licence: mit
React Native styles that respond to orientation change

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Responsive Styles

Moretoggles.css
A pure CSS library that provides you with a variety of nice-looking toggles
Stars: ✭ 596 (+244.51%)
Mutual labels:  stylesheets
Theme Notes First
A Notes-First StyleSheet for Taskpaper
Stars: ✭ 28 (-83.82%)
Mutual labels:  stylesheets
Web Client
Generic Linked Data browser and UX component framework. Apache license.
Stars: ✭ 105 (-39.31%)
Mutual labels:  stylesheets
Cirrus
☁️ The CSS framework for the modern web.
Stars: ✭ 716 (+313.87%)
Mutual labels:  stylesheets
Assets async
Asynchronous stylesheet and javascript for rails app
Stars: ✭ 9 (-94.8%)
Mutual labels:  stylesheets
Bss
🎨 Better Style Sheets
Stars: ✭ 72 (-58.38%)
Mutual labels:  stylesheets
Destyle.css
Opinionated reset stylesheet that provides a clean styling slate for your project.
Stars: ✭ 499 (+188.44%)
Mutual labels:  stylesheets
Qdarkstylesheet
A dark style sheet for QtWidgets application
Stars: ✭ 1,952 (+1028.32%)
Mutual labels:  stylesheets
Motif
Lightweight and customizable stylesheets for iOS
Stars: ✭ 879 (+408.09%)
Mutual labels:  stylesheets
Flexibility
Xamarin.Forms FlexLayout samples styled in a variety of ways: directly, XAML Styles, XAML Styles in a Resource Dictionary, CSS inline, and CSS loaded from a StyleSheet.
Stars: ✭ 94 (-45.66%)
Mutual labels:  stylesheets
Jss
JSS is an authoring tool for CSS which uses JavaScript as a host language.
Stars: ✭ 6,576 (+3701.16%)
Mutual labels:  stylesheets
Ember Cli Scss Lint
An ember-cli addon to integrate sass-lint for standards adherence and improved style consistency
Stars: ✭ 7 (-95.95%)
Mutual labels:  stylesheets
Uncss
Remove unused styles from CSS
Stars: ✭ 9,170 (+5200.58%)
Mutual labels:  stylesheets
Qt Frameless Window Darkstyle
simple MainWindow class implementation with frameless window and custom dark style. It adds also support for titlebar and buttons (minimize, maximize, close)
Stars: ✭ 628 (+263.01%)
Mutual labels:  stylesheets
Style Loader
Style Loader
Stars: ✭ 1,572 (+808.67%)
Mutual labels:  stylesheets
Premailer.net
C# library that moves your stylesheets to inline style attributes, for maximum compatibility with E-mail clients.
Stars: ✭ 503 (+190.75%)
Mutual labels:  stylesheets
Osmm Topography Layer Stylesheets
SQL scripts & cartographic stylesheets for OS MasterMap Topography Layer
Stars: ✭ 32 (-81.5%)
Mutual labels:  stylesheets
Cssjanus
↔️ Convert CSS stylesheets between left-to-right and right-to-left.              Made by Wikimedia.
Stars: ✭ 168 (-2.89%)
Mutual labels:  stylesheets
Skin
Pure CSS framework designed & developed by eBay for a branded, e-commerce marketplace.
Stars: ✭ 126 (-27.17%)
Mutual labels:  stylesheets
Interfacss
The CSS-inspired styling and layout framework for iOS
Stars: ✭ 92 (-46.82%)
Mutual labels:  stylesheets

react-native-responsive-styles

npm version

React Native styles that respond to device orientation change


How-to

Installation:

npm i --save react-native-responsive-styles

This library depends on walmartlabs/react-native-orientation-listener, which contains native dependencies for iOS and Android. Link them with:

react-native link react-native-orientation-listener

You can now import StyleSheet and any React components from react-native-responsive-styles instead of react-native:

import {
  View,
  Image,
  ScrollView,
  StyleSheet
} from 'react-native-responsive-styles';

You can then define custom style properties for landscape and portrait orientations:

const styles = StyleSheet.create({
  container: {
    flex: 1,
    // define separate styles for portrait and landscape
    portrait: {
      flexDirection: 'column'
    },
    landscape: {
      flexDirection: 'row'
    }
  },
  mainContent: {
    flex: 8,
    // override a default value when orientation is landscape
    landscape: {
      flex: 1
    }
  },
  secondaryContent: {
    flex: 1,
    // override a default value when orientation is portrait
    portrait: {
      backgroundColor: '#ccc'
    }
  }
});

Usage of StyleSheet.create is not required. Plain style objects will work as well, as long as you use the React components from this package.

That's it!

Demo

Demo

Advanced features

Animate transitions

You can apply a LayoutAnimation to orientation changes. Valid animation values are spring, linear and easeInEaseOut.

StyleSheet.configureLayoutAnimation('spring');

The default behaviour is no animation, but configuring one is recommended to avoid visual glitches when rearranging elements.

Make your custom components responsive

To add support for orientation-specific styles to your own components or other third-party components, wrap them in a higher-order component with StyleSheet.makeResponsive:

import React from 'react';
import StyleSheet from 'react-native-responsive-styles';

class CustomComponent extends React.Component({
  //...
});

export default StyleSheet.makeResponsive(CustomComponent);

In most cases this should not be required. You can simply nest your component in a responsive View.

Hiding elements

A common use case is to hide an element entirely in one orientation. You can use StyleSheet.hidden for that:

const styles = StyleSheet.create({
  landscapeOnly: {
    flex: 1,
    portrait: StyleSheet.hidden
  }
})

Please note

This project is in a pre-release state. The API may be considered relatively stable, but changes may still occur.

MIT licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].