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] Add Reusable blocks to the inserter menu #25383

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1ea8f94
Merge pull request #3 from WordPress/master
fluiddot Sep 18, 2020
b3e7e51
Merge pull request #4 from WordPress/master
fluiddot Sep 22, 2020
80b6df5
Merge pull request #5 from WordPress/master
fluiddot Sep 24, 2020
aadd803
Merge pull request #6 from WordPress/master
fluiddot Oct 1, 2020
351a225
Merge pull request #7 from WordPress/master
fluiddot Dec 21, 2020
ff8d204
Merge pull request #8 from WordPress/master
fluiddot Dec 23, 2020
8458b75
Merge pull request #9 from WordPress/master
fluiddot Dec 30, 2020
77abb11
Merge pull request #10 from WordPress/master
fluiddot Jan 4, 2021
aef7830
Add support for required reusable blocks API paths
fluiddot Sep 10, 2020
3481cdb
Add native version of Disable component
fluiddot Sep 10, 2020
c42f0db
Add native version of Reusable block (only preview)
fluiddot Sep 10, 2020
c13151b
Add Reusable block to mobile registered core blocks
fluiddot Sep 10, 2020
0e73832
Fix undefined progress in Spinner component
fluiddot Sep 11, 2020
5620152
api-fetch-setup unit test updated with new paths
fluiddot Sep 16, 2020
9bd67ce
Posts removed from supported endpoints
fluiddot Sep 24, 2020
7315735
Add Lock icon
fluiddot Sep 25, 2020
665cd25
Add Reusable block edit title
fluiddot Sep 25, 2020
2309ac7
Extend Reusable block title separator
fluiddot Sep 29, 2020
f9b4516
Add bottom sheet to Reusable blocks
fluiddot Sep 29, 2020
7ab4a4c
Fix reusable blocks use of UBE
fluiddot Sep 30, 2020
c0855a3
Fix reusable block render bottom sheet
fluiddot Sep 30, 2020
7670980
Fix title in reusable block when using UBE
fluiddot Oct 1, 2020
002e690
Add closeSheet handler for bottom sheet in Reusable block
fluiddot Oct 2, 2020
9fcb360
Transform Reusable block edit to functional component
fluiddot Dec 23, 2020
26e7b71
Fix long texts on Reusable block title
fluiddot Dec 23, 2020
3dd7299
Filter out reusable blocks in inserter menu
fluiddot Dec 23, 2020
1dcfe46
Clear timeout when reusable block edit is unmounted
fluiddot Dec 23, 2020
6b58641
Change toggleSheet to openSheet in reusable block edit
fluiddot Dec 23, 2020
753e27b
Rename edit block in web browser label of reusable block
fluiddot Dec 30, 2020
03fcdcc
Update react-native-editor CHANGELOG
fluiddot Jan 4, 2021
c419923
Add custom header to BottomSheet
fluiddot Sep 10, 2020
96fafcd
SegmentedControl mobile component exported
fluiddot Sep 10, 2020
5fc495b
Add Reusable blocks to inserter menu with tabs
fluiddot Sep 10, 2020
8c25354
Add native version of inserter-list-item
fluiddot Sep 14, 2020
d98b527
Add mobile version of block-types-list component
fluiddot Sep 15, 2020
7c09b4e
Add getWidth to mobile version of inserter-list-item component
fluiddot Sep 15, 2020
00f7037
Add blocks-tab mobile version to inserter component
fluiddot Sep 15, 2020
f3dcfa4
Add reusable-blocks-tab mobile version to inserter component
fluiddot Sep 15, 2020
19ab89e
Inserter menu mobile version refactor to use new tabs
fluiddot Sep 15, 2020
21b79b8
Lint fixes in inserter menu components
fluiddot Sep 18, 2020
6e04f7c
README of block-types-list component updated with mobile changes
fluiddot Sep 21, 2020
f3ef832
modal prefix removed from inserter-list-item style names
fluiddot Sep 21, 2020
0839f54
blocks-tab renamed to block-types-tab in inserter menu
fluiddot Sep 21, 2020
035bd15
add block-types-tab UI test
fluiddot Sep 21, 2020
0358fa2
Add reusable-blocks-tab UI test
fluiddot Sep 22, 2020
e53c31c
Remove unused import from block types list
fluiddot Oct 2, 2020
135e06b
Change key calculation for block types list component
fluiddot Jan 4, 2021
f1c8224
Fix style format issue in inserter list item
fluiddot Jan 4, 2021
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
21 changes: 20 additions & 1 deletion packages/block-editor/src/components/block-types-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Renders a list of blocks types.
```jsx
import { BlockTypesList } from '@wordpress/block-editor';

const MyBlockTypesList = () => <BlockTypesList items={ filteredItems } />;;
const MyBlockTypesList = () => <BlockTypesList items={ filteredItems } />;
```

