Skip to content

Commit

Permalink
[RNMobile] Image block makes call to native for fullscreen preview (#…
Browse files Browse the repository at this point in the history
…18493)

* Call to RN gutenberg bridge for Android native fullscreen preview

* Added highlight border around image when image block is selected

* Do not request fullscreen preview if tapped mid upload or while showing tap to rety.
  • Loading branch information
cameronvoell authored and hypest committed Nov 14, 2019
1 parent 262cca4 commit aba13e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
* External dependencies
*/
import React from 'react';
import { View, ImageBackground, Text, TouchableWithoutFeedback, Dimensions } from 'react-native';
import { View, ImageBackground, Text, TouchableWithoutFeedback, Dimensions, Platform } from 'react-native';
import {
requestMediaImport,
mediaUploadSync,
requestImageFailedRetryDialog,
requestImageUploadCancelDialog,
requestImageFullscreenPreview,
} from 'react-native-gutenberg-bridge';
import { isEmpty, map } from 'lodash';

Expand Down Expand Up @@ -142,11 +143,14 @@ export class ImageEdit extends React.Component {
requestImageUploadCancelDialog( attributes.id );
} else if ( attributes.id && ! isURL( attributes.url ) ) {
requestImageFailedRetryDialog( attributes.id );
} else if ( Platform.OS === 'android' ) {
requestImageFullscreenPreview( attributes.url );
}

this.setState( {
isCaptionSelected: false,
} );

}

updateMediaProgress( payload ) {
Expand Down Expand Up @@ -334,6 +338,7 @@ export class ImageEdit extends React.Component {
};

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

const getImageComponent = ( openMediaOptions, getMediaOptions ) => (
<TouchableWithoutFeedback
accessible={ ! isSelected }
Expand All @@ -359,6 +364,7 @@ export class ImageEdit extends React.Component {
renderContent={ ( { isUploadInProgress, isUploadFailed, finalWidth, finalHeight, imageWidthWithinContainer, retryMessage } ) => {
const opacity = isUploadInProgress ? 0.3 : 1;
const icon = this.getIcon( isUploadFailed );
const imageBorderOnSelectedStyle = isSelected && !( isUploadInProgress || isUploadFailed ) ? styles.imageBorder : '';

const iconContainer = (
<View style={ styles.modalIcon }>
Expand All @@ -378,7 +384,7 @@ export class ImageEdit extends React.Component {
accessibilityLabel={ alt }
accessibilityHint={ __( 'Double tap and hold to edit' ) }
accessibilityRole={ 'imagebutton' }
style={ { width: finalWidth, height: finalHeight, opacity } }
style={ [ imageBorderOnSelectedStyle, { width: finalWidth, height: finalHeight, opacity } ] }
resizeMethod="scale"
source={ { uri: url } }
key={ url }
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/image/styles.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
background-color: $gray-lighten-30;
}

.imageBorder {
border-color: $blue-medium;
border-width: 2px;
border-style: solid;
}

.uploadFailedText {
color: #fff;
font-size: 14;
Expand Down

0 comments on commit aba13e2

Please sign in to comment.