Skip to content

Commit

Permalink
Merge pull request #5750 from nextcloud/fix/request-animation-frame
Browse files Browse the repository at this point in the history
fix(editor): requestAnimationFrame in onResize callbacks
  • Loading branch information
juliusknorr authored May 4, 2024
2 parents adb887e + 5b53cf7 commit a0929ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,12 @@ export default {
subscribe('text:image-node:delete', this.onDeleteImageNode)
this.emit('update:loaded', true)
useResizeObserver(this.$el, (entries) => {
const entry = entries[0]
const { width } = entry.contentRect
const maxWidth = width - 36
this.$el.style.setProperty('--widget-full-width', `${maxWidth}px`)
window.requestAnimationFrame(() => {
const entry = entries[0]
const { width } = entry.contentRect
const maxWidth = width - 36
this.$el.style.setProperty('--widget-full-width', `${maxWidth}px`)
})
})
subscribe('text:translate-modal:show', this.showTranslateModal)
},
Expand Down
21 changes: 9 additions & 12 deletions src/components/Editor/EditorOutline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
</template>

<script>
import debounce from 'debounce'
import { NcButton } from '@nextcloud/vue'
import TableOfContents from './TableOfContents.vue'
import { useOutlineStateMixin, useOutlineActions } from './Wrapper.provider.js'
import { Close } from './../icons.js'
import useStore from '../../mixins/store.js'
const onResize = debounce((context) => {
context.mobile = context.$el.parentElement.clientWidth < 320
}, 10)
export default {
name: 'EditorOutline',
components: {
Expand All @@ -39,20 +34,22 @@ export default {
mobile: false,
}),
mounted() {
this.$onResize = () => {
onResize(this)
}
this.$resizeObserver = new ResizeObserver(this.$onResize)
this.$resizeObserver = new ResizeObserver(this.onResize)
this.$resizeObserver.observe(this.$el.parentElement)
this.$onResize()
this.onResize()
},
beforeDestroy() {
this.$resizeObserver.unobserve(this.$el.parentElement)
this.$resizeObserver = null
this.$onResize = null
},
methods: {
onResize([el]) {
window.requestAnimationFrame(() => {
this.mobile = el.clientWidth < 320
})
},
},
}
</script>

Expand Down
19 changes: 10 additions & 9 deletions src/components/Menu/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,18 @@ export default {
},
methods: {
onResize(entries) {
const entry = entries[0]
const { width } = entry.contentRect
window.requestAnimationFrame(() => {
const entry = entries[0]
const { width } = entry.contentRect

// leave some buffer - this is necessary so the bar does not wrap during resizing
const spaceToFill = width - 4
const spacePerSlot = this.$isMobile ? 44 : 46
const slots = Math.floor(spaceToFill / spacePerSlot)
// leave some buffer - this is necessary so the bar does not wrap during resizing
const spaceToFill = width - 4
const spacePerSlot = this.$isMobile ? 44 : 46
const slots = Math.floor(spaceToFill / spacePerSlot)

// Leave one slot empty for the three dot menu
this.iconsLimit = slots - 1
this.isReady = true
// Leave one slot empty for the three dot menu
this.iconsLimit = slots - 1
})
},
showHelp() {
this.displayHelp = true
Expand Down

0 comments on commit a0929ec

Please sign in to comment.