-
Notifications
You must be signed in to change notification settings - Fork 34
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
Switch between light and dark themes in Prebuilt UI #231
Comments
Hey @ahkhanjani, you'll want to pass both objects to To achieve that, pass both theme objects like this: const CALL_OPTIONS: DailyFactoryOptions = {
strictMode: true,
showLeaveButton: true,
showFullscreenButton: true,
iframeStyle: {
top: "0",
left: "0",
width: "100%",
height: "100%",
border: "0",
borderRadius: "0",
},
theme: {
light: {
colors: LIGHT_THEME,
},
dark: {
colors: DARK_THEME,
}
}
}; You don't have to call Let me know if this solves the issue for you. Best, |
Hi @Regaddi. Thank you for the explanation.
Is this part mentioned in the docs? I don't remember seeing this. If it's not mentioned I think we should add it there. This might be natural for vanilla CSS users but for those of us who use things like Tailwind and Best regards |
While the |
Hey @Regaddi,
It turns out that this doesn't work when we want to switch between light/dark modes independent of user's system settings, since we can't change I think we should have an option like: { darkMode?: boolean | undefined; setDarkMode: (darkMode: boolean | undefined) => void } So that when it's undefined, it defaults to
If Daily does what I think it does, it should solve this issue. But even if they are unrelated, this should improve the DX of working with light/dark themed apps. Best regards |
Hey @ahkhanjani, in this case you'll want to initialize the callFrame with the appropriate color theme, as set in your custom theme settings: useEffect(() => {
if (!callRef.current) return;
const newCallFrame = DailyIframe.createFrame(callRef.current, {
...CALL_OPTIONS,
theme: getCurrentTheme(resolvedTheme),
});
// ...
void newCallFrame.join({ ... });
}, [createAndJoinCall, resolvedTheme]); That will pretty much ignore any Let me know how that goes! |
@Regaddi That's a solution. The reason I didn't go for this approach was the problems discussed in #229. Since But with that being said, I think there is not much to do until #229 is solved and we can handle everything including theme change via the new internal hook or something. Thanks for your patience |
Hey @ahkhanjani, following up here to check if there's anything else you need to have this issue resolved, since #229 is resolved now. Best, |
Hey @Regaddi,
I'm having some trouble setting the new hook up. Like mentioned here. After successfully migrating and testing this issue I will let you know. |
Now that it's working, I tried passing the theme directly to the new hook options: const { resolvedTheme } = useTheme();
const callFrame = useCallFrame({
...,
options: { ...CALL_OPTIONS, theme: getCurrentTheme(resolvedTheme) },
}); The flash is still there. I can't tell what exactly causes it but I'm guessing it's one of these two scenarios:
Also passing the theme -which can change at any time by the user- to the call options seems to trigger a full reload of the call frame. So I'm assuming nothing passed to If the problem is number 2, the fix should be as straightforward as changing the background color of the initial parent of the call to transparent. Please let me know if that's not the case. Thanks for your hard work, |
@ahkhanjani I'm working on a fix to prevent the flash of un-themed colors you are experiencing. When the iframe is created initially, it has
You'll only want to pass the initial theme to const [initialConfigApplied, setInitialConfigApplied] = useState(false);
const callFrame = useCallFrame({
parentEl: callRef.current,
options: { ...CALL_OPTIONS, theme: getCurrentTheme(resolvedTheme) },
shouldCreateInstance: useCallback(() => !initialConfigApplied, [initialConfigApplied]),
});
useEffect(() => {
if (!callFrame) return;
callFrame.once('loaded', () => setInitialConfigApplied(true));
}, [callFrame]); To update the theme at runtime you'll want to use |
Should
I just tested this and it does solve the reloading problem. But visually nothing has changed. I assume this will be needed after the fix? useEffect(() => {
if (!callFrame) {
return;
}
void callFrame.setTheme(getCurrentTheme(resolvedTheme));
}, [callFrame, resolvedTheme]); React makes it so difficult to actually understand what happens when. So I wonder if |
Hey @ahkhanjani, I think all the issues you ran into should be solved by now.
This shouldn't be required anymore, unless the |
Hi @Regaddi. The rough edges and bugs all seem to be fixed. From this issue, the white flashing problem still remains. |
Hey @ahkhanjani, could you share a reproduction of the flashing issue? It should be resolved already and I can't reproduce it myself. Thanks in advance! |
My apologies @Regaddi. I made a codesandbox repro and as you said didn't see any of the two problems I'm facing. Turns out the theme library I'm using, Thank you. |
Hey @Regaddi, sorry to bother again.
If there is an actual problem and not some newbie mistake, it could be a very niche Daily bug that we might find. Edit: I figured out not creating call frame instance problem. Using dynamic import causes it. |
Alternatively we could invite you for a session in our classroom to see the problem in action. Our product is up and running. Anything that helps spot the issue. |
I'm currently using
.setTheme()
method to change the colors object entirely on theme change. But since Daily already provides a means to initialize the objects themselves, using that sounds more reasonable. Except I couldn't find any documented way of switching between light and dark modes.The reason I'm interested in this approach is that, when the iframe is initializing, if the website is in dark mode, there will be a white background flash for a moment. I can't figure out which element exactly is causing this. Event setting the initial colors to the dark mode colors doesn't do the trick. So maybe Daily needs both themes initially + a way to know that we're in dark mode so that it can use that color scheme before our
useEffect
kicks in and sets the colors object.Here's my code:
The text was updated successfully, but these errors were encountered: