Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useWindowSize Resize detection on mobile devices #1505

Closed
7 tasks done
ryoji-sagara opened this issue Apr 19, 2022 · 4 comments
Closed
7 tasks done

useWindowSize Resize detection on mobile devices #1505

ryoji-sagara opened this issue Apr 19, 2022 · 4 comments

Comments

@ryoji-sagara
Copy link

ryoji-sagara commented Apr 19, 2022

Describe the bug

Prerequisite :

In index.html

<meta name="apple-mobile-web-app-capable" content="yes" />

Set and "Add to Home" state.

Issue

I used useWindowSize for reactive window size detection.

import { watch } from 'vue'
import { useWindowSize } from '@vueuse/core'

const { height } = useWindowSize()
watch(height, () => {
  console.log('Change WindowSize!', height.value)
})

I used useWindowSize to detect not only the resize event, but also the
I think we should add an orientationchange event as well, since it is possible to detect changes by binding an orientationchange event as well.

I'm not sure I've covered all the features of Vueuse, so if there is another way to do it, I'd appreciate it if you could let me know.

Reproduction

none

System Info

iPhone safari

Used Package Manager

yarn

Validations

@JMaylor
Copy link
Contributor

JMaylor commented May 15, 2022

Could you combine with useScreenOrientation?

e.g.

import { watch } from 'vue'
import { useWindowSize, useScreenOrientation } from '@vueuse/core'

const { height } = useWindowSize()
const { orientation } = useScreenOrientation()
watch([height, orientation], () => {
  if (window) console.log(window.innerHeight)
})

@ryoji-sagara
Copy link
Author

@JMaylor
Thanks.
In my case, I can use useScreenOrientation and it will be fine.

However, I am concerned that the height of useWindowSize does not change reactively when the device is rotated, which may be a bug for development users.

@stale
Copy link

stale bot commented Sep 14, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 14, 2022
@stale stale bot closed this as completed Sep 21, 2022
@CodyBontecou
Copy link

CodyBontecou commented Nov 28, 2023

@JMaylor Thanks. In my case, I can use useScreenOrientation and it will be fine.

However, I am concerned that the height of useWindowSize does not change reactively when the device is rotated, which may be a bug for development users.

I'm running into this. These are outputting different amounts:

watch(orientation, () => {
  console.log("width: ", windowWidth.value, "height: ", windowHeight.value);
});

watch(windowWidth, () => {
  console.log(
    "windowWidth: ",
    windowWidth.value,
    "height: ",
    windowHeight.value,
  );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants