From 9d60993f8d2bd5e339321abddfdb0cf8b42e1921 Mon Sep 17 00:00:00 2001 From: Arthur Jamet Date: Tue, 2 May 2023 14:13:57 +0100 Subject: [PATCH] Front: Partition View: Fix disappearing cursor on resize --- front/components/PartitionView.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/front/components/PartitionView.tsx b/front/components/PartitionView.tsx index de6b47c..609ce46 100644 --- a/front/components/PartitionView.tsx +++ b/front/components/PartitionView.tsx @@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'; import { CursorType, Fraction, OpenSheetMusicDisplay as OSMD } from 'opensheetmusicdisplay'; import useColorScheme from '../hooks/colorScheme'; +import { useWindowDimensions } from 'react-native'; type PartitionViewProps = { // The Buffer of the MusicXML file retreived from the API @@ -17,6 +18,7 @@ const PartitionView = (props: PartitionViewProps) => { const [osmd, setOsmd] = useState(); const colorScheme = useColorScheme(); const [currentWindowIndex, setCurrentWindowIndex] = useState(0); + const dimensions = useWindowDimensions(); const options = { darkMode: colorScheme == 'dark', drawComposer: false, @@ -28,7 +30,7 @@ const PartitionView = (props: PartitionViewProps) => { drawFromMeasureNumber: 1, drawUpToMeasureNumber: WINDOW_SIZE, stretchLastSystemLine: true, - autoResize: true, + autoResize: false, } useEffect(() => { @@ -37,11 +39,19 @@ const PartitionView = (props: PartitionViewProps) => { .then(() => { _osmd.render(); props.onPartitionReady(); - _osmd.cursor.show(); + _osmd.cursor.show(); + console.log(_osmd.Sheet.DefaultStartTempoInBpm) }); setOsmd(_osmd); }, []); + // Re-render manually (otherwise done by 'autoResize' option), to fix disappearing cursor + useEffect(() => { + if (osmd) { + osmd.render(); + osmd.cursor.show(); + } + }, [dimensions]) useEffect(() => {