-
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] Dark mode on Android put on the v1.25.0 native release (#2…
…1352) * Revert revert of dark mode impl * Add pre to list of block wrappers (#21255) * Add pre to list of block wrappers * Share the elements definition between web and native. * Make constant name all uppercase. * Rename constant name to be all uppercase * Rename elements constant to all uppercase Co-authored-by: Marko Savic <[email protected]> Co-authored-by: Sérgio Estêvão <[email protected]>
- Loading branch information
1 parent
c7a3c2c
commit 0768103
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