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(Theming): Adds theming support with documentation. #2636

Merged
merged 61 commits into from
Aug 13, 2024
Merged

Conversation

markrickert
Copy link
Member

Please verify the following:

  • yarn test jest tests pass with new tests, if relevant
  • yarn lint eslint checks pass with new code, if relevant
  • yarn format:check prettier checks pass with new code, if relevant
  • README.md (or relevant documentation) has been updated with your changes

Describe your PR

This PR adds theming support to the ignite boilerplate as well as relevant documentation on how to use the theming system.

Note that this PR is onto the v10 branch and not main.

@jamonholmgren
Copy link
Member

Before we merge this, I want to make sure we get some real-world experience. @markrickert you're starting a new project soon, so this will be a good opportunity for that.

Copy link
Member

@jamonholmgren jamonholmgren left a comment

Choose a reason for hiding this comment

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

This is really looking good. Just want to wait for real-world experience.

docs/boilerplate/app/theme/Theming.md Outdated Show resolved Hide resolved
docs/boilerplate/app/theme/Theming.md Outdated Show resolved Hide resolved
docs/boilerplate/app/theme/Theming.md Outdated Show resolved Hide resolved
@markrickert
Copy link
Member Author

@jamonholmgren Absolutely. I'll keep this branch up to date with main and use this as the starting point for my next project.

frankcalise and others added 3 commits March 28, 2024 10:06
* feat: cng ftw

* fix(babel-config): simplify plugins with SDK 50

* fix(boilerplate): remove unused eslint pkgs

* fix(cli): reword workflow question

* fix(cli): remove unnecessary warning
* feat(boilerplate): mmkv in over async storage

* fix(cli): remove async storage new arch specifics

* test(boilerplate): mmkv clean up

* fix(boilerplate): storage.load with just a string

