-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31452 from margelo/@chrispader/use-theme-illustra…
…tions Feature: Implement theme dependent illustrations (`useThemeIllustrations` hook)
- Loading branch information
Showing
11 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
import DarkIllustrations from './dark'; | ||
import {Illustrations} from './types'; | ||
|
||
const ThemeIllustrationsContext = React.createContext<Illustrations>(DarkIllustrations); | ||
|
||
export default ThemeIllustrationsContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, {useMemo} from 'react'; | ||
import useThemePreference from '@styles/themes/useThemePreference'; | ||
import DarkIllustrations from './dark'; | ||
import LightIllustrations from './light'; | ||
import ThemeIllustrationsContext from './ThemeIllustrationsContext'; | ||
|
||
type ThemeIllustrationsProviderProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
function ThemeIllustrationsProvider({children}: ThemeIllustrationsProviderProps) { | ||
const themePreference = useThemePreference(); | ||
|
||
const illustrations = useMemo(() => (themePreference === 'dark' ? DarkIllustrations : LightIllustrations), [themePreference]); | ||
|
||
return <ThemeIllustrationsContext.Provider value={illustrations}>{children}</ThemeIllustrationsContext.Provider>; | ||
} | ||
|
||
ThemeIllustrationsProvider.displayName = 'ThemeIllustrationsProvider'; | ||
|
||
export default ThemeIllustrationsProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import EmptyStateBackgroundImage from '@assets/images/empty-state_background-fade-dark.png'; | ||
import {Illustrations} from './types'; | ||
|
||
const illustrations = { | ||
EmptyStateBackgroundImage, | ||
} satisfies Illustrations; | ||
|
||
export default illustrations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import EmptyStateBackgroundImage from '@assets/images/empty-state_background-fade-light.png'; | ||
import {Illustrations} from './types'; | ||
|
||
const illustrations = { | ||
EmptyStateBackgroundImage, | ||
} satisfies Illustrations; | ||
|
||
export default illustrations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {ImageSourcePropType} from 'react-native'; | ||
|
||
type Illustrations = { | ||
EmptyStateBackgroundImage: ImageSourcePropType; | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export {type Illustrations}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {useContext} from 'react'; | ||
import ThemeIllustrationsContext from './ThemeIllustrationsContext'; | ||
|
||
function useThemeIllustrations() { | ||
const illustrations = useContext(ThemeIllustrationsContext); | ||
|
||
if (!illustrations) { | ||
throw new Error('ThemeIllustrationsContext was null! Are you sure that you wrapped the component under a <ThemeIllustrationsProvider>?'); | ||
} | ||
|
||
return illustrations; | ||
} | ||
|
||
export default useThemeIllustrations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters