Giter Club home page Giter Club logo

react-div-100vh's People

Contributors

atav32 avatar bignimbus avatar charlescrtr avatar charliehess avatar dependabot[bot] avatar joshuarrr avatar katt avatar kframesa avatar meyerds avatar mvasin avatar smileart avatar tinder-kyleboss avatar yatsyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-div-100vh's Issues

not working for me...

I really want this to work, but I tried using it in my Gatsby JS app and it doesn't seem to be doing the job. Here is my layout code:

export default ({ children }) => (
  <Div100vh>
    <StaticQuery
      query={graphql`
        query {
          site {
            siteMetadata {
              title
            }
          }
        }
      `}
      render={data => (
        <AppLayout>
          <Navigation>
            <NavLink to={`/`}>
              <H3>{data.site.siteMetadata.title}</H3>
            </NavLink>
            <NavLink to={`/products`}>
              Products
            </NavLink>
            <NavLink to={`/features`}>
              Features
            </NavLink>
            <NavLink to={`/about`}>
              About Us
            </NavLink>
          </Navigation>
          {/* <PageTransition> */}
            <MainContent>
              {children}
            </MainContent>
          {/* </PageTransition> */}
        </AppLayout>
      )}
    />
  </Div100vh>
)

I tried putting the component around both the whole layout, including the , which did not work, and also the Component, then tried running it on my iPhone, and neither worked for me. Is there anything about using this component I should know about? Has it ever been tested with a Gatsby App at all?

It would be awesome if this can work for me, as I've been dealing with this issue for over a year now, and it's no fun at all.

Would something like this be possible?

Hi,

Been trying for months but can't get your component to work properly in my Gatsby JS React app. I'm thinking now, however, that maybe I need to do something like this:

@media (min-width: 50rem) {
  grid-template-rows: 20rvh 5rvh 5rvh 50rvh 20rvh;
  grid-template-columns: 1fr 3fr;
}

...in which I am using your Real Viewport Unit measurement as declarations of the grid-rows of a grid layout. Is something like this even possible? I'm using Viewport Units inside a styled-component, like so:

const App = styled(animated.div)`
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-rows: 20rvh 70rvh 10rvh;
  grid-template-columns: repeat(3, 1fr);

  @media (min-width: 50rem) {
    grid-template-rows: 20vh 5vh 5vh 50vh 20vh;
    grid-template-columns: 1fr 3fr;
  }
`

...in combination with react-spring (hence the animated.div) inside of a Gatsby JS React app. It's all very convoluted, I know, but for me to even begin to use your component properly I need to do some fancy stuff in the gatsby-browser.js file, like so:

import React, { useEffect } from 'react'
import Div100vh from 'react-div-100vh'

const WrapperComponent = (props) => {
  useEffect(() => {
    window.onresize = function() {
      document.body.height = window.innerHeight;
    }

    window.onresize(); // called to initially set the height.
  }, []);

  return props.children;
}

export const wrapRootElement = ({ element }) => { 
  return (
  <WrapperComponent>
    <Div100vh>
      {element}
    </Div100vh>
  </WrapperComponent>
  )
}

I noticed in your docs that you recommend using a style tag and passing the rvh units in as an object, but I'm curious to know if it's possible to do what I have described above.

If you are interested, here is the issue in Gatsby's repo where some nice people are trying to help me out with this as well:

gatsbyjs/gatsby#15049

Any thoughts that you could share regarding this matter would be very much appreciated.

Thank you! XD

Could not find a declaration file for module 'react-div-100vh

I'm using gatsby and running into this import error ?
Anyway to get round this.

Could not find a declaration file for module 'react-div-100vh'. 'path/node_modules/react-div-100vh/lib/index.js' implicitly has an 'any' type.

Unfortunately my project is way too large to break down into a example.

min-height?

Thanks for sharing this component!

For my use I needed to change node.style.height = window.innerHeight + 'px'; to node.style.minHeight = window.innerHeight + 'px';. I don't know how to do this but it seems like passing that down as a prop might be useful?

Update height on device orientation change?

Hi @mvasin, how can we update the height as the orientation change from portrait to landscape and vice-versa when using Chrome on iOS? Although it seems like a pretty common scenrio, I couldn't find any related issues posted here. Can you please guide me?

