-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4761 from nextcloud-libraries/feat/is-mobile--is-…
…fullscreen--composables feat: introduce `useIsMobile` and `useIsFullscreen` composables
- Loading branch information
Showing
13 changed files
with
225 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './useIsFullscreen/index.js' | ||
export * from './useIsMobile/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @copyright Copyright (c) 2019 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* @author Grigorii K. Shartsev <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import { readonly, ref } from 'vue' | ||
|
||
// if the window height is equal to the screen height, | ||
// we're in full screen mode | ||
const checkIfIsFullscreen = () => window.outerHeight === screen.height | ||
|
||
const isFullscreen = ref(checkIfIsFullscreen()) | ||
|
||
window.addEventListener('resize', () => { | ||
isFullscreen.value = checkIfIsFullscreen() | ||
}) | ||
|
||
/** | ||
* Use global isFullscreen state, based on the screen height check | ||
* | ||
* @return {import('vue').DeepReadonly<import('vue').Ref<boolean>>} | ||
*/ | ||
export function useIsFullscreen() { | ||
return readonly(isFullscreen) | ||
} | ||
|
||
/** | ||
* @deprecated Is to be removed in v9.0.0 with Vue 3 migration. | ||
* Use `composables/useIsFullscreen` instead. | ||
* Defined and exported only for isFullscreen mixin. | ||
*/ | ||
export const isFullscreenState = readonly(isFullscreen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 Grigorii K. Shartsev <[email protected]> | ||
* | ||
* @author Grigorii K. Shartsev <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import { readonly, ref } from 'vue' | ||
|
||
/** | ||
* The minimal width of the viewport to be considered a desktop device | ||
*/ | ||
export const MOBILE_BREAKPOINT = 1024 | ||
|
||
const checkIfIsMobile = () => document.documentElement.clientWidth < MOBILE_BREAKPOINT | ||
|
||
const isMobile = ref(checkIfIsMobile()) | ||
|
||
window.addEventListener('resize', () => { | ||
isMobile.value = checkIfIsMobile() | ||
}) | ||
|
||
/** | ||
* Use global isMobile state, based on the viewport width | ||
* | ||
* @return {import('vue').DeepReadonly<import('vue').Ref<boolean>>} | ||
*/ | ||
export function useIsMobile() { | ||
return readonly(isMobile) | ||
} | ||
|
||
/** | ||
* @deprecated Is to be removed in v9.0.0 with Vue 3 migration. | ||
* Use `composables/useIsMobile` instead. | ||
* Defined and exported only for isMobile mixin. | ||
*/ | ||
export const isMobileState = readonly(isMobile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.