-
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.
- Loading branch information
master1lan
committed
Jan 9, 2023
1 parent
021fa17
commit 5a61f15
Showing
11 changed files
with
146 additions
and
51 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
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,45 @@ | ||
| import { Breakpoint } from "@mui/material"; | ||
| import { useScreenMatchSize } from "@utils/hooks/match"; | ||
| import { | ||
| useContext, | ||
| useState, | ||
| createContext, | ||
| useEffect, | ||
| ReactElement, | ||
| } from "react"; | ||
| const size_list: Breakpoint[] = ["lg", "md", "sm", "xs"]; | ||
|
|
||
| const ScreenContext = createContext<ScreenContextType>( | ||
| size_list.reduce((pre, size: Breakpoint) => { | ||
| //@ts-ignore | ||
| pre[size] = false; | ||
| return pre; | ||
| }, {} as ScreenContextType) | ||
| ); | ||
| type ScreenContextType = { | ||
| lg: boolean; | ||
| md: boolean; | ||
| sm: boolean; | ||
| xs: boolean; | ||
| }; | ||
| type ProviewProps = { | ||
| children: ReactElement; | ||
| }; | ||
|
|
||
| const ScreenProview = ({ children }: ProviewProps) => { | ||
| const ScreenSize: ScreenContextType = size_list.reduce((preObj, size) => { | ||
| //@ts-ignore | ||
| preObj[size] = useScreenMatchSize(size); | ||
| return preObj; | ||
| }, {} as ScreenContextType); | ||
| return ( | ||
| <ScreenContext.Provider value={ScreenSize}> | ||
| {children} | ||
| </ScreenContext.Provider> | ||
| ); | ||
| }; | ||
| export const useScreenSize = () => { | ||
| return useContext(ScreenContext); | ||
| }; | ||
|
|
||
| export default ScreenProview; |
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
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,18 @@ | ||
| import { Breakpoint, useMediaQuery, useTheme } from "@mui/material"; | ||
|
|
||
| /** | ||
| * @description 获知当前屏幕处于哪种大小 | ||
| */ | ||
| export const useScreenMatchSize = (size: Breakpoint) => { | ||
| const theme = useTheme(); | ||
| const matchSize = useMediaQuery(theme.breakpoints.up(size)); | ||
| return matchSize; | ||
| }; | ||
| //个人主页头像大小 | ||
| `@240w_240h_1c_1s.webp`; | ||
| //移动平台首页图片大小 | ||
| `@480w_270h_1c`; | ||
| //电脑平台首页图片大小 | ||
| `@672w_378h_1c_!web-search-common-cover`; | ||
| //首页up头像大小 | ||
| `@96w_96h_1s.webp`; |
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