Skip to content

Commit

Permalink
a11y improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Nov 7, 2019
1 parent cf85c25 commit b66c94d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
15 changes: 5 additions & 10 deletions packages/block-library/src/spacer/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { View } from 'react-native';
* WordPress dependencies
*/
import {
RangeControl,
PanelBody,
BottomSheet,
} from '@wordpress/components';
import { withPreferredColorScheme } from '@wordpress/compose';
import { useState, useEffect } from '@wordpress/element';
Expand Down Expand Up @@ -36,27 +36,22 @@ const SpacerEdit = ( { isSelected, attributes, setAttributes, getStylesFromColor
setSpacerMaxHeight( height > maxSpacerHeight ? height * 2 : maxSpacerHeight );
}, [] );

const changeAttribute = ( value ) => {
setAttributes( {
height: value,
} );
};

const defaultStyle = getStylesFromColorScheme( styles.staticSpacer, styles.staticDarkSpacer );

return (
<View style={ [ defaultStyle, isSelected && styles.selectedSpacer, { height } ] }>
<InspectorControls>
<PanelBody title={ __( 'Spacer Settings' ) } >
<RangeControl
<BottomSheet.RangeCell
icon={ 'admin-settings' }
label={ __( 'Height in pixels' ) }
minimumValue={ minSpacerHeight }
maximumValue={ sliderSpacerMaxHeight }
separatorType={ 'none' }
value={ height }
onChange={ changeAttribute }
attribute="height"
setAttributes={ setAttributes }
style={ styles.rangeCellContainer }
allowReset
/>
</PanelBody>
</InspectorControls>
Expand Down
24 changes: 21 additions & 3 deletions packages/components/src/mobile/bottom-sheet/range-cell.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { Platform, AccessibilityInfo, findNodeHandle, TextInput, Slider, View } from 'react-native';
import { Platform, AccessibilityInfo, findNodeHandle, TextInput, Slider, View, PixelRatio, AppState } from 'react-native';

/**
* WordPress dependencies
Expand All @@ -26,10 +26,12 @@ class BottomSheetRangeCell extends Component {
this.handleReset = this.handleReset.bind( this );
this.onChangeValue = this.onChangeValue.bind( this );
this.onCellPress = this.onCellPress.bind( this );
this.handleChangePixelRatio = this.handleChangePixelRatio.bind( this );

const initialValue = this.validateInput( props.value || props.defaultValue || props.minimumValue );
const fontScale = this.getFontScale();

this.state = { accessible: true, sliderValue: initialValue, initialValue, hasFocus: false };
this.state = { accessible: true, sliderValue: initialValue, initialValue, hasFocus: false, fontScale };
}

componentDidUpdate( ) {
Expand All @@ -39,8 +41,23 @@ class BottomSheetRangeCell extends Component {
}
}

componentDidMount() {
AppState.addEventListener( 'change', this.handleChangePixelRatio );
}

componentWillUnmount() {
this.handleToggleFocus();
AppState.removeEventListener( 'change', this.handleChangePixelRatio );
}

getFontScale() {
return PixelRatio.getFontScale() < 1 ? 1 : PixelRatio.getFontScale();
}

handleChangePixelRatio( nextAppState ) {
if ( nextAppState === 'active' ) {
this.setState( { fontScale: this.getFontScale() } );
}
}

handleChange( text ) {
Expand Down Expand Up @@ -126,7 +143,7 @@ class BottomSheetRangeCell extends Component {
...cellProps
} = this.props;

const { hasFocus, sliderValue, accessible } = this.state;
const { hasFocus, sliderValue, accessible, fontScale } = this.state;

const accessibilityLabel =
sprintf(
Expand Down Expand Up @@ -177,6 +194,7 @@ class BottomSheetRangeCell extends Component {
defaultSliderStyle,
borderStyles.borderStyle,
hasFocus && borderStyles.isSelected,
{ width: 40 * fontScale },
] }
onChangeText={ this.handleChange }
onFocus={ this.handleToggleFocus }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
}

.sliderTextInput {
width: 40px;
height: 25px;
min-height: 25px;
align-self: center;
margin-left: 10px;
border-color: $light-gray-400;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
.cellRowContainer {
flex-direction: row;
align-items: center;
flex-shrink: 1;
}

.cellIcon {
Expand Down

0 comments on commit b66c94d

Please sign in to comment.