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] Added support for giphy and pexels images #18026

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
requestMediaPickFromMediaLibrary,
requestMediaPickFromDeviceLibrary,
requestMediaPickFromDeviceCamera,
getOtherMediaOptions,
requestOtherMediaPickFrom,
} from 'react-native-gutenberg-bridge';

/**
Expand All @@ -31,7 +33,27 @@ export class MediaUpload extends React.Component {
this.onPickerPresent = this.onPickerPresent.bind( this );
this.onPickerChange = this.onPickerChange.bind( this );
this.onPickerSelect = this.onPickerSelect.bind( this );

this.state = {
otherMediaOptions: undefined,
};
}

componentDidMount() {
const { allowedTypes = [] } = this.props;
getOtherMediaOptions( allowedTypes, ( otherMediaOptions ) => {
const otherMediaOptionsWithIcons = otherMediaOptions.map( ( option ) => {
return {
icon: this.getChooseFromDeviceIcon(),
value: option.value,
label: option.label,
};
} );

this.setState( { otherMediaOptions: otherMediaOptionsWithIcons } );
} );
}

getTakeMediaLabel() {
const { allowedTypes = [] } = this.props;

Expand Down Expand Up @@ -98,11 +120,22 @@ export class MediaUpload extends React.Component {
this.onPickerSelect( requestMediaPickFromDeviceCamera );
} else if ( value === MEDIA_UPLOAD_BOTTOM_SHEET_VALUE_WORD_PRESS_LIBRARY ) {
this.onPickerSelect( requestMediaPickFromMediaLibrary );
} else {
const { onSelect, multiple = false } = this.props;
requestOtherMediaPickFrom( value, multiple, ( media ) => {
if ( ( multiple && media ) || ( media && media.id ) ) {
onSelect( media );
}
} );
}
}

render() {
const mediaOptions = this.getMediaOptionsItems();
let mediaOptions = this.getMediaOptionsItems();

if ( this.state.otherMediaOptions ) {
mediaOptions = [ ...mediaOptions, ...this.state.otherMediaOptions ];
}

const getMediaOptions = () => (
<Picker
Expand Down
10 changes: 10 additions & 0 deletions packages/block-library/src/image/styles.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@
.iconDark {
fill: $white;
}

.content {
flex: 1;
}

.contentCentered {
flex: 1;
justify-content: center;
align-items: center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ class MediaContainer extends Component {
const { finalWidth, finalHeight, imageWidthWithinContainer, isUploadFailed, retryMessage } = params;
const opacity = isUploadInProgress ? 0.3 : 1;

const contentStyle = ! imageWidthWithinContainer ? styles.content : styles.contentCentered;

return (
<TouchableWithoutFeedback
accessible={ ! isSelected }
onPress={ this.onMediaPressed }
onLongPress={ openMediaOptions }
disabled={ ! isSelected }
>
<View style={ styles.content }>
<View style={ contentStyle }>
{ ! imageWidthWithinContainer &&
<View style={ styles.imageContainer }>
{ this.getIcon( false ) }
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/media-text/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
flex: 1;
}

.contentCentered {
flex: 1;
justify-content: center;
align-items: center;
}

.imageContainer {
align-items: center;
background-color: $gray-lighten-30;
Expand Down
2 changes: 2 additions & 0 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jest.mock( 'react-native-gutenberg-bridge', () => {
requestMediaPickFromMediaLibrary: jest.fn(),
requestMediaPickFromDeviceLibrary: jest.fn(),
requestMediaPickFromDeviceCamera: jest.fn(),
getOtherMediaOptions: jest.fn(),
requestOtherMediaPickFrom: jest.fn(),
};
} );

Expand Down