Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3362312
D9551.id32244.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9551.id32244.diff
View Options
diff --git a/lib/hooks/theme.js b/lib/hooks/theme.js
new file mode 100644
--- /dev/null
+++ b/lib/hooks/theme.js
@@ -0,0 +1,37 @@
+// @flow
+
+import * as React from 'react';
+import { useDispatch } from 'react-redux';
+
+import { updateThemeInfoActionType } from '../actions/theme-actions.js';
+import type { Shape } from '../types/core.js';
+import type { GlobalTheme, GlobalThemeInfo } from '../types/theme-types.js';
+import { useSelector } from '../utils/redux-utils.js';
+
+function useUpdateSystemTheme(): (colorScheme: ?GlobalTheme) => mixed {
+ const globalThemeInfo = useSelector(state => state.globalThemeInfo);
+ const dispatch = useDispatch();
+
+ return React.useCallback(
+ (colorScheme: ?GlobalTheme) => {
+ if (globalThemeInfo.systemTheme === colorScheme) {
+ return;
+ }
+
+ let updateObject: Shape<GlobalThemeInfo> = {
+ systemTheme: colorScheme,
+ };
+ if (globalThemeInfo.preference === 'system') {
+ updateObject = { ...updateObject, activeTheme: colorScheme };
+ }
+
+ dispatch({
+ type: updateThemeInfoActionType,
+ payload: updateObject,
+ });
+ },
+ [globalThemeInfo, dispatch],
+ );
+}
+
+export { useUpdateSystemTheme };
diff --git a/native/themes/theme-handler.react.js b/native/themes/theme-handler.react.js
--- a/native/themes/theme-handler.react.js
+++ b/native/themes/theme-handler.react.js
@@ -3,38 +3,13 @@
import invariant from 'invariant';
import * as React from 'react';
import { Appearance } from 'react-native';
-import { useDispatch } from 'react-redux';
-import { updateThemeInfoActionType } from 'lib/actions/theme-actions.js';
-import type { Shape } from 'lib/types/core.js';
-import type { GlobalTheme, GlobalThemeInfo } from 'lib/types/theme-types.js';
+import { useUpdateSystemTheme } from 'lib/hooks/theme.js';
-import { useSelector } from '../redux/redux-utils.js';
import { osCanTheme } from '../themes/theme-utils.js';
function ThemeHandler(): null {
- const globalThemeInfo = useSelector(state => state.globalThemeInfo);
- const dispatch = useDispatch();
- const updateSystemTheme = React.useCallback(
- (colorScheme: ?GlobalTheme) => {
- if (globalThemeInfo.systemTheme === colorScheme) {
- return;
- }
-
- let updateObject: Shape<GlobalThemeInfo> = {
- systemTheme: colorScheme,
- };
- if (globalThemeInfo.preference === 'system') {
- updateObject = { ...updateObject, activeTheme: colorScheme };
- }
-
- dispatch({
- type: updateThemeInfoActionType,
- payload: updateObject,
- });
- },
- [globalThemeInfo, dispatch],
- );
+ const updateSystemTheme = useUpdateSystemTheme();
React.useEffect(() => {
if (!osCanTheme) {
@@ -54,7 +29,9 @@
}, [updateSystemTheme]);
React.useEffect(
- () => updateSystemTheme(Appearance.getColorScheme()),
+ () => {
+ updateSystemTheme(Appearance.getColorScheme());
+ },
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 10:05 PM (20 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2579158
Default Alt Text
D9551.id32244.diff (2 KB)
Attached To
Mode
D9551: [lib/native] introduce useUpdateSystemTheme
Attached
Detach File
Event Timeline
Log In to Comment