All Projects â†’ diego3g â†’ responsive-native

diego3g / responsive-native

Licence: MIT license
A responsive utility toolkit for React Native 📱⚛

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to responsive-native

svelto
Modular front end framework for modern browsers, with battery included: 100+ widgets and tools.
Stars: ✭ 61 (-81.57%)
Mutual labels:  responsive
Portfolio-Demo-1
A portfolio build by using flutter for web.
Stars: ✭ 74 (-77.64%)
Mutual labels:  responsive
ember-responsive-image
Automatically generate resized images at build-time, optimized for the responsive web, and using components to render them easily as <picture> elements.
Stars: ✭ 103 (-68.88%)
Mutual labels:  responsive
react-responsive-tabs
React responsive tabs http://maslianok.github.io/react-responsive-tabs/
Stars: ✭ 118 (-64.35%)
Mutual labels:  responsive
pichichi
Simple one page responsive portfolio template
Stars: ✭ 54 (-83.69%)
Mutual labels:  responsive
mainsail
Mainsail is the popular web interface for Klipper
Stars: ✭ 960 (+190.03%)
Mutual labels:  responsive
griding
🧱 lean grid & responsive for react
Stars: ✭ 18 (-94.56%)
Mutual labels:  responsive
tb-grid
tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.
Stars: ✭ 19 (-94.26%)
Mutual labels:  responsive
responsivebootstrap
This is the repository for my course, Bootstrap Layouts: Responsive Single-Page Design on LinkedIn Learning and Lynda.com.
Stars: ✭ 49 (-85.2%)
Mutual labels:  responsive
terminal-columns
Render readable & responsive tables in the terminal
Stars: ✭ 27 (-91.84%)
Mutual labels:  responsive
multiple-windows
This project is a chrome extension. It provide to create windows to different sizes and multiple for front-end developers.
Stars: ✭ 16 (-95.17%)
Mutual labels:  responsive
uptime-kuma
A fancy self-hosted monitoring tool
Stars: ✭ 27,425 (+8185.5%)
Mutual labels:  responsive
ionic-login-component
Free sample of Premium Ionic Login Component
Stars: ✭ 17 (-94.86%)
Mutual labels:  responsive
website
Fully responsive website built with NextJS, React and Fluent UI, with the aim of providing services and access to all groups of didactic courses and general purposes to students of the University of Milan.
Stars: ✭ 29 (-91.24%)
Mutual labels:  responsive
flutter-ui-boilerplate
Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file folder.
Stars: ✭ 114 (-65.56%)
Mutual labels:  responsive
react-native-bootstrap-styles
Bootstrap style library for React Native
Stars: ✭ 95 (-71.3%)
Mutual labels:  responsive
ekzo
💫 Functional Sass framework for rapid and painless development
Stars: ✭ 32 (-90.33%)
Mutual labels:  responsive
Tech-Writing-Linktree
✨ tech writer portfolio in the style of linktree ✨
Stars: ✭ 26 (-92.15%)
Mutual labels:  responsive
qt-quick-responsive-helper
A simple toolbar for QtQuick based applications, to let developers test different resolutions and dpi settings easily. It was made to be integrated with minimal effort (only one QML file), and to be configurable for your specific usage.
Stars: ✭ 26 (-92.15%)
Mutual labels:  responsive
breaking-point
BREAKING-POINT lets you quickly define and subscribe to screen (i.e. window) breakpoints in your re-frame application
Stars: ✭ 36 (-89.12%)
Mutual labels:  responsive

Responsive applications are a big challenge for mobile developers.

Most of the mobile devices have different dimensions and densities, so using absolute units like pixels ('px') can cause elements to have different sizes than expected.

As iPhones, for example, have a higher pixel density than Android phones, if you use 16px in a Text, it will look much larger on Android than on iOS.

This library aims to solve this problem by converting this value from px to rem. The value in rem is calculated with some variables such as device width and height, thus providing a much more proportional interface.

It also includes an easy way to create Media Queries just like the web environment but based on breakpoints as inside mobile devices we do not need to deal a lot with screen resizing while the app is running.

