-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
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 @@ | ||
{ | ||
"label": "Advanced", | ||
"position": 3, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Learn the more advanced usecases" | ||
} | ||
} |
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,76 @@ | ||
--- | ||
sidebar_position: 1 | ||
title: Get Theme value in global | ||
--- | ||
|
||
|
||
|
||
# Get Theme Value Globally | ||
|
||
The React Native Styled System does not provide a way to retrieve themes from globally outside of React's Context. | ||
|
||
However, when you pass a theme to `StyledSystemProvider`, you can store the theme as a global object and reference it in your code where this theme changes. | ||
|
||
Let's say you have a Wrapper component in your code that wraps a `StyledSystemProvider` like this: | ||
|
||
```tsx | ||
import... | ||
import StyledSystemTheme from './AppTheme' | ||
|
||
export const StyledSystemAppThemeProvider = ({ children }: PropsWithChildren<{}>) => { | ||
const { sfTop, sfBottom, sfLeft, sfRight } = useSafeAreaValues(); | ||
|
||
const theme = useMemo(() => { | ||
const safeArea = { sfTop, sfRight, sfBottom, sfLeft }; | ||
return { | ||
...StyledSystemTheme, | ||
sizes: { ...StyledSystemTheme.sizes, ...safeArea }, | ||
space: { ...StyledSystemTheme.space, ...safeArea }, | ||
}; | ||
}, [sfLeft, sfTop, sfRight, sfBottom]); | ||
|
||
return <StyledSystemProvider theme={theme}>{children}</StyledSystemProvider>; | ||
}; | ||
``` | ||
|
||
Now, when the `theme` object changes, we save it for reference as a global variable. | ||
|
||
```tsx | ||
import... | ||
import StyledSystemTheme from './AppTheme' | ||
|
||
//highlight-start | ||
let _globalTheme: ThemedDict = StyledSystemTheme; | ||
export const getGlobalTheme = () => _globalTheme; | ||
//highlight-end | ||
|
||
export const StyledSystemAppThemeProvider = ({ children }: PropsWithChildren<{}>) => { | ||
const { sfTop, sfBottom, sfLeft, sfRight } = useSafeAreaValues(); | ||
|
||
const theme = useMemo(() => { | ||
const safeArea = { sfTop, sfRight, sfBottom, sfLeft }; | ||
return { | ||
...StyledSystemTheme, | ||
sizes: { ...StyledSystemTheme.sizes, ...safeArea }, | ||
space: { ...StyledSystemTheme.space, ...safeArea }, | ||
}; | ||
}, [sfLeft, sfTop, sfRight, sfBottom]); | ||
|
||
//highlight-start | ||
useEffect(() => { | ||
globalTheme = theme; | ||
}, [theme]); | ||
//highlight-end | ||
|
||
return <StyledSystemProvider theme={theme}>{children}</StyledSystemProvider>; | ||
}; | ||
``` | ||
|
||
We can now reference the theme via `getGlobalTheme()` in our code. | ||
|
||
:::warning | ||
Note that the latest `theme` value may not always be referenced. | ||
|
||
For example, save the value returned by `getGlobalTheme()` in a variable and then | ||
If you try to use it after the theme value has changed, it will point to the old value. | ||
::: |
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,14 @@ | ||
{ | ||
"title": { | ||
"message": "Blog", | ||
"description": "The title for the blog used in SEO" | ||
}, | ||
"description": { | ||
"message": "Blog", | ||
"description": "The description for the blog used in SEO" | ||
}, | ||
"sidebar.title": { | ||
"message": "Recent posts", | ||
"description": "The label for the left sidebar" | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
doc/i18n/ko/docusaurus-plugin-content-docs/current/advanced/global-theme-value.mdx
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,76 @@ | ||
--- | ||
sidebar_position: 1 | ||
title: 전역 테마 객체 참조 | ||
--- | ||
|
||
# 전역 테마 객체 참조 | ||
|
||
React Native Styled System은 React의 Context 외부의 전역에서 테마를 가져오는 | ||
방식을 제공하지 않습니다. | ||
|
||
그러나 `StyledSystemProvider`에 테마를 전달할 때, 이 테마가 변경되는 당신의 코드에서 | ||
전역 객체로 테마를 저장해두고 참조할 수 있습니다. | ||
|
||
다음과 같은 `StyledSystemProvider`를 감싸는 당신의 코드의 Wrapper 컴포넌트가 있다고 해보겠습니다. | ||
|
||
```tsx | ||
import ... | ||
import StyledSystemTheme from './AppTheme' | ||
|
||
export const StyledSystemAppThemeProvider = ({ children }: PropsWithChildren<{}>) => { | ||
const { sfTop, sfBottom, sfLeft, sfRight } = useSafeAreaValues(); | ||
|
||
const theme = useMemo(() => { | ||
const safeArea = { sfTop, sfRight, sfBottom, sfLeft }; | ||
return { | ||
...StyledSystemTheme, | ||
sizes: { ...StyledSystemTheme.sizes, ...safeArea }, | ||
space: { ...StyledSystemTheme.space, ...safeArea }, | ||
}; | ||
}, [sfLeft, sfTop, sfRight, sfBottom]); | ||
|
||
return <StyledSystemProvider theme={theme}>{children}</StyledSystemProvider>; | ||
}; | ||
``` | ||
|
||
이제 `theme`객체가 변경될 때 이를 전역 변수로 참조할 수 있게 저장합니다. | ||
|
||
```tsx | ||
import ... | ||
import StyledSystemTheme from './AppTheme' | ||
|
||
// highlight-start | ||
let _globalTheme: ThemedDict = StyledSystemTheme; | ||
export const getGlobalTheme = () => _globalTheme; | ||
// highlight-end | ||
|
||
export const StyledSystemAppThemeProvider = ({ children }: PropsWithChildren<{}>) => { | ||
const { sfTop, sfBottom, sfLeft, sfRight } = useSafeAreaValues(); | ||
|
||
const theme = useMemo(() => { | ||
const safeArea = { sfTop, sfRight, sfBottom, sfLeft }; | ||
return { | ||
...StyledSystemTheme, | ||
sizes: { ...StyledSystemTheme.sizes, ...safeArea }, | ||
space: { ...StyledSystemTheme.space, ...safeArea }, | ||
}; | ||
}, [sfLeft, sfTop, sfRight, sfBottom]); | ||
|
||
// highlight-start | ||
useEffect(() => { | ||
globalTheme = theme; | ||
}, [theme]); | ||
// highlight-end | ||
|
||
return <StyledSystemProvider theme={theme}>{children}</StyledSystemProvider>; | ||
}; | ||
``` | ||
|
||
이제 우리의 코드에서 `getGlobalTheme()`를 통해 테마를 참조할 수 있습니다. | ||
|
||
:::warning | ||
항상 최신 `theme`값이 참조되지 않을 수 있다는 것을 주의하세요. | ||
|
||
예를 들어, `getGlobalTheme()`로 반환된 값을 변수에 저장해두었다가 | ||
테마 값이 변경된 이후 사용하려고 하면 이전의 값을 가리키고 있습니다. | ||
::: |
8 changes: 0 additions & 8 deletions
8
doc/i18n/ko/docusaurus-plugin-content-docs/current/usage/_category_.json
This file was deleted.
Oops, something went wrong.
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