Sometimes the height does not change when orientation change from Landscape to Portrait on iOS PWA

Demo

RPReplay_Final1639494891.MP4

Detail

When changing orientation from Landspace to Portrait, sometimes the height doesn't change.

But this doesn't always happen, it's really sometimes.
It may be reproduced immediately, or it may not be reproduced unless the orientation is changed many times.

I used next-pwa to make PWA, and [email protected] doesn't have this problem.

Source

Using [email protected]

https://github.com/Takkiii/pwa-orientation-behavior-app

Using [email protected]

https://github.com/Takkiii/pwa-orientation-behavior-app/tree/react-div-100vh/0.6.0

Great work, man!

No real issue, just wanted to say that Div100vh is awesome, great idea and well executed, thanks!

module error when building

Getting this error when using webpack to build. Also using React 16.4.1

ERROR in .//react-div-100vh/lib/convertStyle/convertStyle.js
Module not found: Error: Can't resolve 'jest-get-type' in 'C:\projects\node_modules\react-div-100vh\lib\convertStyle'
@ ./
/react-div-100vh/lib/convertStyle/convertStyle.js 9:42-66
@ .//react-div-100vh/lib/convertStyle/index.js
@ ./
/react-div-100vh/lib/Div100vh.js
@ ./~/react-div-100vh/lib/index.js

0.3.3 is broken

Hi there! It looks like 0.3.3 is missing the lib/ folder in the tarball on npm. Here's what it looks like installed in the node_modules of my project:

Screenshot 2019-04-28 12 00 16

Did you maybe forget to run the lib script before publishing? ๐Ÿ™‚

height is sometimes wrong when browser height shrinks

When I shrink the website height by resizing my browser (Chrome Desktop Version 87.0.4280.88) the height (output of the measureHeight function) is sometimes too small by 15px.

This means a 15px tall white bar along the bottom of my site flicks into and out of existence as I shrink the browser.

As I drag the bottom of the window up, every 2nd call to measureHeight returns the incorrect value.

There is no issue when increasing the window height.

The odd thing is if I stop resizing the window once I get a bad value, and then use the console to get the documentElement.clientHeight, I get the correct value. It's almost like the browser hasn't updated the documentElement.clientHeight when measureHeight runs, but then it does so right after.

This does not happen when I activate the device toolbar, switch it to responsive and shrink the height there.

Does anyone else have this issue? I'm not sure if it is a browser bug, something in this library or most likely just something odd with my site.

Problem with recalculating height on mobile

I'm having a problem with mobile, when you first open the page we have the address bar and the bottom nav bar, and for the it calculates the div correctly to fill the space, but when I try to scroll on the div the address bar hides and the results to a div shorten then it supposed to be. Is there a way to recalculate that height after the address bar is hidden or something similar?

Exception during server-side rendering

After PR #26, which applies styles on first render, my Gatsby website build process fails with the exception:

failed Building static HTML for pages - 5.299s
error "document" is not available during server side rendering.

   8 | // extracted into a separate module so it's easier to mock with Jest
   9 | function getWindowHeight() {
> 10 |   return document && document.documentElement && document.documentElement.clientHeight || window.innerHeight;
     | ^
  11 | }
  12 | 
  13 | var _default = getWindowHeight;


  WebpackError: ReferenceError: document is not defined
  
  - getWindowHeight.js:10 getWindowHeight
    node_modules/react-div-100vh/lib/getWindowHeight.js:10:1
  
  - Div100vh.js:63 new Div100vh
    node_modules/react-div-100vh/lib/Div100vh.js:63:1

This is because the code to compute window height is now called in the constructor instead of at mount time, which means it runs during SSR builds as well, where window and document are not defined.

The usual solution to this would be to check if window is defined in getWindowHeight (this is the approach Gatsby docs suggest), but this would fail the assertions in convertStyle, so those assertions would need to be removed.

Another approach is to only call convertStyle in the constructor if the DOM is available (by doing the window check above), but then we'd have to call the method again in componentDidMount anyway in order to be isomorphic. This seems to be the preferable approach.

Happy to put up a PR based on guidance.

Android Chrome, UI bar dissappears as user scrolls down leaving gap when moving page

