Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Audio & Video block - Autoplay BottomSheet Cell help support #30885

Merged
merged 17 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
710b891
added the help behavior to the cell component of the bottomsheet.
jd-alexander Apr 15, 2021
b23e8dd
Passed the autoplay help prop to ToggleControl. Changed the order.
jd-alexander Apr 15, 2021
6e39f14
Added CHANGELOG entry for cell help change..
jd-alexander Apr 16, 2021
269de3a
Merge branch 'trunk' into rnmobile/bottomsheet-cell-help
jd-alexander Apr 16, 2021
47e14a4
Used platform specific help behavior for video block.
jd-alexander Apr 16, 2021
de6a0bf
Put Audio block's autoplay setting at the top of the panel.
jd-alexander Apr 16, 2021
8a9a0bc
Utilized sizing from SCSS Variables instead of hardcoding values.
jd-alexander Apr 16, 2021
8891800
Added PR number to the CHANGELOG entry.
jd-alexander Apr 16, 2021
330f509
added platform specific styling for cellHelpLabel
jd-alexander Apr 19, 2021
29b4393
Made autoplay label consistent across web and mobile.
jd-alexander Apr 20, 2021
23de048
Merge branch 'trunk' into rnmobile/bottomsheet-cell-help
jd-alexander May 12, 2021
0b4931b
added help support to cell's accessibility capabilities.
jd-alexander May 12, 2021
67ce0aa
added help support to switch cell accessibility capabilities
jd-alexander May 12, 2021
89dbc06
utilised cellProps.help instead of help so the props are passed down
jd-alexander May 12, 2021
89b8d8f
Merge branch 'trunk' into rnmobile/bottomsheet-cell-help
jd-alexander May 14, 2021
cf4eab0
Merge branch 'trunk' into rnmobile/bottomsheet-cell-help
jd-alexander May 14, 2021
500de81
Merge branch 'trunk' into rnmobile/bottomsheet-cell-help
jd-alexander May 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ function AudioEdit( {

function getAutoplayHelp( checked ) {
return checked
? __(
'Note: Autoplaying audio may cause usability issues for some visitors.'
)
? __( 'Autoplay may cause usability issues for some users.' )
: null;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/audio/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ function AudioEdit( {
label={ __( 'Autoplay' ) }
onChange={ toggleAttribute( 'autoplay' ) }
checked={ autoplay }
help={ __(
'Autoplay may cause usability issues for some users.'
) }
/>
<ToggleControl
label={ __( 'Loop' ) }
Expand Down
18 changes: 10 additions & 8 deletions packages/block-library/src/video/edit-common-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { ToggleControl, SelectControl } from '@wordpress/components';
import { useMemo, useCallback } from '@wordpress/element';
import { useMemo, useCallback, Platform } from '@wordpress/element';

const options = [
{ value: 'auto', label: __( 'Auto' ) },
Expand All @@ -21,13 +21,15 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
preload,
} = attributes;

const getAutoplayHelp = useCallback( ( checked ) => {
return checked
? __(
'Note: Autoplaying videos may cause usability issues for some visitors.'
)
: null;
}, [] );
const autoPlayHelpText = __(
'Autoplay may cause usability issues for some users.'
);
const getAutoplayHelp = Platform.select( {
web: useCallback( ( checked ) => {
return checked ? autoPlayHelpText : null;
}, [] ),
AmandaRiu marked this conversation as resolved.
Show resolved Hide resolved
native: autoPlayHelpText,
} );

const toggleFactory = useMemo( () => {
const toggleAttribute = ( attribute ) => {
Expand Down
43 changes: 36 additions & 7 deletions packages/components/src/mobile/bottom-sheet/cell.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TextInput,
I18nManager,
AccessibilityInfo,
Platform,
} from 'react-native';
import { isEmpty, get } from 'lodash';

Expand All @@ -27,6 +28,7 @@ import styles from './styles.scss';
import platformStyles from './cellStyles.scss';
import TouchableRipple from './ripple';

const isIOS = Platform.OS === 'ios';
class BottomSheetCell extends Component {
constructor( props ) {
super( ...arguments );
Expand Down Expand Up @@ -119,6 +121,7 @@ class BottomSheetCell extends Component {
type,
step,
borderless,
help,
...valueProps
} = this.props;

Expand Down Expand Up @@ -266,18 +269,35 @@ class BottomSheetCell extends Component {
if ( accessibilityLabel || ! showValue ) {
return accessibilityLabel || label;
}
return isEmpty( value )

if ( isEmpty( value ) ) {
return isEmpty( help )
? sprintf(
/* translators: accessibility text. Empty state of a inline textinput cell. %s: The cell's title */
_x( '%s. Empty', 'inline textinput cell' ),
label
)
: // Separating by ',' is necessary to make a pause on urls (non-capitalized text)
sprintf(
/* translators: accessibility text. Empty state of a inline textinput cell. %1: Cell title, %2: cell help. */
_x( '%1$s, %2$s. Empty', 'inline textinput cell' ),
label,
help
);
}
return isEmpty( help )
? sprintf(
/* translators: accessibility text. Empty state of a inline textinput cell. %s: The cell's title */
_x( '%s. Empty', 'inline textinput cell' ),
label
)
: // Separating by ',' is necessary to make a pause on urls (non-capitalized text)
sprintf(
/* translators: accessibility text. Inline textinput title and value.%1: Cell title, %2: cell value. */
_x( '%1$s, %2$s', 'inline textinput cell' ),
label,
value
) // Separating by ',' is necessary to make a pause on urls (non-capitalized text)
: sprintf(
/* translators: accessibility text. Inline textinput title, value and help text.%1: Cell title, %2: cell value, , %3: cell help. */
_x( '%1$s, %2$s, %3$s', 'inline textinput cell' ),
label,
value,
help
);
};

Expand All @@ -289,6 +309,10 @@ class BottomSheetCell extends Component {
styles.resetButton,
styles.resetButtonDark
);
const cellHelpStyle = [
styles.cellHelpLabel,
isIOS && styles.cellHelpLabelIOS,
];
const containerPointerEvents =
this.state.isScreenReaderEnabled && accessible ? 'none' : 'auto';
const { title, handler } = customActionButton || {};
Expand Down Expand Up @@ -370,6 +394,11 @@ class BottomSheetCell extends Component {
{ showValue && getValueComponent() }
{ children }
</View>
{ help && (
<Text style={ [ cellHelpStyle, styles.placeholderColor ] }>
{ help }
</Text>
) }
{ ! drawTopSeparator && <View style={ separatorStyle() } /> }
</TouchableRipple>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,12 @@
.flex {
flex: 1;
}

.cellHelpLabel {
font-size: $default-font-size;
padding-bottom: $grid-unit-15;
}

.cellHelpLabelIOS {
padding-bottom: $grid-unit-10;
}
42 changes: 30 additions & 12 deletions packages/components/src/mobile/bottom-sheet/switch-cell.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { Switch } from 'react-native';
import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
Expand All @@ -18,22 +19,39 @@ export default function BottomSheetSwitchCell( props ) {
onValueChange( ! value );
};

const accessibilityLabel = value
? sprintf(
/* translators: accessibility text. Switch setting ON state. %s: Switch title. */
_x( '%s. On', 'switch control' ),
cellProps.label
)
: sprintf(
/* translators: accessibility text. Switch setting OFF state. %s: Switch title. */
_x( '%s. Off', 'switch control' ),
cellProps.label
);
const getAccessibilityLabel = () => {
if ( isEmpty( cellProps.help ) ) {
return value
? sprintf(
/* translators: accessibility text. Switch setting ON state. %s: Switch title. */
_x( '%s. On', 'switch control' ),
cellProps.label
)
: sprintf(
/* translators: accessibility text. Switch setting OFF state. %s: Switch title. */
_x( '%s. Off', 'switch control' ),
cellProps.label
);
}
return value
? sprintf(
/* translators: accessibility text. Switch setting ON state. %1: Switch title, %2: switch help. */
_x( '%1$s, %2$s. On', 'switch control' ),
cellProps.label,
cellProps.help
)
: sprintf(
/* translators: accessibility text. Switch setting OFF state. %1: Switch title, %2: switch help. */
_x( '%1$s, %2$s. Off', 'switch control' ),
cellProps.label,
cellProps.help
);
};

return (
<Cell
{ ...cellProps }
accessibilityLabel={ accessibilityLabel }
accessibilityLabel={ getAccessibilityLabel() }
accessibilityRole={ 'none' }
accessibilityHint={
/* translators: accessibility text (hint for switches) */
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ For each user feature we should also add a importance categorization label to i
- [*] Fixes color picker rendering bug when scrolling [#30994]
- [*] Add enableCaching param to fetch request on Android [#31186]
- [***] Add reusable blocks to the inserter menu. [#28495]
- [*] The BottomSheet Cell component now supports the help prop so that a hint can be supplied to all Cell based components. [#30885]


## 1.52.2

Expand Down