Skip to content

Commit

Permalink
[RNMobile] Gallery - Add append logic to MediaPlaceholder (#18262)
Browse files Browse the repository at this point in the history
* Add append logic to MediaPlaceholder for gallery

* Fix lint errors
  • Loading branch information
mkevins committed Nov 7, 2019
1 parent ad35eda commit 6b4cf2c
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { View, Text, TouchableWithoutFeedback } from 'react-native';
import { uniqBy } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -22,6 +23,7 @@ import styles from './styles.scss';

function MediaPlaceholder( props ) {
const {
addToGallery,
allowedTypes = [],
labels = {},
icon,
Expand All @@ -30,8 +32,13 @@ function MediaPlaceholder( props ) {
disableMediaButtons,
getStylesFromColorScheme,
multiple,
value = [],
} = props;

const setMedia = multiple && addToGallery ?
( selected ) => onSelect( uniqBy( [ ...value, ...selected ], 'id' ) ) :
onSelect;

const isOneType = allowedTypes.length === 1;
const isImage = isOneType && allowedTypes.includes( MEDIA_TYPE_IMAGE );
const isVideo = isOneType && allowedTypes.includes( MEDIA_TYPE_VIDEO );
Expand Down Expand Up @@ -103,7 +110,7 @@ function MediaPlaceholder( props ) {
<View style={ { flex: 1 } }>
<MediaUpload
allowedTypes={ allowedTypes }
onSelect={ onSelect }
onSelect={ setMedia }
multiple={ multiple }
render={ ( { open, getMediaOptions } ) => {
return (
Expand Down

0 comments on commit 6b4cf2c

Please sign in to comment.