Hard one to explain, but I have a bug on Android Chrome when using this library with Gatsby, everything works fine but if I navigate to a page that isn't locked to 100vh, scroll down, the android UI bar at the bottom on the screen dissappears, when I nav back to another page from my fixed header, the 100vh page is calculated with the OS UI bar even though it isn't there, leaving a gap at the bottom.

An example can be seen here - https://prb-architects.netlify.app/ - if you navigate to a project from the carousel on the home page, scroll down, then click back in the fixed header at the top, you'll see the bug.

Is there any way anyone knows a workaround for this? It's fine in every mobile browser except Chrome Android

Thanks in advance,
Sam

`as` prop not working

The as prop doesn't seem to be working correctly. It is rendering a div with an as attribute.

For example.

This

<Div100vh as="main">
    ...
</Div100vh>

Is rendering

<div as="main" style="height: 879px;">
    ...
</div>

get npm ERR! Cannot read properties of undefined (reading 'spec') error

Tried to install on a Gatsby V3 website via npm, got 238 line in the log, here they are:

220 timing auditReport:init Completed in 33087ms
221 timing reify:audit Completed in 34348ms
222 timing reifyNode:node_modules/undefined Completed in 125553ms
223 timing reify:unpack Completed in 125553ms
224 timing reify:unretire Completed in 1ms
225 timing build:queue Completed in 35ms
226 timing build:deps Completed in 35ms
227 timing build Completed in 35ms
228 timing reify:build Completed in 35ms
229 timing reify:trash Completed in 0ms
230 timing command:install Completed in 132733ms
231 verbose stack TypeError: Cannot read properties of undefined (reading 'spec')
231 verbose stack at Arborist.[saveIdealTree] (/opt/homebrew/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:1086:44)
231 verbose stack at Arborist.reify (/opt/homebrew/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:150:31)
231 verbose stack at async Install.install (/opt/homebrew/lib/node_modules/npm/lib/install.js:150:5)
232 verbose cwd /Applications/MAMP/htdocs/react
233 verbose Darwin 20.6.0
234 verbose argv "/opt/homebrew/Cellar/node/16.9.1/bin/node" "/opt/homebrew/bin/npm" "install" "react-div-100vh" "https://github.com/mvasin/react-div-100vh.git"
235 verbose node v16.9.1
236 verbose npm v7.21.1
237 error Cannot read properties of undefined (reading 'spec')
238 verbose exit 1

Bug with mobile chrome

Bug with mobile chrome after change orientation not recalculated correct height. Sorry of my English

Images

Hello all,

Is it possible to apply this library to images? I tried something like this:

<Div100vh as="img" src={logo} style={{ height: '9.43rvh' }}></Div100vh>

The resulting HTML was:

<div as="img" src={logo} style={{ height: '9.43rvh' }}></div>

So no image was rendered.

A feature like this would be awesome.

[mobile]: resize event on keyboard open

On mobile, the resize event is triggered on input focus (keyboard open), but this should not be the case as it does not make any sense to shift the layout when keyboard is opened.

q2: Why not using orientationchange on mobile devices too ?

Build Failed with create-react-app

this is my package.json

"react-scripts": "1.1.5",
"react-div-100vh": "^0.3.2"

I got this error after run yarn build

Creating an optimized production build...
Failed to compile.

Failed to minify the code from this file: 

        ./node_modules/jest-get-type/build/index.js:14 

Read more here: http://bit.ly/2tRViJ9

Request to add further explanation to readme

I was thinking perhaps it would be nice to show something to new users explaining that the actual calculation of "rvh" basically boils down to this:

document && document.documentElement && document.documentElement.clientHeight || window.innerHeight

For a long time I used the package without knowing how this calculation was made, but opening up the files really helped.

Recently I needed to set minHeight to calc(100rvh - 100px). However this wasn't possible with the package, so learning the actual expression allowed me to create a listener and get this value myself.

Not recommended IMHO

So I tried all 100vh hacks I found, and my conclusion is that native iOS behavior is not fixable.
Every fix has its own quirks, even this one. I am not sure whether it's race conditions in CSS rendering engine or what, but my personal recommendation is to not try to fix iOS Safari anymore. We should not fight with it, we should embrace it in our designs. Btw, when the web app is linked to the home screen, it runs in full-screen without any bars and everything works as I expect.

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.