### Props
Expand All @@ -35,6 +35,25 @@ The blocks that will be displayed in the block list.

- Type: `Array<Block>`
- Required: Yes
- Platform: Web | Mobile

#### name

Name of the list to be used as part of component's key.

- Type: `String`
- Required: Yes
- Platform: Mobile

#### listProps

Extra `FlatList` props for customizing the list.

On Mobile usually this component is rendered inside `BottomSheet` component, which already [generates these props](<(https://github.com/WordPress/gutenberg/blob/c3c514ba1123be5a7cf881c223c038cfc31b3f59/packages/components/src/mobile/bottom-sheet/index.native.js#L335-L354)>) for this component.

- Type: `String`
- Required: No
- Platform: Mobile

## Related components

Expand Down
128 changes: 128 additions & 0 deletions packages/block-editor/src/components/block-types-list/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* External dependencies
*/
import {
FlatList,
View,
TouchableWithoutFeedback,
Dimensions,
} from 'react-native';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { BottomSheet, InserterButton } from '@wordpress/components';

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

const MIN_COL_NUM = 3;

export class BlockTypesList extends Component {
constructor() {
super( ...arguments );

this.onLayout = this.onLayout.bind( this );
this.renderItem = this.renderItem.bind( this );

this.state = {
numberOfColumns: MIN_COL_NUM,
};

Dimensions.addEventListener( 'change', this.onLayout );
}

componentWillUnmount() {
Dimensions.removeEventListener( 'change', this.onLayout );
}

calculateMinItemWidth( bottomSheetWidth ) {
const { paddingLeft, paddingRight } = styles.columnPadding;
return (
( bottomSheetWidth - 2 * ( paddingLeft + paddingRight ) ) /
MIN_COL_NUM
);
}

calculateItemWidth() {
const {
paddingLeft: itemPaddingLeft,
paddingRight: itemPaddingRight,
} = InserterButton.Styles.modalItem;
const { width: itemWidth } = InserterButton.Styles.modalIconWrapper;
return itemWidth + itemPaddingLeft + itemPaddingRight;
}

calculateColumnsProperties() {
const bottomSheetWidth = BottomSheet.getWidth();
const { paddingLeft, paddingRight } = styles.columnPadding;
const itemTotalWidth = this.calculateItemWidth();
const containerTotalWidth =
bottomSheetWidth - ( paddingLeft + paddingRight );
const numofColumns = Math.floor( containerTotalWidth / itemTotalWidth );

if ( numofColumns < MIN_COL_NUM ) {
return {
numOfColumns: MIN_COL_NUM,
itemWidth: this.calculateMinItemWidth( bottomSheetWidth ),
maxWidth: containerTotalWidth / MIN_COL_NUM,
};
}
return {
numOfColumns: numofColumns,
maxWidth: containerTotalWidth / numofColumns,
};
}

onLayout() {
const {
numOfColumns,
itemWidth,
maxWidth,
} = this.calculateColumnsProperties();
const numberOfColumns = numOfColumns;

this.setState( { numberOfColumns, itemWidth, maxWidth } );
}

renderItem( { item } ) {
const { itemWidth, maxWidth } = this.state;
const { onSelect } = this.props;
return (
<InserterButton
item={ item }
itemWidth={ itemWidth }
maxWidth={ maxWidth }
onSelect={ onSelect }
/>
);
}

render() {
const { name, items, listProps } = this.props;
const { numberOfColumns } = this.state;

return (
<FlatList
onLayout={ this.onLayout }
key={ `InserterUI-${ name }-${ numberOfColumns }` } //re-render when numberOfColumns changes
keyboardShouldPersistTaps="always"
numColumns={ numberOfColumns }
data={ items }
ItemSeparatorComponent={ () => (
<TouchableWithoutFeedback accessible={ false }>
<View style={ styles.rowSeparator } />
</TouchableWithoutFeedback>
) }
keyExtractor={ ( item ) => item.id }
renderItem={ this.renderItem }
{ ...listProps }
/>
);
}
}

export default BlockTypesList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.rowSeparator {
height: 12px;
}

.columnPadding {
padding: $grid-unit-20;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* External dependencies
*/
import { View, TouchableHighlight, Text } from 'react-native';

/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';
import { withPreferredColorScheme } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';

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

function InserterListItem( {
getStylesFromColorScheme,
item,
itemWidth,
maxWidth,
onSelect,
} ) {
const onPress = () => {
onSelect( item );
};

const iconWrapperStyle = getStylesFromColorScheme(
styles.iconWrapper,
styles.iconWrapperDark
);
const iconStyle = getStylesFromColorScheme( styles.icon, styles.iconDark );
const itemLabelStyle = getStylesFromColorScheme(
styles.itemLabel,
styles.itemLabelDark
);

const clipboardBlockStyles = getStylesFromColorScheme(
styles.clipboardBlock,
styles.clipboardBlockDark
);

const isClipboardBlock = item.id === 'clipboard';

return (
<TouchableHighlight
style={ styles.touchableArea }
underlayColor="transparent"
activeOpacity={ 0.5 }
accessibilityLabel={ item.title }
onPress={ onPress }
>
<View style={ [ styles.item, { width: maxWidth } ] }>
<View
style={ [
iconWrapperStyle,
itemWidth && {
width: itemWidth,
},
isClipboardBlock && clipboardBlockStyles,
] }
>
<View style={ iconStyle }>
<Icon
icon={ item.icon.src || item.icon }
fill={ iconStyle.fill }
size={ iconStyle.width }
/>
</View>
</View>
<Text style={ itemLabelStyle }>
{ isClipboardBlock ? __( 'Copied block' ) : item.title }
</Text>
</View>
</TouchableHighlight>
);
}

function getWidth() {
const {
paddingLeft: itemPaddingLeft,
paddingRight: itemPaddingRight,
} = styles.item;
const { width: itemWidth } = styles.iconWrapper;
return itemWidth + itemPaddingLeft + itemPaddingRight;
}

const ThemedInserterListItem = withPreferredColorScheme( InserterListItem );

ThemedInserterListItem.getWidth = getWidth;

export default ThemedInserterListItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.touchableArea {
border-radius: 8px 8px 8px 8px;
}

.item {
flex-direction: column;
justify-content: flex-start;
align-items: center;
padding-left: $grid-unit-20 / 2;
padding-right: $grid-unit-20 / 2;
padding-top: 0;
padding-bottom: 0;
}

.iconWrapper {
width: 104px;
height: 64px;
background-color: $gray-light; //#f3f6f8
border-radius: 8px 8px 8px 8px;
justify-content: center;
align-items: center;
}

.modalIconWrapperDark {
background-color: rgba($white, 0.07);
}

.icon {
width: 32px;
height: 32px;
justify-content: center;
align-items: center;
fill: $gray-dark;
}

.iconDark {
fill: $white;
}

.itemLabel {
background-color: transparent;
padding-left: 2;
padding-right: 2;
padding-top: 4;
padding-bottom: 0;
justify-content: center;
font-size: 12;
color: $gray-dark;
}

.itemLabelDark {
color: $white;
}

.clipboardBlock {
background-color: transparent;
border-width: 1px;
border-color: $light-gray-400;
}

.clipboardBlockDark {
border-color: $gray-70;
}
Loading