-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: breakpointIndex가 바뀔 때 반응형을 사용하는 컴포넌트만 리랜더링 되도록 한다 (#937)
- Loading branch information
1 parent
c5a1d3c
commit 3c85844
Showing
10 changed files
with
78 additions
and
79 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
10 changes: 4 additions & 6 deletions
10
packages/vibrant-core/src/lib/injectContext/injectContext.tsx
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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
import type { CurrentTheme } from '@vibrant-ui/theme'; | ||
import { useCurrentTheme } from '../ThemeProvider'; | ||
import { useResponsiveValue } from '../useResponsiveValue'; | ||
|
||
export function injectContext<ReturnType>( | ||
fn: (_: { theme: CurrentTheme; breakpointIndex: number }) => ReturnType | ||
): () => ReturnType { | ||
return () => { | ||
fn: (_: { theme: CurrentTheme; props: Record<string, any> }) => ReturnType | ||
): (props: any) => ReturnType { | ||
return (props: Record<string, any>) => { | ||
const { theme } = useCurrentTheme(); | ||
const { breakpointIndex } = useResponsiveValue(); | ||
|
||
return fn({ theme, breakpointIndex }); | ||
return fn({ theme, props }); | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import type { CurrentTheme } from '@vibrant-ui/theme'; | ||
|
||
type StyleObject = { | ||
export type StyleObject = { | ||
[property: string]: any; | ||
}; | ||
|
||
export type BuildStyleFn = (_: { | ||
styleObjects: StyleObject[]; | ||
theme: CurrentTheme; | ||
breakpointIndex: number; | ||
}) => Record<string, any>; | ||
export type BuildStyleFn = (_: { styleObjects: StyleObject[]; theme: CurrentTheme }) => Record<string, any>; |
19 changes: 16 additions & 3 deletions
19
packages/vibrant-core/src/lib/useBuildStyle/useBuildStyle.native.ts
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 |
---|---|---|
@@ -1,4 +1,17 @@ | ||
import type { BuildStyleFn } from './type'; | ||
import { useResponsiveValue } from '../useResponsiveValue'; | ||
import type { BuildStyleFn, StyleObject } from './type'; | ||
|
||
export const useBuildStyle: BuildStyleFn = ({ styleObjects, breakpointIndex }) => | ||
styleObjects.slice(0, breakpointIndex + 1).reduce((result, styleObject) => ({ ...result, ...styleObject }), {}); | ||
export const useBuildStyle: BuildStyleFn = ({ styleObjects }) => { | ||
if (styleObjects.length < 2) { | ||
return styleObjects[0] ?? {}; | ||
} | ||
|
||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const { breakpointIndex } = useResponsiveValue(); | ||
|
||
const style: StyleObject = styleObjects | ||
.slice(0, breakpointIndex + 1) | ||
.reduce((result, styleObject) => ({ ...result, ...styleObject }), {}); | ||
|
||
return style; | ||
}; |
17 changes: 8 additions & 9 deletions
17
packages/vibrant-core/src/lib/useInterpolation/useInterpolation.ts
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { useMemo } from 'react'; | ||
import { useCallback } from 'react'; | ||
import { createInterpolation } from '../createInterpolation'; | ||
import type { SystemProp } from '../createSystemProp'; | ||
import { allSystemProps } from '../props'; | ||
import { useCurrentTheme } from '../ThemeProvider'; | ||
import { useResponsiveValue } from '../useResponsiveValue'; | ||
|
||
export const useInterpolation = (additionalSystemProps: SystemProp[] = []) => { | ||
const interpolation = createInterpolation(allSystemProps); | ||
|
||
export const useInterpolation = () => { | ||
const { theme } = useCurrentTheme(); | ||
const { breakpointIndex } = useResponsiveValue(); | ||
|
||
const interpolation = useMemo( | ||
() => createInterpolation([...allSystemProps, ...additionalSystemProps])({ theme, breakpointIndex }), | ||
[additionalSystemProps, breakpointIndex, theme] | ||
const useInterpolateStyle = useCallback( | ||
(style: Record<string, any>) => interpolation({ theme, props: style }), | ||
[theme] | ||
); | ||
|
||
return { | ||
interpolation, | ||
useInterpolateStyle, | ||
}; | ||
}; |
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
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