File tree Expand file tree Collapse file tree 1 file changed +9
-13
lines changed
src/containers/ThemeProvider Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change @@ -32,29 +32,25 @@ const ThemeObserver: FC<{
32
32
}
33
33
} , [ setAppearance ] ) ;
34
34
35
- useLayoutEffect ( ( ) => {
36
- // 如果是自动的话,则去做一次匹配
37
- if ( themeMode === 'auto' ) matchBrowserTheme ( ) ;
38
- // 否则就明确设定亮暗色
39
- else setAppearance ( themeMode ) ;
40
- } , [ themeMode ] ) ;
41
-
42
35
// 自动监听系统主题变更
43
36
useLayoutEffect ( ( ) => {
44
- if ( ! darkThemeMatch ) {
45
- darkThemeMatch = matchThemeMode ( 'dark' ) ;
37
+ // 如果不是自动,就明确设定亮暗色
38
+ if ( themeMode !== 'auto' ) {
39
+ setAppearance ( themeMode ) ;
40
+ return ;
46
41
}
42
+ // 如果是自动的话,则去做一次匹配,并开始监听
43
+ setTimeout ( matchBrowserTheme , 1 ) ;
47
44
48
- if ( themeMode === 'auto' ) {
49
- setTimeout ( matchBrowserTheme , 1 ) ;
45
+ if ( ! darkThemeMatch ) {
46
+ darkThemeMatch = matchThemeMode ( 'dark' ) ;
50
47
}
51
-
52
48
darkThemeMatch . addEventListener ( 'change' , matchBrowserTheme ) ;
53
49
54
50
return ( ) => {
55
51
darkThemeMatch . removeEventListener ( 'change' , matchBrowserTheme ) ;
56
52
} ;
57
- } , [ ] ) ;
53
+ } , [ themeMode ] ) ;
58
54
59
55
return null ;
60
56
} ;
You can’t perform that action at this time.
0 commit comments