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] Fix media upload placeholder #19497

Merged
merged 4 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
37 changes: 25 additions & 12 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ import {
LINK_DESTINATION_NONE,
} from './constants';

const ICON_TYPE = {
PLACEHOLDER: 'placeholder',
RETRY: 'retry',
UPLOAD: 'upload',
};
const IMAGE_SIZE_THUMBNAIL = 'thumbnail';
const IMAGE_SIZE_MEDIUM = 'medium';
const IMAGE_SIZE_LARGE = 'large';
Expand Down Expand Up @@ -286,12 +291,18 @@ export class ImageEdit extends React.Component {
}
}

getIcon( isRetryIcon ) {
if ( isRetryIcon ) {
return <Icon icon={ SvgIconRetry } { ...styles.iconRetry } />;
getIcon( iconType ) {
let iconStyle;
switch ( iconType ) {
case ICON_TYPE.RETRY:
return <Icon icon={ SvgIconRetry } { ...styles.iconRetry } />;
case ICON_TYPE.PLACEHOLDER:
iconStyle = this.props.getStylesFromColorScheme( styles.iconPlaceholder, styles.iconPlaceholderDark );
break;
case ICON_TYPE.UPLOAD:
iconStyle = this.props.getStylesFromColorScheme( styles.iconUpload, styles.iconUploadDark );
break;
}

const iconStyle = this.props.getStylesFromColorScheme( styles.icon, styles.iconDark );
return <Icon icon={ SvgIcon } { ...iconStyle } />;
}

Expand Down Expand Up @@ -366,7 +377,7 @@ export class ImageEdit extends React.Component {
<MediaPlaceholder
allowedTypes={ [ MEDIA_TYPE_IMAGE ] }
onSelect={ this.onSelectMediaUploadOption }
icon={ this.getIcon( false ) }
icon={ this.getIcon( ICON_TYPE.PLACEHOLDER ) }
onFocus={ this.props.onFocus }
/>
</View>
Expand Down Expand Up @@ -407,12 +418,11 @@ export class ImageEdit extends React.Component {
onMediaUploadStateReset={ this.mediaUploadStateReset }
renderContent={ ( { isUploadInProgress, isUploadFailed, finalWidth, finalHeight, imageWidthWithinContainer, retryMessage } ) => {
const opacity = isUploadInProgress ? 0.3 : 1;
const icon = this.getIcon( isUploadFailed );
const imageBorderOnSelectedStyle = isSelected && ! ( isUploadInProgress || isUploadFailed || this.state.isCaptionSelected ) ? styles.imageBorder : '';

const iconContainer = (
const iconRetryContainer = (
<View style={ styles.modalIcon }>
{ icon }
{ this.getIcon( ICON_TYPE.RETRY ) }
</View>
);

Expand All @@ -425,8 +435,11 @@ export class ImageEdit extends React.Component {
alignSelf: imageWidthWithinContainer && alignToFlex[ align ] }
} >
{ ! imageWidthWithinContainer &&
<View style={ [ styles.imageContainer, { height: imageContainerHeight } ] } >
{ this.getIcon( false ) }
<View style={ [ this.props.getStylesFromColorScheme( styles.imageContainerUpload, styles.imageContainerUploadDark ),
{ height: imageContainerHeight } ] } >
<View style={ styles.imageUploadingIconContainer }>
{ this.getIcon( ICON_TYPE.UPLOAD ) }
</View>
</View> }
<ImageBackground
accessible={ true }
Expand All @@ -441,7 +454,7 @@ export class ImageEdit extends React.Component {
>
{ isUploadFailed &&
<View style={ [ styles.imageContainer, { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.5)' } ] } >
{ iconContainer }
{ iconRetryContainer }
<Text style={ styles.uploadFailedText }>{ retryMessage }</Text>
</View>
}
Expand Down
35 changes: 33 additions & 2 deletions packages/block-library/src/image/styles.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,53 @@
align-items: center;
}

.imageUploadingIconContainer {
width: 40px;
height: 40px;
justify-content: center;
align-items: center;
}

.iconRetry {
fill: #fff;
width: 100%;
height: 100%;
}

.icon {
.iconPlaceholder {
fill: $gray-dark;
width: 100%;
height: 100%;
}

.iconDark {
.iconPlaceholderDark {
fill: $white;
}

.iconUpload {
fill: $gray-lighten-20;
width: 100%;
height: 100%;
}

.iconUploadDark {
fill: $gray-70;
width: 100%;
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the dark version of the style we don't need to re-define other than the color properties. All properties that are the same will be copied from the light version.

(Same for all other Dark style definitions)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, thanks! Updated f32aab3

}

.imageContainerUpload {
justify-content: center;
align-items: center;
background-color: $gray-light;
}

.imageContainerUploadDark {
justify-content: center;
align-items: center;
background-color: $gray-90;
}

.content {
flex: 1;
}
Expand Down
30 changes: 22 additions & 8 deletions packages/block-library/src/video/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ import SvgIcon from './icon';
import SvgIconRetry from './icon-retry';
import VideoCommonSettings from './edit-common-settings';

const ICON_TYPE = {
PLACEHOLDER: 'placeholder',
RETRY: 'retry',
UPLOAD: 'upload',
};

class VideoEdit extends React.Component {
constructor( props ) {
super( props );
Expand Down Expand Up @@ -147,13 +153,20 @@ class VideoEdit extends React.Component {
}
}

getIcon( isRetryIcon, isMediaPlaceholder ) {
if ( isRetryIcon ) {
return <Icon icon={ SvgIconRetry } { ...style.icon } />;
getIcon( iconType ) {
let iconStyle;
switch ( iconType ) {
case ICON_TYPE.RETRY:
return <Icon icon={ SvgIconRetry } { ...style.icon } />;
case ICON_TYPE.PLACEHOLDER:
iconStyle = this.props.getStylesFromColorScheme( style.icon, style.iconDark );
break;
case ICON_TYPE.UPLOAD:
iconStyle = this.props.getStylesFromColorScheme( style.iconUploading, style.iconUploadingDark );
break;
}

const iconStyle = this.props.getStylesFromColorScheme( style.icon, style.iconDark );
return <Icon icon={ SvgIcon } { ...( ! isMediaPlaceholder ? style.iconUploading : iconStyle ) } />;
return <Icon icon={ SvgIcon } { ...iconStyle } />;
}

render() {
Expand Down Expand Up @@ -188,7 +201,7 @@ class VideoEdit extends React.Component {
<MediaPlaceholder
allowedTypes={ [ MEDIA_TYPE_VIDEO ] }
onSelect={ this.onSelectMediaUploadOption }
icon={ this.getIcon( false, true ) }
icon={ this.getIcon( ICON_TYPE.PLACEHOLDER ) }
onFocus={ this.props.onFocus }
/>
</View>
Expand Down Expand Up @@ -218,7 +231,7 @@ class VideoEdit extends React.Component {
onMediaUploadStateReset={ this.mediaUploadStateReset }
renderContent={ ( { isUploadInProgress, isUploadFailed, retryMessage } ) => {
const showVideo = isURL( src ) && ! isUploadInProgress && ! isUploadFailed;
const icon = this.getIcon( isUploadFailed, false );
const icon = this.getIcon( isUploadFailed ? ICON_TYPE.RETRY : ICON_TYPE.UPLOAD );
const styleIconContainer = isUploadFailed ? style.modalIconRetry : style.modalIcon;

const iconContainer = (
Expand Down Expand Up @@ -247,7 +260,8 @@ class VideoEdit extends React.Component {
</View>
}
{ ! showVideo &&
<View style={ { height: videoContainerHeight, width: '100%', ...style.placeholder } }>
<View style={ { height: videoContainerHeight, width: '100%', ...this.props.getStylesFromColorScheme(
style.placeholderContainer, style.placeholderContainerDark ) } }>
{ videoContainerHeight > 0 && iconContainer }
{ isUploadFailed && <Text style={ style.uploadFailedText }>{ retryMessage }</Text> }
</View>
Expand Down
16 changes: 15 additions & 1 deletion packages/block-library/src/video/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
background-color: #000;
}

.placeholder {
.placeholderContainer {
flex: 1;
justify-content: center;
align-items: center;
background-color: $gray-light;
}

.placeholderContainerDark {
flex: 1;
justify-content: center;
align-items: center;
background-color: $gray-90;
}

.placeholderIcon {
Expand Down Expand Up @@ -68,3 +76,9 @@
width: 100%;
height: 100%;
}

.iconUploadingDark {
fill: $gray-70;
width: 100%;
height: 100%;
}