-
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
Merged
gziolo
merged 12 commits into
WordPress:rnmobile/master
from
callstack:rnmobile/is-appender
Sep 25, 2019
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
302c905
Add isAppender functionality on mobile
lukewalczak 5a38e78
refactor isAppender conditions
lukewalczak d75fdb6
Merge branch 'rnmobile/master' into rnmobile/is-appender
lukewalczak 24355ca
Replace dropZoneUIOnly in favour of showMediaSelectionUI
lukewalczak 204be46
deprecate dropZoneUIOnly and add disableMediaSelection prop
lukewalczak 873357c
Merge branch 'rnmobile/master' into rnmobile/is-appender
lukewalczak b0013fc
Update test
lukewalczak ceaff07
Refactor tests and change prop name
lukewalczak a4a0ec6
Remove redundant empty lines
lukewalczak 8ac70ad
Refactor conditions inside MediaPlaceholder
lukewalczak 84973dc
Update block-editor CHANGELOG
lukewalczak 22425ee
Update packages/block-editor/CHANGELOG.md
lukewalczak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,27 @@ 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 { | ||
MediaUpload, | ||
MEDIA_TYPE_IMAGE, | ||
MEDIA_TYPE_VIDEO, | ||
} from '@wordpress/block-editor'; | ||
import { Dashicon } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
function MediaPlaceholder( props ) { | ||
const { mediaType, labels = {}, icon, onSelectURL } = props; | ||
const { | ||
mediaType, | ||
labels = {}, | ||
icon, | ||
onSelectURL, | ||
isAppender, | ||
isSelected, | ||
} = props; | ||
|
||
const isImage = MEDIA_TYPE_IMAGE === mediaType; | ||
const isVideo = MEDIA_TYPE_VIDEO === mediaType; | ||
|
@@ -46,40 +58,63 @@ function MediaPlaceholder( props ) { | |
accessibilityHint = __( 'Double tap to select a video' ); | ||
} | ||
|
||
const renderContent = () => { | ||
if ( isAppender === undefined || ! isAppender ) { | ||
return ( | ||
<> | ||
<View style={ styles.modalIcon }>{ icon }</View> | ||
<Text style={ styles.emptyStateTitle }>{ placeholderTitle }</Text> | ||
<Text style={ styles.emptyStateDescription }>{ instructions }</Text> | ||
</> | ||
); | ||
} else if ( isAppender && isSelected ) { | ||
return ( | ||
<Dashicon | ||
icon="plus-alt" | ||
style={ styles.addBlockButton } | ||
color={ styles.addBlockButton.color } | ||
size={ styles.addBlockButton.size } | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
if ( isAppender && ! isSelected ) { | ||
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 | ||
mediaType={ mediaType } | ||
onSelectURL={ onSelectURL } | ||
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={ styles.emptyStateContainer }> | ||
{ getMediaOptions() } | ||
<View style={ styles.modalIcon }> | ||
{ icon } | ||
<View style={ { flex: 1 } }> | ||
<MediaUpload | ||
mediaType={ mediaType } | ||
onSelectURL={ onSelectURL } | ||
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={ [ | ||
styles.emptyStateContainer, | ||
isAppender && styles.isAppender, | ||
] }> | ||
{ getMediaOptions() } | ||
{ renderContent() } | ||
</View> | ||
<Text style={ styles.emptyStateTitle }> | ||
{ placeholderTitle } | ||
</Text> | ||
<Text style={ styles.emptyStateDescription }> | ||
{ instructions } | ||
</Text> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
} } /> | ||
</TouchableWithoutFeedback> | ||
); | ||
} } | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It doesn't look like
isSelected
needs to be part of MediaPlaceholder API. Block can decide to render/not render the MediaPlaceholder due to its selected state.Also as far as I see web also handles it this way without needing to add this to MediaPlaceholder API and we want to come close to web as much as possible.
Let me know if I am missing something.
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.
According to the mobile gallery design,
isAppender
button should be displayed only whengallery
block is selected, that's why there is a need to passisSelected
value from parent component intomediaPlaceholder
. Please, correct me if I understood it wrongly.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.
Could you be able to do some investigation about how this works on web? As far as I see mediaplaceholder isn't rendered if block is not selected on web as well. So how is it handled without some isSelected prop on Gallery block? We want to keep props of components as similar as possible between platforms.
Independent from this, it doesn't sound right for a component to have a prop named 'isSelected' where it actually decides rendering/not rendering it. 'isSelected' belongs to blocks and not applicable here as is. We need to change it to describe what it does for MediaPlaceholder.
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.
Sure, will investigate it!
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.
After the investigation, I've noticed that web media-placeholder accepts prop called
dropZoneUIOnly={ hasImages && ! isSelected }
which then within placeholder is rendering gallery with appender whendropZoneUIOnly === false
otherwise without appender.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.
maybe we can make use of the same prop for parity, although, we don't currently have drag & drop of media. But it looks like a nice enhancement for the future. wdyt @koke ? I think we can start using
dropZoneUIOnly
on mobile too.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 don't think
dropZoneUIOnly
is the right prop to use here. I checked theREADME
and it's not documented anywhere. From what I'm seeing, as long as media upload is possible, the drop zone would be rendered on the web, and the UI to pick media is the variable here.Adding
dropZoneUIOnly
to mobile would imply that we support drag and drop, and could be confusing. I'd rather flip the logic and have ashowMediaSelectionUI
(or another better name) prop that is set only when the block is selected.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.
The name you've proposed (
showMediaSelectionUI
) sounds good for me. Just to be sure, would you like to replacedropZoneUIOnly
withshowMediaSelectionUI
on the web and have the same prop on mobile?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.
Yes, I would propose that change for the web as well
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.
LGTM as soon as we keep the parity. 👍