Skip to content

Commit

Permalink
Fix dark mode edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Mar 30, 2024
1 parent 4b7a994 commit 43f2779
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 66 deletions.
109 changes: 51 additions & 58 deletions src/viser/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import { SynchronizedCameraControls } from "./CameraControls";
import {
Anchor,
Box,
ColorSchemeScript,
Image,
MantineProvider,
Modal,
Tooltip,
createTheme,
useMantineColorScheme,
useMantineTheme,
} from "@mantine/core";
import React, { useEffect } from "react";
Expand Down Expand Up @@ -162,65 +162,69 @@ function ViewerContents() {
const colors = viewer.useGui((state) => state.theme.colors);
const control_layout = viewer.useGui((state) => state.theme.control_layout);
return (
<MantineProvider
theme={createTheme({
...theme,
...(colors === null
? {}
: { colors: { custom: colors }, primaryColor: "custom" }),
})}
>
<Notifications
position="top-left"
containerWidth="20em"
styles={{
root: {
boxShadow: "0.1em 0 1em 0 rgba(0,0,0,0.1) !important",
},
}}
/>
<ViserModal />
<Box
style={{
width: "100%",
height: "100%",
// We use flex display for the titlebar layout.
display: "flex",
position: "relative",
flexDirection: "column",
}}
<>
<ColorSchemeScript forceColorScheme={dark_mode ? "dark" : "light"} />
<MantineProvider
theme={createTheme({
...theme,
...(colors === null
? {}
: { colors: { custom: colors }, primaryColor: "custom" }),
})}
forceColorScheme={dark_mode ? "dark" : "light"}
>
<Titlebar />
<Notifications
position="top-left"
containerWidth="20em"
styles={{
root: {
boxShadow: "0.1em 0 1em 0 rgba(0,0,0,0.1) !important",
},
}}
/>
<ViserModal />
<Box
style={{
// Put the canvas and control panel side-by-side.
width: "100%",
position: "relative",
flexGrow: 1,
overflow: "hidden",
height: "100%",
// We use flex display for the titlebar layout.
display: "flex",
position: "relative",
flexDirection: "column",
}}
>
<Titlebar />
<Box
style={(theme) => ({
backgroundColor: dark_mode ? theme.colors.dark[9] : "#fff",
style={{
// Put the canvas and control panel side-by-side.
width: "100%",
position: "relative",
flexGrow: 1,
overflow: "hidden",
height: "100%",
})}
display: "flex",
}}
>
<Viewer2DCanvas />
<ViewerCanvas>
<FrameSynchronizedMessageHandler />
</ViewerCanvas>
{viewer.useGui((state) => state.theme.show_logo) ? (
<ViserLogo />
) : null}
<Box
style={(theme) => ({
backgroundColor: dark_mode ? theme.colors.dark[9] : "#fff",
flexGrow: 1,
overflow: "hidden",
height: "100%",
})}
>
<Viewer2DCanvas />
<ViewerCanvas>
<FrameSynchronizedMessageHandler />
</ViewerCanvas>
{viewer.useGui((state) => state.theme.show_logo) ? (
<ViserLogo />
) : null}
</Box>
<ControlPanel control_layout={control_layout} />
</Box>
<ControlPanel control_layout={control_layout} />
</Box>
</Box>
</MantineProvider>
</MantineProvider>
</>
);
}

Expand All @@ -232,17 +236,6 @@ function ViewerCanvas({ children }: { children: React.ReactNode }) {
);
const theme = useMantineTheme();

// Overwrite the Mantine color scheme, which is persisted in local storage.
// This doesn't really belong to the canvas, it just needs to be run
// somewhere within the Mantine + viewer contexts.
const mantineColorScheme = useMantineColorScheme();
const colorScheme = viewer.useGui((state) => state.theme.dark_mode)
? "dark"
: "light";
useEffect(() => {
mantineColorScheme.setColorScheme(colorScheme);
});

return (
<Canvas
camera={{ position: [-3.0, 3.0, -3.0], near: 0.05 }}
Expand Down
9 changes: 1 addition & 8 deletions src/viser/client/src/WebsocketInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ import {
import { isGuiConfig } from "./ControlPanel/GuiState";
import { useFrame } from "@react-three/fiber";
import GeneratedGuiContainer from "./ControlPanel/Generated";
import {
MantineProvider,
Paper,
Progress,
useMantineColorScheme,
} from "@mantine/core";
import { MantineProvider, Paper, Progress } from "@mantine/core";
import { IconCheck } from "@tabler/icons-react";
import { computeT_threeworld_world } from "./WorldTransformUtils";
import { theme } from "./AppTheme";
Expand Down Expand Up @@ -75,7 +70,6 @@ function useMessageHandler() {
const updateGuiProps = viewer.useGui((state) => state.updateGuiProps);
const setClickable = viewer.useSceneTree((state) => state.setClickable);
const updateUploadState = viewer.useGui((state) => state.updateUploadState);
const colorScheme = useMantineColorScheme();

// Same as addSceneNode, but make a parent in the form of a dummy coordinate
// frame if it doesn't exist yet.
Expand Down Expand Up @@ -131,7 +125,6 @@ function useMessageHandler() {
// Configure the theme.
case "ThemeConfigurationMessage": {
setTheme(message);
colorScheme.setColorScheme(message.dark_mode ? "dark" : "light");
return;
}
// Enable/disable whether scene pointer events are sent.
Expand Down

0 comments on commit 43f2779

Please sign in to comment.