Skip to content
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

feat(components-native): AtlantisThemeContext for mobile #2387

Merged
merged 23 commits into from
Feb 24, 2025

Conversation

jdeichert
Copy link
Contributor

@jdeichert jdeichert commented Feb 19, 2025

Motivations

This PR adds a new mobile component: AtlantisThemeContextProvider. This component behaves similar to our web version with the exact same API.

We also expose a useAtlantisTheme() hook. This is slightly different from the web version because it also returns a setTheme() method which allows you to change the theme globally. The web version is a little more complex because it needs to dispatch a global event (via updateTheme()) that all theme providers (in various distinct react roots) listen for. Mobile doesn't need that complexity as we only have one react tree and not a bunch of disparate islands.

Changes

Added

  • New AtlantisThemeContextProvider for mobile

Testing

There's not much testing to do. This is a new component that will not affect JM at all until we start using it, which will be in followup PRs.

  • Check out the new mobile stories
    • Note that the contents inside the theme provider don't look correct in dark mode! We'll be slowly adding dark theme support to all native components, starting with a few prioritized ones.
  • Check out the docs page update
    • Documents mobile usage

Changes can be tested via Pre-release

Copy link

cloudflare-workers-and-pages bot commented Feb 19, 2025

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7e177f9
Status: ✅  Deploy successful!
Preview URL: https://1e53e2fb.atlantis.pages.dev
Branch Preview URL: https://job-116234-theme-context-for.atlantis.pages.dev

View logs

Copy link

cloudflare-workers-and-pages bot commented Feb 20, 2025

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9fe8b36
Status:⚡️  Build in progress...

View logs

useAtlantisTheme,
} from "@jobber/components-native";

export default {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some basic stories. They won't look correct in dark mode until we update the entire library to use buildThemedStyles.

Screen.Recording.2025-02-20.at.1.46.26.PM.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, after I recorded this video I reverted the Button style changes. @Aiden-Brine's PR will handle that!

children,
dangerouslyOverrideTheme,
}: AtlantisThemeContextProviderProps) {
// TODO: check last saved theme from local/device storage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a TODO for the future when we actually do dark mode in JM

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9fe8b36
Status: ✅  Deploy successful!
Preview URL: https://325d3cc1.atlantis.pages.dev
Branch Preview URL: https://job-116234-theme-context-for.atlantis.pages.dev

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3c05faf
Status:⚡️  Build in progress...

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: a7d4432
Status:⚡️  Build in progress...

View logs

@@ -18,7 +18,7 @@ const skeletonHTML = (theme: Theme, type: "web" | "mobile") => {
return `

<!DOCTYPE html>
<html data-theme="${type === "web" ? theme : "light"}" data-type="${type}">
<html data-theme="${theme}" data-type="${type}">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got dark mode working with mobile iframes:

Screen.Recording.2025-02-21.at.9.42.13.AM.mov

if (iframeMobile.current) {
const iframeMobileWindow = iframeMobile.current.contentWindow;
iframeMobileWindow?.postMessage({ type: "updateTheme", theme }, "*");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the docs site theme is toggled, this also toggles the mobile iframe preview just like the web one above.

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3c05faf
Status: ✅  Deploy successful!
Preview URL: https://4fdb6165.atlantis.pages.dev
Branch Preview URL: https://job-116234-theme-context-for.atlantis.pages.dev

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: a7d4432
Status: ✅  Deploy successful!
Preview URL: https://395668db.atlantis.pages.dev
Branch Preview URL: https://job-116234-theme-context-for.atlantis.pages.dev

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5348136
Status:⚡️  Build in progress...

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5348136
Status: ✅  Deploy successful!
Preview URL: https://89b8698d.atlantis.pages.dev
Branch Preview URL: https://job-116234-theme-context-for.atlantis.pages.dev

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 556789c
Status:⚡️  Build in progress...

View logs

Copy link

Deploying atlantis with  Cloudflare Pages  Cloudflare Pages

Latest commit: 556789c
Status: ✅  Deploy successful!
Preview URL: https://a3b0d0e6.atlantis.pages.dev
Branch Preview URL: https://job-116234-theme-context-for.atlantis.pages.dev

View logs

@jdeichert jdeichert marked this pull request as ready for review February 21, 2025 19:01
@jdeichert jdeichert requested a review from a team as a code owner February 21, 2025 19:01
* Force the theme for this provider to always be the same as the provided theme. Useful for sections that should remain the same theme regardless of the rest of the application's theme.
* This is dangerous because the children in this provider will not be able to change the theme.
*/
readonly dangerouslyOverrideTheme?: Theme;
Copy link
Contributor

@Aiden-Brine Aiden-Brine Feb 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably too late for this component because I know we use this language on the web theme provider but ideally should this be "unsafe" instead of "dangerous" to be more consistent with our current naming or is there a difference between an unsafe action and a dangerous action? This definitely isn't for this PR but I wanted to raise it to chat about

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the code I think this is the only place we use "dangerous"

Copy link
Contributor Author

@jdeichert jdeichert Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point. This predates our decisions around using unsafe terminology. I believe the original intent for using dangerously is that it's similar to other react props, like dangerouslySetInnerHTML.

I'll create a ticket to rename these props in atlantis and consumers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the ticket, it's in our backlog 👍

@@ -61,6 +61,50 @@ function ThemedComponent() {
}
```

### Usage for mobile
Copy link
Contributor

@Aiden-Brine Aiden-Brine Feb 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage sections give enough information to figure out how to use both web and mobile but how about a small section to highlight the differences so that if someone who is familiar with one is looking at the other they can quickly see the differences in usages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will add this today!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some docs above!

Copy link
Contributor

@Aiden-Brine Aiden-Brine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two non-blocking questions but otherwise this looks really nice!


On web, you'll need to import the `updateTheme` function and call it with the
new theme. This is a separate function because it synchronizes the theme update
across all providers in various react trees (due to our island architecture).
Copy link
Contributor

@Aiden-Brine Aiden-Brine Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say "to handle cases where a React Island architecture is used" since there is potential that someone outside of Jobber is reading these docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think outlining specifics about our architecture might be fine. We do reference internal specifics in other places, see https://atlantis.getjobber.com/content/voice-and-tone for example.

Screenshot 2025-02-24 at 10 04 40 AM

While I don't think this change is necessary, I'll make the adjustment as it's pretty small and still gets the point across.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@jdeichert jdeichert merged commit 1c3085f into master Feb 24, 2025
12 checks passed
@jdeichert jdeichert deleted the JOB-116234/theme-context-for-mobile branch February 24, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants