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

[RN mobile] Accessibility: Handle the iOS z-gesture to exit modals and block selection #15153

Merged
merged 15 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 32 additions & 27 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,16 @@ class ImageEdit extends React.Component {
this.setState( { showSettings: false } );
};

const toolbarEditButton = (
<MediaUpload mediaType={ MEDIA_TYPE_IMAGE }
onSelectURL={ this.onSelectMediaUploadOption }
render={ ( { open, getMediaOptions } ) => {
return (
<Toolbar>
{ getMediaOptions() }
<ToolbarButton
title={ __( 'Edit image' ) }
icon="edit"
onClick={ open }
/>
</Toolbar>
);
} } >
</MediaUpload>
const getToolbarEditButton = ( open ) => (
<BlockControls>
<Toolbar>
<ToolbarButton
title={ __( 'Edit image' ) }
icon="edit"
onClick={ open }
/>
</Toolbar>
</BlockControls>
);

const getInspectorControls = () => (
Expand Down Expand Up @@ -276,11 +270,9 @@ class ImageEdit extends React.Component {
}

const imageContainerHeight = Dimensions.get( 'window' ).width / IMAGE_ASPECT_RATIO;

return (
const getImageComponent = ( openMediaOptions, getMediaOptions ) => (
<TouchableWithoutFeedback
accessible={ ! isSelected }

accessibilityLabel={ sprintf(
/* translators: accessibility text. 1: image alt text. 2: image caption. */
__( 'Image block. %1$s. %2$s' ),
Expand All @@ -289,14 +281,14 @@ class ImageEdit extends React.Component {
) }
accessibilityRole={ 'button' }
onPress={ this.onImagePressed }
onLongPress={ openMediaOptions }
disabled={ ! isSelected }
>
<View style={ { flex: 1 } }>
{ getInspectorControls() }
{ getMediaOptions() }
{ ( ! this.state.isCaptionSelected ) &&
<BlockControls>
{ toolbarEditButton }
</BlockControls>
getToolbarEditButton( openMediaOptions )
}
<InspectorControls>
<ToolbarButton
Expand Down Expand Up @@ -326,16 +318,20 @@ class ImageEdit extends React.Component {

return (
<View style={ { flex: 1 } } >
{ ! imageWidthWithinContainer && <View style={ [ styles.imageContainer, { height: imageContainerHeight } ] } >
{ this.getIcon( false ) }
</View> }
{ ! imageWidthWithinContainer &&
<View style={ [ styles.imageContainer, { height: imageContainerHeight } ] } >
{ this.getIcon( false ) }
</View> }
<ImageBackground
accessible={ true }
disabled={ ! isSelected }
accessibilityLabel={ alt }
accessibilityHint={ __( 'Double tap and hold to edit' ) }
accessibilityRole={ 'imagebutton' }
style={ { width: finalWidth, height: finalHeight, opacity } }
resizeMethod="scale"
source={ { uri: url } }
key={ url }
accessible={ true }
accessibilityLabel={ alt }
>
{ isUploadFailed &&
<View style={ [ styles.imageContainer, { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.5)' } ] } >
Expand Down Expand Up @@ -383,6 +379,15 @@ class ImageEdit extends React.Component {
</View>
</TouchableWithoutFeedback>
);

return (
<MediaUpload mediaType={ MEDIA_TYPE_IMAGE }
onSelectURL={ this.onSelectMediaUploadOption }
render={ ( { open, getMediaOptions } ) => {
return getImageComponent( open, getMediaOptions );
} }
/>
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class BottomSheet extends Component {
swipeDirection="down"
onMoveShouldSetResponder={ panResponder.panHandlers.onMoveShouldSetResponder }
onMoveShouldSetResponderCapture={ panResponder.panHandlers.onMoveShouldSetResponderCapture }
onAccessibilityEscape={ this.props.onClose }
>
<KeyboardAvoidingView
behavior={ Platform.OS === 'ios' && 'padding' }
Expand Down