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

Fix Viewer with Fullscreen mode toggle #9607

Merged
merged 2 commits into from
May 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 54 additions & 15 deletions src/composables/useViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { computed, nextTick, ref, watch } from 'vue'

import { useIsInCall } from './useIsInCall.js'
import { useStore } from './useStore.js'

Expand All @@ -29,19 +31,59 @@ import { useStore } from './useStore.js'
* @param {object} list - The list of the files to be opened
*/

/**
* FIXME Remove this hack once it is possible to set the parent
* element of the viewer.
* By default the viewer is a sibling of the fullscreen element, so
* it is not visible when in fullscreen mode. It is not possible to
* specify the parent nor to know when the viewer was actually
* opened, so for the time being it is reparented if needed shortly
* after calling it.
*
* @see https://github.com/nextcloud/viewer/issues/995
*
* @param {boolean} isFullscreen - is currently in fullscreen mode
*/
function reparentViewer(isFullscreen) {
const viewerElement = document.getElementById('viewer')

if (isFullscreen) {
// When changed to the fullscreen mode, Viewer should be moved to the talk app
document.getElementById('content-vue').appendChild(viewerElement)
} else {
// In normal mode if it was in fullscreen before, move back to body
// Otherwise it will be overlapped by web-page's header
document.body.appendChild(viewerElement)
}
}

/**
* Is Viewer currently opened
*
* @type {import('vue').Ref<boolean>}
*/
const isViewerOpen = ref(false)

/**
* Composable with OCA.Viewer helpers
*
* @return {{ openViewer: OpenViewer }}
* @return {{ openViewer: OpenViewer, isViewerOpen: import('vue').Ref<boolean> }}
*/
export function useViewer() {
const store = useStore()
const isInCall = useIsInCall()
const isFullscreen = computed(() => store.getters.isFullscreen())

watch(isFullscreen, () => {
if (isViewerOpen.value) {
reparentViewer(isFullscreen.value)
}
})

/**
* @type {OpenViewer}
*/
const openViewer = (path, list) => {
const openViewer = async (path, list) => {
if (!OCA.Viewer) {
return false
}
Expand All @@ -59,26 +101,23 @@ export function useViewer() {
path,
list,
onClose: () => {
isViewerOpen.value = false
store.dispatch('setCallViewMode', { isViewerOverlay: false })
},
})

// FIXME Remove this hack once it is possible to set the parent
// element of the viewer.
// By default the viewer is a sibling of the fullscreen element, so
// it is not visible when in fullscreen mode. It is not possible to
// specify the parent nor to know when the viewer was actually
// opened, so for the time being it is reparented if needed shortly
// after calling it.
// @see https://github.com/nextcloud/viewer/issues/995
setTimeout(() => {
if (store.getters.isFullscreen()) {
document.getElementById('content-vue').appendChild(document.getElementById('viewer'))
}
}, 1000)
// Wait Viewer to be mounted
await nextTick()

isViewerOpen.value = true

if (isFullscreen.value) {
reparentViewer(true)
}
}

return {
isViewerOpen,
openViewer,
}
}