Skip to content

Commit

Permalink
[RNMobile] Ensure uploaded audio is always visible within Audio block (
Browse files Browse the repository at this point in the history
…#55627)

Ensure the Audio block is always visible when media's been uploaded to it.
  • Loading branch information
Siobhan Bamber authored Nov 16, 2023
1 parent 2fb6bec commit 3875618
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,5 @@ export {
getGlobalStyles,
getColorsAndGradients,
useMobileGlobalStylesColors,
useEditorColorScheme,
} from './mobile/global-styles-context/utils';
22 changes: 9 additions & 13 deletions packages/components/src/mobile/audio-player/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { default as VideoPlayer } from 'react-native-video';
* WordPress dependencies
*/
import { View } from '@wordpress/primitives';
import { Icon } from '@wordpress/components';
import { Icon, useEditorColorScheme } from '@wordpress/components';
import { withPreferredColorScheme } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { audio, warning } from '@wordpress/icons';
Expand All @@ -34,7 +34,6 @@ import { parseAudioUrl } from './audio-url-parser.native';
const isIOS = Platform.OS === 'ios';

function Player( {
getStylesFromColorScheme,
isUploadInProgress,
isUploadFailed,
attributes,
Expand Down Expand Up @@ -70,14 +69,14 @@ function Player( {
}
};

const containerStyle = getStylesFromColorScheme(
const containerStyle = useEditorColorScheme(
styles.container,
styles.containerDark
);

const iconStyle = getStylesFromColorScheme( styles.icon, styles.iconDark );
const iconStyle = useEditorColorScheme( styles.icon, styles.iconDark );

const iconDisabledStyle = getStylesFromColorScheme(
const iconDisabledStyle = useEditorColorScheme(
styles.iconDisabled,
styles.iconDisabledDark
);
Expand All @@ -89,7 +88,7 @@ function Player( {
...( isDisabled && iconDisabledStyle ),
};

const iconContainerStyle = getStylesFromColorScheme(
const iconContainerStyle = useEditorColorScheme(
styles.iconContainer,
styles.iconContainerDark
);
Expand All @@ -99,17 +98,14 @@ function Player( {
...( isIOS ? styles.titleContainerIOS : styles.titleContainerAndroid ),
};

const titleStyle = getStylesFromColorScheme(
styles.title,
styles.titleDark
);
const titleStyle = useEditorColorScheme( styles.title, styles.titleDark );

const uploadFailedStyle = getStylesFromColorScheme(
const uploadFailedStyle = useEditorColorScheme(
styles.uploadFailed,
styles.uploadFailedDark
);

const subtitleStyle = getStylesFromColorScheme(
const subtitleStyle = useEditorColorScheme(
styles.subtitle,
styles.subtitleDark
);
Expand All @@ -119,7 +115,7 @@ function Player( {
...( isUploadFailed && uploadFailedStyle ),
};

const buttonBackgroundStyle = getStylesFromColorScheme(
const buttonBackgroundStyle = useEditorColorScheme(
styles.buttonBackground,
styles.buttonBackgroundDark
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { camelCase } from 'change-case';
import { Dimensions } from 'react-native';
import { colord } from 'colord';

/**
* WordPress dependencies
Expand All @@ -13,6 +14,12 @@ import {
useMultipleOriginColorsAndGradients,
SETTINGS_DEFAULTS,
} from '@wordpress/block-editor';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';

/**
* Internal dependencies
*/
import { useGlobalStyles } from './index.native';

export const BLOCK_STYLE_ATTRIBUTES = [
'textColor',
Expand Down Expand Up @@ -441,3 +448,40 @@ export function getGlobalStyles( rawStyles, rawFeatures ) {
__experimentalGlobalStylesBaseStyles: globalStyles,
};
}

/**
* Determine and apply appropriate color scheme based on global styles or device's light/dark mode.
*
* The function first attempts to retrieve the editor's background color from global styles.
* If the detected background color is light, light styles are applied, and dark styles otherwise.
* If no custom background color is defined, styles are applied using the device's dark/light setting.
*
* @param {Object} baseStyle - An object representing the base (light theme) styles for the editor.
* @param {Object} darkStyle - An object representing the additional styles to apply when the editor is in dark mode.
*
* @return {Object} - The combined style object that should be applied to the editor.
*/
export const useEditorColorScheme = ( baseStyle, darkStyle ) => {
const globalStyles = useGlobalStyles();

const deviceColorScheme = usePreferredColorSchemeStyle(
baseStyle,
darkStyle
);

const editorColors = globalStyles?.baseColors?.color;
const editorBackgroundColor = editorColors?.background;

const isBackgroundColorDefined =
typeof editorBackgroundColor !== 'undefined' &&
editorBackgroundColor !== 'undefined';

if ( isBackgroundColorDefined ) {
const isEditorBackgroundDark = colord( editorBackgroundColor ).isDark();
return isEditorBackgroundDark
? { ...baseStyle, ...darkStyle }
: baseStyle;
}

return deviceColorScheme;
};
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For each user feature we should also add a importance categorization label to i
-->

## Unreleased
- [*] Audio block: Improve legibility of audio file details on various background colors [#55627]

## 1.108.0
- [*] Fix error when pasting deeply nested structure content [#55613]
Expand Down

0 comments on commit 3875618

Please sign in to comment.