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] Media upload multiple prop #17397

Merged
merged 36 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
635108e
[RNMobile] Native mobile release v1.11.0 (#17181)
etoledom Aug 28, 2019
472854f
rebase to rnmobile/master
dratwas Aug 28, 2019
643c1b2
Activate Travis CI on rnmobile/master branch (#17229)
etoledom Aug 28, 2019
dc3eddd
Merge branch 'rnmobile/master' into rnmobile/media-upload-props
dratwas Aug 28, 2019
ad6c39b
fix types after merge
dratwas Aug 28, 2019
944d4e7
fix tests
dratwas Aug 28, 2019
5046a97
add multiple prop support
dratwas Aug 28, 2019
0a377e7
add check if media exists
dratwas Aug 28, 2019
49d5502
fix test
dratwas Aug 28, 2019
a78f204
Add native support for the MediaText block (#16305)
Tug Aug 29, 2019
3db95b7
MediaUpload and MediaPlaceholder unify props (#17145)
dratwas Aug 30, 2019
7aa44a2
Unify media placeholder and upload props within media-text (#17268)
lukewalczak Aug 30, 2019
f9fa455
[RNMobile] Fix dismiss keyboard button for the post title (#17260)
geriux Aug 30, 2019
a30a207
Merge branch 'rnmobile/master' into rnmobile/master
dratwas Aug 30, 2019
7b12673
Recover border colors (#17269)
etoledom Aug 30, 2019
14d482b
[RNMobile] Insure tapping at end of post inserts at end
mchowning Aug 6, 2019
89664eb
Support group block on mobile (#17251)
lukewalczak Sep 3, 2019
fc8c3da
Remove redundant bg color within button appender (#17325)
lukewalczak Sep 4, 2019
264b178
[RNMobile] DarkMode improvements (#17309)
etoledom Sep 4, 2019
b4d622c
add unit test cases
dratwas Sep 10, 2019
a2b26a5
Merge branch 'rnmobile/master' into rnmobile/media-upload-multiple
dratwas Sep 10, 2019
806c880
add multiple prop to media placeholder
dratwas Sep 16, 2019
648a1b9
[RNMobile] Add autosave to mobile apps (#17329)
daniloercoli Sep 19, 2019
2a1e2a5
Merge branch 'rnmobile/master' into rnmobile/media-upload-multiple
dratwas Sep 24, 2019
e99d365
Add isAppender functionality on mobile (#17195)
lukewalczak Sep 25, 2019
69da85e
Autosave monitor - Make the mobile editor ping the native at each key…
daniloercoli Sep 25, 2019
ae6d2ce
[RNMobile] Refactor Dark Mode HOC (#17552)
Tug Sep 25, 2019
1c9b133
Add missing heading levels to the UI (H4, H5, H6) (#17533)
SergioEstevao Sep 25, 2019
df025a6
Fix lint issue (#17598)
lukewalczak Sep 26, 2019
d8b0d83
Fix list filter on paste for RN mobile. (#17550)
SergioEstevao Sep 26, 2019
f3085c1
[RNMobile] Move MediaUploadPorgress to its own component folder (#17392)
geriux Sep 27, 2019
95acf23
Rnmobile/fix link editing on start (#17631)
SergioEstevao Sep 30, 2019
99c17b2
Merge branch 'rnmobile/master' into rnmobile/media-upload-multiple
dratwas Oct 2, 2019
febf65b
Merge branch 'master' into rnmobile/media-upload-multiple
dratwas Oct 2, 2019
00c7f35
remove redundant styles
dratwas Oct 2, 2019
37642d5
Merge branch 'master' into rnmobile/media-upload-multiple
dratwas Oct 2, 2019
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cache:
branches:
only:
- master
- rnmobile/master

before_install:
- nvm install
Expand Down
30 changes: 30 additions & 0 deletions packages/block-editor/src/components/block-icon/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { get } from 'lodash';
import { View } from 'react-native';

/**
* WordPress dependencies
*/
import { Path, Icon, SVG } from '@wordpress/components';

export default function BlockIcon( { icon, showColors = false } ) {
if ( get( icon, [ 'src' ] ) === 'block-default' ) {
icon = {
src: <SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M19 7h-1V5h-4v2h-4V5H6v2H5c-1.1 0-2 .9-2 2v10h18V9c0-1.1-.9-2-2-2zm0 10H5V9h14v8z" /></SVG>,
};
}

const renderedIcon = <Icon icon={ icon && icon.src ? icon.src : icon } />;
const style = showColors ? {
backgroundColor: icon && icon.background,
color: icon && icon.foreground,
} : {};

return (
<View style={ style }>
{ renderedIcon }
</View>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* External dependencies
*/
import { last } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { getDefaultBlockName } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import DefaultBlockAppender from '../default-block-appender';
import styles from './style.scss';

function BlockListAppender( {
blockClientIds,
rootClientId,
canInsertDefaultBlock,
isLocked,
renderAppender: CustomAppender,
} ) {
if ( isLocked ) {
return null;
}

if ( CustomAppender ) {
return (
<CustomAppender />
);
}

if ( canInsertDefaultBlock ) {
return (
<DefaultBlockAppender
rootClientId={ rootClientId }
lastBlockClientId={ last( blockClientIds ) }
containerStyle={ styles.blockListAppender }
placeholder={ blockClientIds.length > 0 ? '' : null }
/>
);
}

return null;
}

export default withSelect( ( select, { rootClientId } ) => {
const {
getBlockOrder,
canInsertBlockType,
getTemplateLock,
} = select( 'core/block-editor' );

return {
isLocked: !! getTemplateLock( rootClientId ),
blockClientIds: getBlockOrder( rootClientId ),
canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootClientId ),
};
} )( BlockListAppender );
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.blockListAppender {
padding-left: 16;
padding-right: 16;
padding-top: 12;
padding-bottom: 0; // will be flushed into inline toolbar height
border-color: transparent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class BlockListBlock extends Component {
>
{ isValid && this.getBlockForType() }
{ ! isValid &&
<BlockInvalidWarning blockTitle={ title } icon={ icon } />
<BlockInvalidWarning blockTitle={ title } icon={ icon } />
}
</View>
{ isSelected && <BlockMobileToolbar clientId={ clientId } /> }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
}

.blockContainer {
background-color: $white;
padding-left: 16px;
padding-right: 16px;
padding-top: 12px;
padding-bottom: 12px;
}

.blockContainerFocused {
background-color: $white;
padding-left: 16px;
padding-right: 16px;
padding-top: 12px;
Expand Down
83 changes: 36 additions & 47 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { __ } from '@wordpress/i18n';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { createBlock, isUnmodifiedDefaultBlock } from '@wordpress/blocks';
import { KeyboardAwareFlatList, ReadableContentView } from '@wordpress/components';
import { KeyboardAwareFlatList, ReadableContentView, withTheme } from '@wordpress/components';

/**
* Internal dependencies
*/
import styles from './style.scss';
import BlockListBlock from './block';
import DefaultBlockAppender from '../default-block-appender';
import BlockListAppender from '../block-list-appender';

const innerToolbarHeight = 44;

Expand All @@ -33,31 +33,12 @@ export class BlockList extends Component {
this.renderDefaultBlockAppender = this.renderDefaultBlockAppender.bind( this );
this.onCaretVerticalPositionChange = this.onCaretVerticalPositionChange.bind( this );
this.scrollViewInnerRef = this.scrollViewInnerRef.bind( this );
this.getNewBlockInsertionIndex = this.getNewBlockInsertionIndex.bind( this );
this.addBlockToEndOfPost = this.addBlockToEndOfPost.bind( this );
this.shouldFlatListPreventAutomaticScroll = this.shouldFlatListPreventAutomaticScroll.bind( this );
}

finishBlockAppendingOrReplacing( newBlock ) {
// now determine whether we need to replace the currently selected block (if it's empty)
// or just add a new block as usual
if ( this.isReplaceable( this.props.selectedBlock ) ) {
// do replace here
this.props.replaceBlock( this.props.selectedBlockClientId, newBlock );
} else {
this.props.insertBlock( newBlock, this.getNewBlockInsertionIndex() );
}
}

getNewBlockInsertionIndex() {
if ( this.props.isPostTitleSelected ) {
// if post title selected, insert at top of post
return 0;
} else if ( this.props.selectedBlockIndex === -1 ) {
// if no block selected, insert at end of post
return this.props.blockCount;
}
// insert after selected block
return this.props.selectedBlockIndex + 1;
addBlockToEndOfPost( newBlock ) {
this.props.insertBlock( newBlock, this.props.blockCount );
}

blockHolderBorderStyle() {
Expand All @@ -79,41 +60,47 @@ export class BlockList extends Component {
renderDefaultBlockAppender() {
return (
<ReadableContentView>
<DefaultBlockAppender
<BlockListAppender
rootClientId={ this.props.rootClientId }
containerStyle={ [
styles.blockContainerFocused,
this.blockHolderBorderStyle(),
{ borderColor: 'transparent' },
] }
renderAppender={ this.props.renderAppender }
/>
</ReadableContentView>
);
}

render() {
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender } = this.props;

return (
<View
style={ { flex: 1 } }
onAccessibilityEscape={ this.props.clearSelectedBlock }
onAccessibilityEscape={ clearSelectedBlock }
>
<KeyboardAwareFlatList
{ ...( Platform.OS === 'android' ? { removeClippedSubviews: false } : {} ) } // Disable clipping on Android to fix focus losing. See https://github.com/wordpress-mobile/gutenberg-mobile/pull/741#issuecomment-472746541
accessibilityLabel="block-list"
autoScroll={ this.props.autoScroll }
innerRef={ this.scrollViewInnerRef }
extraScrollHeight={ innerToolbarHeight + 10 }
keyboardShouldPersistTaps="always"
style={ styles.list }
data={ this.props.blockClientIds }
extraData={ [ this.props.isFullyBordered ] }
data={ blockClientIds }
extraData={ [ isFullyBordered ] }
keyExtractor={ identity }
renderItem={ this.renderItem }
shouldPreventAutomaticScroll={ this.shouldFlatListPreventAutomaticScroll }
title={ this.props.title }
ListHeaderComponent={ this.props.header }
title={ title }
ListHeaderComponent={ header }
ListEmptyComponent={ this.renderDefaultBlockAppender }
ListFooterComponent={ this.renderBlockListFooter }
ListFooterComponent={ withFooter && this.renderBlockListFooter }
/>

{ renderAppender && blockClientIds.length > 0 &&
<BlockListAppender
rootClientId={ this.props.rootClientId }
renderAppender={ this.props.renderAppender }
/>
}
</View>
);
}
Expand All @@ -126,6 +113,7 @@ export class BlockList extends Component {
}

renderItem( { item: clientId, index } ) {
const blockHolderFocusedStyle = this.props.useStyle( styles.blockHolderFocused, styles.blockHolderFocusedDark );
const { shouldShowBlockAtIndex, shouldShowInsertionPoint } = this.props;
return (
<ReadableContentView>
Expand All @@ -138,18 +126,20 @@ export class BlockList extends Component {
rootClientId={ this.props.rootClientId }
onCaretVerticalPositionChange={ this.onCaretVerticalPositionChange }
borderStyle={ this.blockHolderBorderStyle() }
focusedBorderColor={ styles.blockHolderFocused.borderColor }
focusedBorderColor={ blockHolderFocusedStyle.borderColor }
/> ) }
</ReadableContentView>
);
}

renderAddBlockSeparator() {
const lineStyle = this.props.useStyle( styles.lineStyleAddHere, styles.lineStyleAddHereDark );
const labelStyle = this.props.useStyle( styles.labelStyleAddHere, styles.labelStyleAddHereDark );
return (
<View style={ styles.containerStyleAddHere } >
<View style={ styles.lineStyleAddHere }></View>
<Text style={ styles.labelStyleAddHere } >{ __( 'ADD BLOCK HERE' ) }</Text>
<View style={ styles.lineStyleAddHere }></View>
<View style={ lineStyle }></View>
<Text style={ labelStyle } >{ __( 'ADD BLOCK HERE' ) }</Text>
<View style={ lineStyle }></View>
</View>
);
}
Expand All @@ -158,7 +148,7 @@ export class BlockList extends Component {
const paragraphBlock = createBlock( 'core/paragraph' );
return (
<TouchableWithoutFeedback onPress={ () => {
this.finishBlockAppendingOrReplacing( paragraphBlock );
this.addBlockToEndOfPost( paragraphBlock );
} } >
<View style={ styles.blockListFooter } />
</TouchableWithoutFeedback>
Expand All @@ -170,19 +160,20 @@ export default compose( [
withSelect( ( select, { rootClientId } ) => {
const {
getBlockCount,
getBlockName,
getBlockIndex,
getBlockOrder,
getSelectedBlock,
getSelectedBlockClientId,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
getSelectedBlock,
} = select( 'core/block-editor' );

const selectedBlockClientId = getSelectedBlockClientId();
const blockClientIds = getBlockOrder( rootClientId );
const insertionPoint = getBlockInsertionPoint();
const blockInsertionPointIsVisible = isBlockInsertionPointVisible();
const selectedBlock = getSelectedBlock();
const isSelectedGroup = selectedBlock && selectedBlock.name === 'core/group';
const shouldShowInsertionPoint = ( clientId ) => {
return (
blockInsertionPointIsVisible &&
Expand All @@ -194,7 +185,7 @@ export default compose( [
const selectedBlockIndex = getBlockIndex( selectedBlockClientId );
const shouldShowBlockAtIndex = ( index ) => {
const shouldHideBlockAtIndex = (
blockInsertionPointIsVisible &&
! isSelectedGroup && blockInsertionPointIsVisible &&
// if `index` === `insertionPoint.index`, then block is replaceable
index === insertionPoint.index &&
// only hide selected block
Expand All @@ -206,13 +197,10 @@ export default compose( [
return {
blockClientIds,
blockCount: getBlockCount( rootClientId ),
getBlockName,
isBlockInsertionPointVisible: isBlockInsertionPointVisible(),
shouldShowBlockAtIndex,
shouldShowInsertionPoint,
selectedBlock: getSelectedBlock(),
selectedBlockClientId,
selectedBlockIndex,
};
} ),
withDispatch( ( dispatch ) => {
Expand All @@ -228,5 +216,6 @@ export default compose( [
replaceBlock,
};
} ),
withTheme,
] )( BlockList );

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* External dependencies
*/
import { Text, View } from 'react-native';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import styles from './style.scss';

const BlockInsertionPoint = ( { showInsertionPoint } ) => {
if ( ! showInsertionPoint ) {
return null;
}

return (
<View style={ styles.containerStyleAddHere } >
<View style={ styles.lineStyleAddHere }></View>
<Text style={ styles.labelStyleAddHere } >{ __( 'ADD BLOCK HERE' ) }</Text>
<View style={ styles.lineStyleAddHere }></View>
</View>
);
};

export default withSelect( ( select, { clientId, rootClientId } ) => {
const {
getBlockIndex,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
} = select( 'core/block-editor' );
const blockIndex = getBlockIndex( clientId, rootClientId );
const insertionPoint = getBlockInsertionPoint();
const showInsertionPoint = (
isBlockInsertionPointVisible() &&
insertionPoint.index === blockIndex &&
insertionPoint.rootClientId === rootClientId
);

return { showInsertionPoint };
} )( BlockInsertionPoint );
Loading