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

Add/mobile fullscreen image preview #17109

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
21ff74f
Simplest implementation of fullscreen image preview using react-nativ…
cameronvoell Aug 19, 2019
6c1e053
Merge branch 'master' into add/mobile-fullscreen-image-preview
cameronvoell Aug 20, 2019
73c7820
Added highlight border around image when image block is selected
cameronvoell Aug 20, 2019
61b6e00
Merge branch 'master' into add/mobile-fullscreen-image-preview
cameronvoell Aug 20, 2019
664ecd2
Fixed miss-copy of getImageViewer method. Image preview onImagePresse…
cameronvoell Aug 20, 2019
231595e
Image scales to correct size for fullscreen preview in portrait and l…
cameronvoell Aug 22, 2019
3b3f645
Fixed lint errors. Small refactor so we can utilize dimension paramet…
cameronvoell Aug 26, 2019
ec59c56
Refactored, removing extra calculateSize method, image variable, and …
cameronvoell Aug 26, 2019
9d3bbab
Removed custom PanResponder setup. Does not seem to affect ImageViewe…
cameronvoell Aug 26, 2019
635108e
[RNMobile] Native mobile release v1.11.0 (#17181)
etoledom Aug 28, 2019
643c1b2
Activate Travis CI on rnmobile/master branch (#17229)
etoledom Aug 28, 2019
a78f204
Add native support for the MediaText block (#16305)
Tug Aug 29, 2019
3db95b7
MediaUpload and MediaPlaceholder unify props (#17145)
dratwas Aug 30, 2019
7aa44a2
Unify media placeholder and upload props within media-text (#17268)
lukewalczak Aug 30, 2019
f9fa455
[RNMobile] Fix dismiss keyboard button for the post title (#17260)
geriux Aug 30, 2019
7b12673
Recover border colors (#17269)
etoledom Aug 30, 2019
14d482b
[RNMobile] Insure tapping at end of post inserts at end
mchowning Aug 6, 2019
89664eb
Support group block on mobile (#17251)
lukewalczak Sep 3, 2019
57ab955
Merge branch 'rnmobile/master' into add/mobile-fullscreen-image-preview
cameronvoell Sep 4, 2019
97df694
Hide fullscreen feature behind dev flag. Fix lint error.
cameronvoell Sep 4, 2019
fc8c3da
Remove redundant bg color within button appender (#17325)
lukewalczak Sep 4, 2019
264b178
[RNMobile] DarkMode improvements (#17309)
etoledom Sep 4, 2019
e5054dd
Merge branch 'rnmobile/master' into add/mobile-fullscreen-image-preview
cameronvoell Sep 4, 2019
648a1b9
[RNMobile] Add autosave to mobile apps (#17329)
daniloercoli Sep 19, 2019
e99d365
Add isAppender functionality on mobile (#17195)
lukewalczak Sep 25, 2019
69da85e
Autosave monitor - Make the mobile editor ping the native at each key…
daniloercoli Sep 25, 2019
ae6d2ce
[RNMobile] Refactor Dark Mode HOC (#17552)
Tug Sep 25, 2019
1c9b133
Add missing heading levels to the UI (H4, H5, H6) (#17533)
SergioEstevao Sep 25, 2019
df025a6
Fix lint issue (#17598)
lukewalczak Sep 26, 2019
d8b0d83
Fix list filter on paste for RN mobile. (#17550)
SergioEstevao Sep 26, 2019
f3085c1
[RNMobile] Move MediaUploadPorgress to its own component folder (#17392)
geriux Sep 27, 2019
95acf23
Rnmobile/fix link editing on start (#17631)
SergioEstevao Sep 30, 2019
18aaa5e
Merge branch 'rnmobile/master' into add/mobile-fullscreen-image-preview
cameronvoell Oct 23, 2019
7f6d71e
Merging in master
cameronvoell Oct 23, 2019
cae51b4
Re-implementing #17802, affected by merge. Removing extra style.
cameronvoell Oct 23, 2019
6ad5d78
Merge branch 'master' into add/mobile-fullscreen-image-preview
cameronvoell Oct 30, 2019
8f3b2ef
Merge branch 'master' into add/mobile-fullscreen-image-preview
cameronvoell Nov 1, 2019
a927609
Fullscreen image preview enabled for ios only
cameronvoell Nov 2, 2019
c259edf
Removing no longer needed eslint disable
cameronvoell Nov 4, 2019
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
24 changes: 21 additions & 3 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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,
Expand All @@ -15,6 +15,7 @@ import { isEmpty, map } from 'lodash';
* WordPress dependencies
*/
import {
ImageViewer,
TextControl,
ToggleControl,
SelectControl,
Expand Down Expand Up @@ -75,6 +76,7 @@ export class ImageEdit extends React.Component {

this.state = {
isCaptionSelected: false,
showImageViewer: false,
};

this.finishMediaUploadWithSuccess = this.finishMediaUploadWithSuccess.bind( this );
Expand Down Expand Up @@ -139,9 +141,10 @@ export class ImageEdit extends React.Component {
} else if ( attributes.id && ! isURL( attributes.url ) ) {
requestImageFailedRetryDialog( attributes.id );
}

const enableFullscreen = Platform.OS === 'ios';
this.setState( {
isCaptionSelected: false,
showImageViewer: enableFullscreen && true,
} );
}

Expand Down Expand Up @@ -249,6 +252,10 @@ export class ImageEdit extends React.Component {

const actions = [ { label: __( 'Clear All Settings' ), onPress: this.onClearSettings } ];

const onImageViewerClose = () => {
this.setState( { showImageViewer: false } );
};

const getToolbarEditButton = ( open ) => (
<BlockControls>
<Toolbar>
Expand Down Expand Up @@ -308,6 +315,14 @@ export class ImageEdit extends React.Component {
</InspectorControls>
);

const getImageViewer = () => (
<ImageViewer
isVisible={ this.state.showImageViewer }
onClose={ onImageViewerClose }
url={ url }
/>
);

if ( ! url ) {
return (
<View style={ { flex: 1 } } >
Expand All @@ -330,6 +345,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 @@ -339,6 +355,7 @@ export class ImageEdit extends React.Component {
>
<View style={ { flex: 1 } }>
{ getInspectorControls() }
{ getImageViewer() }
{ getMediaOptions() }
{ ( ! this.state.isCaptionSelected ) &&
getToolbarEditButton( openMediaOptions )
Expand All @@ -355,6 +372,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 ? styles.imageBorder : '';

const iconContainer = (
<View style={ styles.modalIcon }>
Expand All @@ -374,7 +392,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
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export { default as withSpokenMessages } from './higher-order/with-spoken-messag

// Mobile Components
export { default as BottomSheet } from './mobile/bottom-sheet';
export { default as ImageViewer } from './mobile/image-viewer';
export { default as HTMLTextInput } from './mobile/html-text-input';
export { default as KeyboardAvoidingView } from './mobile/keyboard-avoiding-view';
export { default as KeyboardAwareFlatList } from './mobile/keyboard-aware-flat-list';
Expand Down
104 changes: 104 additions & 0 deletions packages/components/src/mobile/image-viewer/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* External dependencies
*/
import { View, Dimensions, ImageBackground, Image } from 'react-native';
import Modal from 'react-native-modal';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';

/**
* Internal dependencies
*/
import styles from './styles.scss';

class ImageViewer extends Component {
constructor() {
super( ...arguments );

this.state = {
width: undefined,
height: undefined,
};

this.onDimensionsChange = this.onDimensionsChange.bind( this );
}

componentDidMount() {
Dimensions.addEventListener( 'change', this.onDimensionsChange );
this.fetchImageSize( Dimensions.get( 'window' ) );
}

componentDidUpdate( prevProps ) {
if ( this.props.url !== prevProps.url ) {
this.fetchImageSize( Dimensions.get( 'window' ) );
}
}

componentWillUnmount() {
Dimensions.removeEventListener( 'change', this.onDimensionsChange );
}

onDimensionsChange( dimensions ) {
this.fetchImageSize( dimensions.window );
}

fetchImageSize( dimensions ) {
Image.getSize( this.props.url, ( width, height ) => {
const { finalWidth, finalHeight } = this.calculateFullscreenImageSize( width, height, dimensions );
this.setState( { width: finalWidth, height: finalHeight } );
} );
}

calculateFullscreenImageSize( imageWidth, imageHeight, container ) {
const imageRatio = imageWidth / imageHeight;
const screenRatio = container.width / container.height;
let finalWidth = container.width;
let finalHeight = container.height;
const shouldUseContainerHeightForImage = imageRatio < screenRatio;
if ( shouldUseContainerHeightForImage ) {
finalWidth = container.height * imageRatio;
} else {
finalHeight = container.width / imageRatio;
}
return { finalWidth, finalHeight };
}

render() {
const {
isVisible,
url = '',
} = this.props;

return (
<Modal
isVisible={ isVisible }
style={ styles.modal }
animationIn={ 'fadeIn' }
animationInTiming={ 1000 }
animationOut={ 'fadeOut' }
animationOutTiming={ 250 }
backdropTransitionInTiming={ 50 }
backdropTransitionOutTiming={ 50 }
backdropOpacity={ 1 }
supportedOrientations={ [ 'portrait', 'landscape' ] }
onBackdropPress={ this.props.onClose }
onBackButtonPress={ this.props.onClose }
onSwipe={ this.props.onClose }
swipeDirection={ 'down' }
onAccessibilityEscape={ this.props.onClose }
>
<View style={ styles.content }>
<ImageBackground
style={ { width: this.state.width, height: this.state.height } }
source={ { uri: url } }
/>
</View>
</Modal>
);
}
}

export default ImageViewer;
10 changes: 10 additions & 0 deletions packages/components/src/mobile/image-viewer/styles.native.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//Image Viewer

.modal {
justify-content: center;
align-items: center;
}

.content {
justify-content: center;
}