-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] - Implements Dark Mode on Android platform (#19293)
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/compose/src/hooks/use-preferred-color-scheme/index.android.js
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,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { | ||
subscribePreferredColorScheme, | ||
isInitialColorSchemeDark, | ||
} from 'react-native-gutenberg-bridge'; | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState, useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ] | ||
* | ||
* @return {string} return current color scheme. | ||
*/ | ||
const usePreferredColorScheme = function() { | ||
const [ currentColorScheme, setCurrentColorScheme ] = useState( | ||
isInitialColorSchemeDark ? 'dark' : 'light' | ||
); | ||
useEffect( () => { | ||
subscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => { | ||
const colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light'; | ||
if ( colorScheme !== currentColorScheme ) { | ||
setCurrentColorScheme( colorScheme ); | ||
} | ||
} ); | ||
} ); | ||
return currentColorScheme; | ||
}; | ||
|
||
export default usePreferredColorScheme; |
File renamed without changes.
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