-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 isAppender functionality on mobile #17195
Changes from 4 commits
302c905
5a38e78
d75fdb6
24355ca
204be46
873357c
b0013fc
ceaff07
a4a0ec6
8ac70ad
84973dc
22425ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,15 @@ If false the default placeholder style is used. | |
- Type: `Boolean` | ||
- Required: No | ||
- Default: `false` | ||
- Platform: Web | ||
- Platform: Web | Mobile | ||
|
||
### showMediaSelectionUI | ||
|
||
Whether render a dropzone/placholder without any other additional UI. | ||
|
||
- Type: `Boolean` | ||
- Required: No | ||
- Platform: Web | Mobile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we specify the default value (false) as part of the docs? |
||
|
||
### labels | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,10 +387,10 @@ export class MediaPlaceholder extends Component { | |
|
||
render() { | ||
const { | ||
dropZoneUIOnly, | ||
showMediaSelectionUI, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gziolo 👋 would changing the prop name here be a problem? Are there some steps we need to take before changing it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be a breaking change as this prop is part of the public API. The corresponding PR was merged in March (#12367) and WordPress 5.2 went out on May 7th (https://wordpress.org/news/2019/05/jaco/). I don't see it in Anyway, it's been a few months since it was exposed as part of the public API so we would have to keep the old name as well to ensure we don't break any plugins which might be using it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see it documented in the
@jorgefilipecosta - can you help here? As far as I can tell, this is something which on the web shows only a box where you can drop an image from your OS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, as far as I understand we are not able to change that prop name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I look at the latest docs I see that disableDropZone and dropZoneUIOnly are also related: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. For consistency with the other prop I would suggest disableMediaSelection instead of “hide” There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jorgefilipecosta let us know if you have concerns about this. Otherwise I think we can go ahead and deprecate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pinarol I've updated, my PR according to the conversation above:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One test is failing |
||
} = this.props; | ||
|
||
if ( dropZoneUIOnly ) { | ||
if ( showMediaSelectionUI ) { | ||
return ( | ||
<MediaUploadCheck> | ||
{ this.renderDropZone() } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,28 @@ import { View, Text, TouchableWithoutFeedback } from 'react-native'; | |
* WordPress dependencies | ||
*/ | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
import { MediaUpload, MEDIA_TYPE_IMAGE, MEDIA_TYPE_VIDEO } from '@wordpress/block-editor'; | ||
import { withTheme, useStyle } from '@wordpress/components'; | ||
import { | ||
MediaUpload, | ||
MEDIA_TYPE_IMAGE, | ||
MEDIA_TYPE_VIDEO, | ||
} from '@wordpress/block-editor'; | ||
import { Dashicon, withTheme, useStyle } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
function MediaPlaceholder( props ) { | ||
const { allowedTypes = [], labels = {}, icon, onSelect, theme } = props; | ||
const { | ||
allowedTypes = [], | ||
labels = {}, | ||
icon, | ||
onSelect, | ||
isAppender, | ||
showMediaSelectionUI, | ||
theme, | ||
} = props; | ||
|
||
const isOneType = allowedTypes.length === 1; | ||
const isImage = isOneType && allowedTypes.includes( MEDIA_TYPE_IMAGE ); | ||
|
@@ -51,40 +63,69 @@ function MediaPlaceholder( props ) { | |
const emptyStateContainerStyle = useStyle( styles.emptyStateContainer, styles.emptyStateContainerDark, theme ); | ||
const emptyStateTitleStyle = useStyle( styles.emptyStateTitle, styles.emptyStateTitleDark, theme ); | ||
|
||
const renderContent = () => { | ||
if ( isAppender === undefined || ! isAppender ) { | ||
return ( | ||
<> | ||
<View style={ styles.modalIcon }> | ||
{ icon } | ||
</View> | ||
<Text style={ emptyStateTitleStyle }> | ||
{ placeholderTitle } | ||
</Text> | ||
<Text style={ styles.emptyStateDescription }> | ||
{ instructions } | ||
</Text> | ||
</> | ||
); | ||
} else if ( isAppender && showMediaSelectionUI ) { | ||
return ( | ||
<Dashicon | ||
icon="plus-alt" | ||
style={ styles.addBlockButton } | ||
color={ styles.addBlockButton.color } | ||
size={ styles.addBlockButton.size } | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
if ( isAppender && ! showMediaSelectionUI ) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like there's sth wrong here, it is returning null if disableMediaButtons is undefined or false. |
||
} | ||
|
||
return ( | ||
<MediaUpload | ||
allowedTypes={ allowedTypes } | ||
onSelect={ onSelect } | ||
render={ ( { open, getMediaOptions } ) => { | ||
return ( | ||
<TouchableWithoutFeedback | ||
accessibilityLabel={ sprintf( | ||
/* translators: accessibility text for the media block empty state. %s: media type */ | ||
__( '%s block. Empty' ), | ||
placeholderTitle | ||
) } | ||
accessibilityRole={ 'button' } | ||
accessibilityHint={ accessibilityHint } | ||
onPress={ ( event ) => { | ||
props.onFocus( event ); | ||
open(); | ||
} } | ||
> | ||
<View style={ emptyStateContainerStyle }> | ||
{ getMediaOptions() } | ||
<View style={ styles.modalIcon }> | ||
{ icon } | ||
<View style={ { flex: 1 } }> | ||
<MediaUpload | ||
allowedTypes={ allowedTypes } | ||
onSelect={ onSelect } | ||
render={ ( { open, getMediaOptions } ) => { | ||
return ( | ||
<TouchableWithoutFeedback | ||
accessibilityLabel={ sprintf( | ||
/* translators: accessibility text for the media block empty state. %s: media type */ | ||
__( '%s block. Empty' ), | ||
placeholderTitle | ||
) } | ||
accessibilityRole={ 'button' } | ||
accessibilityHint={ accessibilityHint } | ||
onPress={ ( event ) => { | ||
props.onFocus( event ); | ||
open(); | ||
} }> | ||
<View | ||
style={ [ | ||
emptyStateContainerStyle, | ||
isAppender && styles.isAppender, | ||
] }> | ||
{ getMediaOptions() } | ||
{ renderContent() } | ||
</View> | ||
<Text style={ emptyStateTitleStyle }> | ||
{ placeholderTitle } | ||
</Text> | ||
<Text style={ styles.emptyStateDescription }> | ||
{ instructions } | ||
</Text> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
} } /> | ||
</TouchableWithoutFeedback> | ||
); | ||
} } | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this flag if enabled will render a drop zone but not a placeholder we can update the text to: "Whether render a dropzone without any other additional UI".