Getting started

Install the library using:

yarn add responsive-native react-native-safe-area-context

The lib react-native-safe-area-context must be installed.

Wrap the application with the provider

You can import the ScreenProvider and wrap the whole App with it then all child components will be able to consume and use the responsive functions.

Set the baseFontSize

ScreenProvider receives a optional baseFontSize prop that corresponds to the value of 1rem. By default 1rem = 16px, but depending on your UI, you would prefer setting this to a different value to provide an easier way to achieve some values in spacings or sizes.

import { ScreenProvider } from 'responsive-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';

export default function App() {
  return (
    <SafeAreaProvider>
      <ScreenProvider baseFontSize={16}>
        { ... }
      </ScreenProvider>
    </SafeAreaProvider>
  )
}

ScreenProvider depends on SafeAreaProvider, from react-native-safe-area-context, so put SafeAreaProvider around ScreenProvider.

Library hooks

useRem

Transforms a rem value to the best pixel value based on the device width, height and accessibility preferences.

The useRem hook receives as first param the value in rem that will be converted to pixels. The second optional parameter is shouldScale that is a boolean (defaults to false) that tells if the fontScale defined by the user device should be used in the conversion (if you're using rem to define font sizes, you might want to use this as true).

You can read a little more about fontScale here

export function MyComponent() {
  const rem = useRem();

  return (
    <View style={styles.container}>
      <Text style={[styles.text, { fontSize: rem(1.5, true) }]}>Hello World!</Text>
    </View>
  );
}

useMediaQuery

Returns true if the conditions match the device.

The useMediaQuery hook receive as params:

{
  platform: 'ios' | 'android' | 'web' | 'windows' | 'macos';
  minBreakpoint: 'sm' | 'md' | 'lg' | 'xlg';
  maxBreakpoint: 'sm' | 'md' | 'lg' | 'xlg';
}
export function MyComponent() {
  const showSideNav = useMediaQuery({
    minBreakpoint: 'lg',
  });

  return (
    <View style={styles.container}>
      { showSideNav ? <SideNav /> : <DefaultNav /> }
    </View>
  );
}

useBreakpointValue

Returns the desired value based on the breakpoint.

You can pass different values so your interface will adapt devices different sizes. The useBreakpointValue hook can return any value, including JSX elements. The base value is always required and will be used if the device breakpoint was not matched by the other rules.

export function MyComponent() {
  const textByBreakpoint = useBreakpointValue({
    sm: "I'm a small device",
    md: "I'm a medium device",
    base: "I will be used in any larger device than md",
  });

  return (
    <View style={styles.container}>
      <Text style={styles.text}>{textByBreakpoint}</Text>
    </View>
  );
}

useScreen

Returns an object with important information about the device screen.

{
  padding: {
    top: number;
    bottom: number;
    left: number;
    right: number;
  };
  breakpoint: {
    size: 'sm' | 'md' | 'lg' | 'xlg';
    maxWidth: number;
  };
  pixelRatio: number;
  fontScaleFactor: number;
  baseFontSize: number;
}

You might want use useScreen to get information like padding so you can use it on Header or TabBar components so it doesn't stay under non-clickable areas.

Integration

styled-components

If you're using styled-components, you can integrate this library functionality into your ThemeProvider.

Create a new ThemeProvider based on this example and use it instead of the standard styled-components ThemeProvider.

Typescript

If you're using TypeScript, you'll have to add the responsive-native functions along with your theme typings, just follow the example.

Usage

import styled from 'styled-components/native';

export const Container = styled.Text`
  font-size: ${({ theme }) => theme.screen.rem(12)}px;
`;

We know, this is the shortest syntax, so we created an example VSCode snippet so you can add it inside VSCode and just type 'rem' and it will autocomplete for you.

Contributing

Thank you for being interested in making this package better. We encourage everyone to help improve this project with new features, bug fixes, or performance improvements. Please take a little bit of your time to read our guide to make this process faster and easier.

Contribution Guidelines

To understand how to submit an issue, commit and create pull requests, check our Contribution Guidelines.

License

MIT License © Diego Fernandes

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].