-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 10 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
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,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 } from '@wordpress/components'; | ||
import { | ||
MediaUpload, | ||
MEDIA_TYPE_IMAGE, | ||
MEDIA_TYPE_VIDEO, | ||
} from '@wordpress/block-editor'; | ||
import { Dashicon, withTheme } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
function MediaPlaceholder( props ) { | ||
const { allowedTypes = [], labels = {}, icon, onSelect, useStyle } = props; | ||
const { | ||
allowedTypes = [], | ||
labels = {}, | ||
icon, | ||
onSelect, | ||
isAppender, | ||
disableMediaButtons, | ||
useStyle, | ||
} = 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 ); | ||
const emptyStateTitleStyle = useStyle( styles.emptyStateTitle, styles.emptyStateTitleDark ); | ||
|
||
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 && ! disableMediaButtons ) { | ||
return ( | ||
<Dashicon | ||
icon="plus-alt" | ||
style={ styles.addBlockButton } | ||
color={ styles.addBlockButton.color } | ||
size={ styles.addBlockButton.size } | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
if ( isAppender && disableMediaButtons ) { | ||
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> | ||
); | ||
} | ||
|
||
|
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.
Should we specify the default value (false) as part of the docs?