Coder Social home page Coder Social logo

trendingtechnology / react-native-use-dimensions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dawsonbooth/react-native-use-dimensions

0.0 1.0 0.0 2.35 MB

A collection of React hooks for using the dimensions of the screen, window, or both

Home Page: https://dawsonbooth.com/react-native-use-dimensions/

License: MIT License

JavaScript 19.26% TypeScript 80.74%

react-native-use-dimensions's Introduction

react-native-use-dimensions

npm version downloads build status license

Description

This Node.js package is a collection of React hooks for using the dimensions of the screen, window, or both.

Installation

With Node.js installed, simply run the following command to add the package to your project.

npm install react-native-use-dimensions

Usage

Check out the examples below or check out the docs.

The package comes with three hooks:

  1. useScreenDimensions - screen dimensions
  2. useWindowDimensions - window dimensions, which can be separate from screen on Android
  3. useDimensions - screen and window dimensions
import React from "react";
import { Text } from "react-native";
import useDimensions, {
  useScreenDimensions,
  useWindowDimensions
} from "react-native-use-dimensions";

const ScreenDimensions = () => {
  const { height, width } = useScreenDimensions();
  const isLandscape = width > height;
  return (
    <Text>
      {width}x{height}
      Orientation: {isLandscape ? "Landscape" : "Portrait"}
    </Text>
  );
};

const WindowDimensions = () => {
  const { height, width } = useWindowDimensions();
  const isLandscape = width > height;
  return (
    <Text>
      {width}x{height}
      Orientation: {isLandscape ? "Landscape" : "Portrait"}
    </Text>
  );
};

const BothDimensions = () => {
  const { screen, window } = useDimensions();
  return (
    <Text>
      Screen: {screen.width}x{screen.height}
      Window: {window.width}x{window.height}
    </Text>
  );
};

License

This software is released under the terms of MIT license.

react-native-use-dimensions's People

Contributors

dawsonbooth avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.