Skip to content

Commit

Permalink
[RNMobile] Dark mode on Android put on the v1.25.0 native release (#2…
Browse files Browse the repository at this point in the history
…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
3 people committed Apr 3, 2020
1 parent c7a3c2c commit 0768103
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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;
1 change: 1 addition & 0 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jest.mock( 'react-native-gutenberg-bridge', () => {
subscribeUpdateHtml: jest.fn(),
subscribeMediaAppend: jest.fn(),
subscribeAndroidModalClosed: jest.fn(),
subscribePreferredColorScheme: () => 'light',
editorDidMount: jest.fn(),
editorDidAutosave: jest.fn(),
subscribeMediaUpload: jest.fn(),
Expand Down

0 comments on commit 0768103

Please sign in to comment.