🎥 Make videos programmatically with React
hide rulers in asset view
Jonny Burgerb5934b9f666a
diff --git a/packages/cli/src/editor/components/Canvas.tsx b/packages/cli/src/editor/components/Canvas.tsxindex 75b6897144..e1c811c28e 100644--- a/packages/cli/src/editor/components/Canvas.tsx+++ b/packages/cli/src/editor/components/Canvas.tsx@@ -24,11 +24,11 @@ import {import {useKeybinding} from '../helpers/use-keybinding';import {canvasRef as ref} from '../state/canvas-ref';import {EditorShowGuidesContext} from '../state/editor-guides';-import {EditorShowRulersContext} from '../state/editor-rulers';import {EditorZoomGesturesContext} from '../state/editor-zoom-gestures';import {PreviewSizeContext} from '../state/preview-size';import EditorGuides from './EditorGuides';import {EditorRulers} from './EditorRuler';+import {useIsRulerVisible} from './EditorRuler/use-is-ruler-visible';import {SPACING_UNIT} from './layout';import {VideoPreview} from './Preview';import {ResetZoomButton} from './ResetZoomButton';@@ -56,7 +56,7 @@ export const Canvas: React.FC<{const {editorZoomGestures} = useContext(EditorZoomGesturesContext);const keybindings = useKeybinding();const config = Internals.useUnsafeVideoConfig();- const {editorShowRulers} = useContext(EditorShowRulersContext);+ const areRulersVisible = useIsRulerVisible();const {editorShowGuides} = useContext(EditorShowGuidesContext);const [assetResolution, setAssetResolution] = useState<AssetMetadata | null>(@@ -339,7 +339,7 @@ export const Canvas: React.FC<{/>)}</div>- {editorShowRulers && (+ {areRulersVisible && (<EditorRulerscontentDimensions={contentDimensions}canvasSize={size}diff --git a/packages/cli/src/editor/components/EditorRuler/Ruler.tsx b/packages/cli/src/editor/components/EditorRuler/Ruler.tsxindex 90a2b3e84b..d1b9130c71 100644--- a/packages/cli/src/editor/components/EditorRuler/Ruler.tsx+++ b/packages/cli/src/editor/components/EditorRuler/Ruler.tsx@@ -6,6 +6,7 @@ import React, {useRef,useState,} from 'react';+import {Internals} from 'remotion';import {TIMELINE_BACKGROUND} from '../../helpers/colors';import {drawMarkingOnRulerCanvas} from '../../helpers/editor-ruler';import {EditorShowGuidesContext} from '../../state/editor-guides';@@ -47,6 +48,12 @@ const Ruler: React.FC<RulerProps> = ({selectedGuideId,setSelectedGuideId,} = useContext(EditorShowGuidesContext);+ const unsafeVideoConfig = Internals.useUnsafeVideoConfig();++ if (!unsafeVideoConfig) {+ throw new Error('Video config not set');+ }+const [cursor, setCursor] = useState<'ew-resize' | 'ns-resize' | 'no-drop'>(isVerticalRuler ? 'ew-resize' : 'ns-resize',);@@ -96,6 +103,7 @@ const Ruler: React.FC<RulerProps> = ({position: -originOffset,show: false,id: guideId,+ compositionId: unsafeVideoConfig.id,},];});@@ -106,6 +114,7 @@ const Ruler: React.FC<RulerProps> = ({setGuidesList,orientation,originOffset,+ unsafeVideoConfig.id,],);diff --git a/packages/cli/src/editor/components/EditorRuler/use-is-ruler-visible.ts b/packages/cli/src/editor/components/EditorRuler/use-is-ruler-visible.tsnew file mode 100644index 0000000000..31b71fdd1b--- /dev/null+++ b/packages/cli/src/editor/components/EditorRuler/use-is-ruler-visible.ts@@ -0,0 +1,12 @@+import {useContext} from 'react';+import {Internals} from 'remotion';+import {EditorShowRulersContext} from '../../state/editor-rulers';++export const useIsRulerVisible = () => {+ const {canvasContent} = useContext(Internals.CompositionManager);+ const {editorShowRulers} = useContext(EditorShowRulersContext);++ return (+ editorShowRulers && canvasContent && canvasContent.type === 'composition'+ );+};diff --git a/packages/cli/src/editor/components/TopPanel.tsx b/packages/cli/src/editor/components/TopPanel.tsxindex 625929314c..4a04fd9e10 100644--- a/packages/cli/src/editor/components/TopPanel.tsx+++ b/packages/cli/src/editor/components/TopPanel.tsx@@ -1,12 +1,13 @@import React, {useCallback, useContext, useMemo} from 'react';import {useBreakpoint} from '../helpers/use-breakpoint';-import {EditorShowRulersContext, RULER_WIDTH} from '../state/editor-rulers';+import {RULER_WIDTH} from '../state/editor-rulers';import {SidebarContext} from '../state/sidebar';import {CanvasOrLoading} from './CanvasOrLoading';import {CurrentCompositionKeybindings,TitleUpdater,} from './CurrentCompositionSideEffects';+import {useIsRulerVisible} from './EditorRuler/use-is-ruler-visible';import {ExplorerPanel} from './ExplorerPanel';import {InitialCompositionLoader} from './InitialCompositionLoader';import {MenuToolbar} from './MenuToolbar';@@ -53,7 +54,7 @@ export const useResponsiveSidebarStatus = (): 'collapsed' | 'expanded' => {export const TopPanel: React.FC = () => {const {setSidebarCollapsedState, sidebarCollapsedStateRight} =useContext(SidebarContext);- const {editorShowRulers} = useContext(EditorShowRulersContext);+ const rulersAreVisible = useIsRulerVisible();const actualStateLeft = useResponsiveSidebarStatus();@@ -69,10 +70,10 @@ export const TopPanel: React.FC = () => {() => ({flex: 1,display: 'flex',- paddingTop: editorShowRulers ? RULER_WIDTH : 0,- paddingLeft: editorShowRulers ? RULER_WIDTH : 0,+ paddingTop: rulersAreVisible ? RULER_WIDTH : 0,+ paddingLeft: rulersAreVisible ? RULER_WIDTH : 0,}),- [editorShowRulers],+ [rulersAreVisible],);const onCollapseLeft = useCallback(() => {diff --git a/packages/cli/src/editor/state/editor-guides.ts b/packages/cli/src/editor/state/editor-guides.tsindex ed428115e4..01e4d463af 100644--- a/packages/cli/src/editor/state/editor-guides.ts+++ b/packages/cli/src/editor/state/editor-guides.ts@@ -5,6 +5,7 @@ export type Guide = {position: number;show: boolean;id: string;+ compositionId: string;};export type GuideState = {