* test(boilerplate): storage test types
… Switch (#2667 by @frankcalise)

* refactor(toggle): split to Checkbox, Radio and Switch components

* fix(boilerplate): update demos to use specific toggle components

* updating deprecated reanimated Extrapolate

* TS fixes

* docs: explode Toggle docs to Checkbox, Radio, Switch

* docs(components): added Checkbox, Radio, Switch to main listing

* fix(boilerplate): remove reanimated from Checkbox

* fix(boilerplate): remove reanimated from Radio

* fix(boilerplate): checkbox, radio match old duration times from default reanimated values

* fix(boilerplate): remove reanimated dep from Switch

* docs(toggle): tsx formatting

* refactor(boilerplate):drop prefix from component specific props

* some missed props

* fix(boilerplate): toggle components accessibilityRole

---------

Co-authored-by: Mazen Chami <mazenchami@gmail.com>
@markrickert markrickert added this to the Ignite v10 milestone May 13, 2024
markrickert and others added 10 commits August 5, 2024 16:29
Makes things easier to test and compare.
Co-authored-by: Lizzi Lindboe <lindboe@users.noreply.github.com>
Co-authored-by: Lizzi Lindboe <lindboe@users.noreply.github.com>
Co-authored-by: Lizzi Lindboe <lindboe@users.noreply.github.com>
markrickert and others added 2 commits August 8, 2024 14:23
Co-authored-by: Lizzi Lindboe <lindboe@users.noreply.github.com>
@lindboe
Copy link
Contributor

lindboe commented Aug 9, 2024

@markrickert I do think we should address #2636 (comment). It not only makes the demo look better, but there are likely to be other use cases where somebody needs to set a theme on non-React components (i.e., imperatively on a native component).

I took a stab at it:

AndroidLessNoticeableJump.mp4

Here's my diff:

diff --git a/app/utils/useAppTheme.ts b/app/utils/useAppTheme.ts
index 8d03a0c..712bf81 100644
--- a/app/utils/useAppTheme.ts
+++ b/app/utils/useAppTheme.ts
@@ -1,4 +1,4 @@
-import { createContext, useCallback, useContext, useMemo, useState } from "react"
+import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react"
 import { StyleProp, useColorScheme } from "react-native"
 import { DarkTheme, DefaultTheme, useTheme as useNavTheme } from "@react-navigation/native"
 import {
@@ -9,6 +9,7 @@ import {
   lightTheme,
   darkTheme,
 } from "app/theme"
+import * as SystemUI from 'expo-system-ui';

 type ThemeContextType = {
   themeScheme: ThemeContexts
@@ -23,6 +24,13 @@ export const ThemeContext = createContext<ThemeContextType>({
   },
 })

+const themeContextToTheme = (themeContext: ThemeContexts): Theme => (
+    themeContext === "dark" ? darkTheme : lightTheme)
+
+const setImperativeThemeing = (theme: Theme) => {
+  SystemUI.setBackgroundColorAsync(theme.colors.background)
+}
+
 export const useThemeProvider = (initialTheme: ThemeContexts = undefined) => {
   const colorScheme = useColorScheme()
   const [overrideTheme, setTheme] = useState<ThemeContexts>(initialTheme)
@@ -34,6 +42,10 @@ export const useThemeProvider = (initialTheme: ThemeContexts = undefined) => {
   const themeScheme = overrideTheme || colorScheme || "light"
   const navigationTheme = themeScheme === "dark" ? DarkTheme : DefaultTheme

+  useEffect(() => {
+    setImperativeThemeing(themeContextToTheme(themeScheme))
+  }, [overrideTheme])
+
   return {
     themeScheme,
     navigationTheme,
@@ -78,7 +90,7 @@ export const useAppTheme = (): UseAppThemeValue => {
   )

   const themeVariant: Theme = useMemo(
-    () => (themeContext === "dark" ? darkTheme : lightTheme),
+    () => themeContextToTheme(themeContext),
     [themeContext],
   )

My only concern here is that we haven't documented using useThemeProvider, which is what would run this. Is that meant to be a required part of the theming system?

Edit: never mind on that framing, I was searching the wrong project.

Instead, do you think this is a good approach to this problem?

Copy link
Contributor

@lindboe lindboe left a comment

Choose a reason for hiding this comment

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

It's looking good to me, just would like your thoughts on the addition of the native background color setting

@lindboe
Copy link
Contributor

lindboe commented Aug 12, 2024

Pushed commit with changes to set native background color after discussion with @markrickert 4fb4d61

Copy link
Contributor

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

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

🚢

nice work everyone!

@lindboe lindboe merged commit a1ae047 into v10 Aug 13, 2024
1 check passed
@lindboe lindboe deleted the mrickert/theming branch August 13, 2024 02:50
@lindboe lindboe mentioned this pull request Aug 13, 2024
4 tasks
infinitered-circleci pushed a commit that referenced this pull request Oct 14, 2024
# [10.0.0](v9.10.1...v10.0.0) (2024-10-14)

### Bug Fixes

* **boilerplate:** expo-router initialize i18n ([#2791](#2791) by [@frankcalise](https://github.com/frankcalise)) ([a00113e](a00113e))
* **boilerplate:** Make icon default color explicit, and respond to dark mode ([#2795](#2795) by [@lindboe](https://github.com/lindboe)) ([b82398d](b82398d))
* **cli:** improper MST removal when using CLI prompt, new arch compat ([#2785](#2785) by [@frankcalise](https://github.com/frankcalise)) ([3956652](3956652))
* remove snackify command and references ([#2763](#2763) by [@frankcalise](https://github.com/frankcalise)) ([09671e8](09671e8))

### Features

* Ignite X with Expo 51 ([005ef05](005ef05))
* **boilerplate:** Toggle component refactored to Checkbox, Radio and Switch ([#2667](#2667) by [@frankcalise](https://github.com/frankcalise)) ([54f5208](54f5208))
* **cli:** expo-router option ([#2727](#2727) by [@frankcalise](https://github.com/frankcalise)) ([8bea1f9](8bea1f9)), closes [#2731](#2731)
* **cli:** generator options --dir and --case  ([#2726](#2726) by [@frankcalise](https://github.com/frankcalise)) ([dff3d24](dff3d24))
* **Theming:** Adds theming support with documentation. ([#2636](#2636)) ([a1ae047](a1ae047))
* **v10:** cng default ([#2641](#2641)) ([c7d998d](c7d998d))
* **v10:** Remove MobX-State-Tree flag for non-demo projects ([#2647](#2647) by @Jpoliachik) ([a738243](a738243))
* add MMKV for v10 ([#2660](#2660) by [@frankcalise](https://github.com/frankcalise)) ([9164e5e](9164e5e))

### BREAKING CHANGES

* Ignite X is out now! This update adds:

* Expo Prebuild as default
* Dark mode support
* Static routing with Expo Router
* Flexible generator directory support
* Option to remove mobx-state-tree
* AsyncStorage->MMKV
* New i18n configuration with react-i18next
* Lint configuration updates
* Toggle component → Checkbox, Radio, and Switch
* Improved keyboard avoidance
* Component test example configuration

Read all about it in our blog article!

https://shift.infinite.red/what-is-ignite-x-9ecde0b34d75
@infinitered-circleci
Copy link

🎉 This PR is included in version 10.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet