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] Buttons block #20191

Merged
merged 60 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
094f8eb
Merge Button changes into Buttons block
lukewalczak Feb 12, 2020
f99fa78
Merge branch 'master' into rnmobile/buttons
lukewalczak Feb 14, 2020
7ac5c48
Merge branch 'master' into rnmobile/buttons
lukewalczak Feb 17, 2020
35e0cb6
Correct expanding button inside buttons
lukewalczak Feb 17, 2020
2ef3544
Adjust logic for removing last button from buttons
lukewalczak Feb 17, 2020
754ec3a
Correct styles import
lukewalczak Feb 17, 2020
865e37f
Refactor adding Button logic inside Buttons
lukewalczak Feb 18, 2020
da749f3
Correct appender
lukewalczak Feb 18, 2020
5a8686e
Merge branch 'master' into rnmobile/buttons
lukewalczak Feb 18, 2020
b5506d5
Correct flex prop initial value
lukewalczak Feb 18, 2020
841d60a
Pass flex prop, correct styles
lukewalczak Feb 18, 2020
e947b12
Add functionality for custom onDelete
lukewalczak Feb 19, 2020
3597f77
Merge branch 'master' into rnmobile/buttons
lukewalczak Feb 19, 2020
8f113d1
Create customOnAdd function
lukewalczak Feb 20, 2020
49fb5bf
Unblock Buttons for testing
lukewalczak Feb 20, 2020
f58ebd4
Merge branch 'master' into rnmobile/buttons
lukewalczak Feb 20, 2020
98754fc
Revert inserter changes
lukewalczak Feb 20, 2020
43f135e
Do not display insertion line
lukewalczak Feb 20, 2020
ae0c67a
Inline appender refactor
Feb 25, 2020
3b23c54
Revert line
lukewalczak Feb 25, 2020
eb7ef7d
Refactor icons and focusing richtext
lukewalczak Feb 25, 2020
f835078
Correct inline appender and fix deleting behavior
lukewalczak Feb 26, 2020
7b5e2f2
Support created before Buttons, change dimmed opacity value
lukewalczak Feb 27, 2020
b2a31db
Pass prop for rendering footer appender
lukewalczak Feb 27, 2020
90c6f05
Refactor setting maxWidth function
lukewalczak Feb 27, 2020
45e83ab
Correct setting maxWidth condition
lukewalczak Feb 27, 2020
1de5f5d
Merge branch 'master' into rnmobile/buttons
lukewalczak Feb 28, 2020
42f24f9
Correct lint
lukewalczak Feb 28, 2020
3291d04
Remove redundant logic to fix test, set dimming opacity to 1.0
lukewalczak Feb 28, 2020
63652ee
Correct current logic for Android
lukewalczak Feb 28, 2020
83b3037
Try avoid buttons jumping
lukewalczak Feb 28, 2020
448bd72
Adjust Button for Android
lukewalczak Mar 2, 2020
72e0867
Avoid setting state in onLayout frequently
lukewalczak Mar 3, 2020
accb890
Merge branch 'master' into rnmobile/buttons
lukewalczak Mar 9, 2020
9692565
Merge branch 'master' into rnmobile/buttons
lukewalczak Mar 18, 2020
8edc752
Revert opacity changes, refactor alignment styles
lukewalczak Mar 23, 2020
72171a1
Correct isFlex prop
lukewalczak Mar 23, 2020
3339add
Merge branch 'master' into rnmobile/buttons
lukewalczak Mar 26, 2020
d2b3d2e
Merge branch 'master' into rnmobile/buttons
lukewalczak Mar 26, 2020
451a434
Adjust Buttons after bordering
lukewalczak Mar 26, 2020
355b50e
Correct buttons styles
lukewalczak Apr 3, 2020
8966c09
Correct border on Android
lukewalczak Apr 3, 2020
923dd21
Refactor on add/remove block func, move horizontal alignment
lukewalczak Apr 6, 2020
2770bb0
Refactor alignment options
lukewalczak Apr 6, 2020
fd5c450
Use useResizeObserver for calculating parent width
lukewalczak Apr 7, 2020
0c60210
Merge branch 'master' into rnmobile/buttons
lukewalczak Apr 7, 2020
3f3b217
Code refactor after review
lukewalczak Apr 7, 2020
b6b8657
Refactor useResizeObserver usage
lukewalczak Apr 7, 2020
7041408
Merge branch 'master' into rnmobile/buttons
lukewalczak Apr 9, 2020
00a7b6e
Small cleanup
lukewalczak Apr 9, 2020
0a2b996
onDelete function refactor
lukewalczak Apr 10, 2020
e55a36d
Calculate placeholder text width
lukewalczak Apr 10, 2020
276cb5e
Simplify getPlaceholdeWith function
lukewalczak Apr 10, 2020
c082b3a
Refactor floating appender,rename horizontalDirection into isStackedH…
lukewalczak Apr 14, 2020
eb3b8ce
Merge branch 'master' into rnmobile/buttons
lukewalczak Apr 14, 2020
9a53911
Merge branch 'master' into rnmobile/buttons
lukewalczak Apr 14, 2020
8dcf7f0
Merge branch 'master' into rnmobile/buttons
lukewalczak Apr 15, 2020
c7c0bfa
Remove useless codelines
lukewalczak Apr 15, 2020
0bfb26f
Add renderFooterAppender
lukewalczak Apr 15, 2020
37e0ccc
Revert get placeholder width condition
lukewalczak Apr 15, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class BlockListBlock extends Component {
this.props.onCaretVerticalPositionChange
}
clientId={ this.props.clientId }
parentWidth={ this.props.parentWidth }
contentStyle={ this.props.contentStyle }
onDeleteBlock={ this.props.onDeleteBlock }
/>
);
}
Expand All @@ -93,7 +95,7 @@ class BlockListBlock extends Component {
isDimmed,
isTouchable,
onDeleteBlock,
horizontalDirection,
isStackedHorizontally,
hasParent,
isParentSelected,
onSelect,
Expand Down Expand Up @@ -180,7 +182,9 @@ class BlockListBlock extends Component {
<BlockMobileToolbar
clientId={ clientId }
onDelete={ onDeleteBlock }
horizontalDirection={ horizontalDirection }
isStackedHorizontally={
isStackedHorizontally
}
/>
) }
</View>
Expand Down
63 changes: 40 additions & 23 deletions packages/block-editor/src/components/block-list/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class BlockList extends Component {

shouldShowInnerBlockAppender() {
const { blockClientIds, renderAppender } = this.props;

return renderAppender && blockClientIds.length > 0;
}

Expand All @@ -95,7 +96,6 @@ export class BlockList extends Component {
blockClientIds,
title,
header,
withFooter = true,
isReadOnly,
isRootList,
horizontal,
Expand All @@ -104,6 +104,8 @@ export class BlockList extends Component {
shouldShowInsertionPointAfter,
marginVertical = styles.defaultBlock.marginTop,
marginHorizontal = styles.defaultBlock.marginLeft,
isStackedHorizontally,
horizontalAlignment,
pinarol marked this conversation as resolved.
Show resolved Hide resolved
} = this.props;

const { blockToolbar, blockBorder, headerToolbar } = styles;
Expand Down Expand Up @@ -144,7 +146,12 @@ export class BlockList extends Component {
contentContainerStyle={
horizontal && styles.horizontalContentContainer
}
style={ ! isRootList && styles.overflowVisible }
style={ [
! isRootList && styles.overflowVisible,
isStackedHorizontally && styles.horizontal,
horizontalAlignment &&
styles[ `is-aligned-${ horizontalAlignment }` ],
] }
data={ blockClientIds }
keyExtractor={ identity }
extraData={ forceRefresh }
Expand All @@ -157,9 +164,7 @@ export class BlockList extends Component {
ListEmptyComponent={
! isReadOnly && this.renderDefaultBlockAppender
}
ListFooterComponent={
! isReadOnly && withFooter && this.renderBlockListFooter
}
ListFooterComponent={ this.renderBlockListFooter }
/>

{ this.shouldShowInnerBlockAppender() && (
Expand Down Expand Up @@ -188,7 +193,7 @@ export class BlockList extends Component {
shouldShowInsertionPointAfter,
marginVertical = styles.defaultBlock.marginTop,
marginHorizontal = styles.defaultBlock.marginLeft,
horizontalDirection,
isStackedHorizontally,
contentResizeMode,
contentStyle,
onAddBlock,
Expand Down Expand Up @@ -218,7 +223,8 @@ export class BlockList extends Component {
onCaretVerticalPositionChange={
this.onCaretVerticalPositionChange
}
horizontalDirection={ horizontalDirection }
parentWidth={ this.props.parentWidth }
lukewalczak marked this conversation as resolved.
Show resolved Hide resolved
isStackedHorizontally={ isStackedHorizontally }
contentStyle={ contentStyle }
onAddBlock={ onAddBlock }
onDeleteBlock={ onDeleteBlock }
Expand All @@ -234,18 +240,29 @@ export class BlockList extends Component {

renderBlockListFooter() {
const paragraphBlock = createBlock( 'core/paragraph' );
return (
<>
<TouchableWithoutFeedback
accessibilityLabel={ __( 'Add paragraph block' ) }
onPress={ () => {
this.addBlockToEndOfPost( paragraphBlock );
} }
>
<View style={ styles.blockListFooter } />
</TouchableWithoutFeedback>
</>
);
const {
isReadOnly,
withFooter = true,
renderFooterAppender,
} = this.props;

if ( ! isReadOnly && withFooter ) {
return (
<>
<TouchableWithoutFeedback
accessibilityLabel={ __( 'Add paragraph block' ) }
onPress={ () => {
this.addBlockToEndOfPost( paragraphBlock );
} }
>
<View style={ styles.blockListFooter } />
</TouchableWithoutFeedback>
</>
);
} else if ( renderFooterAppender ) {
return renderFooterAppender();
}
return null;
}
}

Expand All @@ -260,7 +277,7 @@ export default compose( [
getSettings,
} = select( 'core/block-editor' );

const horizontalDirection =
const isStackedHorizontally =
__experimentalMoverDirection === 'horizontal';

const selectedBlockClientId = getSelectedBlockClientId();
Expand All @@ -269,7 +286,7 @@ export default compose( [
const blockInsertionPointIsVisible = isBlockInsertionPointVisible();
const shouldShowInsertionPointBefore = ( clientId ) => {
return (
! horizontalDirection &&
! isStackedHorizontally &&
blockInsertionPointIsVisible &&
insertionPoint.rootClientId === rootClientId &&
// if list is empty, show the insertion point (via the default appender)
Expand All @@ -280,7 +297,7 @@ export default compose( [
};
const shouldShowInsertionPointAfter = ( clientId ) => {
return (
! horizontalDirection &&
! isStackedHorizontally &&
blockInsertionPointIsVisible &&
insertionPoint.rootClientId === rootClientId &&
// if the insertion point is at the end of the list
Expand All @@ -301,7 +318,7 @@ export default compose( [
selectedBlockClientId,
isReadOnly,
isRootList: rootClientId === undefined,
horizontalDirection,
isStackedHorizontally,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
17 changes: 17 additions & 0 deletions packages/block-editor/src/components/block-list/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@
height: $mobile-block-toolbar-height;
}

.horizontal {
flex-direction: row;
flex-wrap: wrap;
}

.is-aligned-left {
justify-content: flex-start;
}

.is-aligned-center {
justify-content: center;
}

.is-aligned-right {
justify-content: flex-end;
}

.overflowVisible {
overflow: visible;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const BlockMobileToolbar = ( {
clientId,
onDelete,
order,
horizontalDirection,
isStackedHorizontally,
} ) => (
<View style={ styles.toolbar }>
<BlockMover
clientIds={ [ clientId ] }
horizontalDirection={ horizontalDirection }
isStackedHorizontally={ isStackedHorizontally }
/>

<View style={ styles.spacer } />
Expand Down
13 changes: 7 additions & 6 deletions packages/block-editor/src/components/block-mover/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const BlockMover = ( {
onMoveUp,
firstIndex,
rootClientId,
horizontalDirection,
isStackedHorizontally,
} ) => {
const {
backwardButtonIcon,
Expand All @@ -61,7 +61,7 @@ const BlockMover = ( {
forwardButtonHint,
firstBlockTitle,
lastBlockTitle,
} = horizontalDirection ? horizontalMover : verticalMover;
} = isStackedHorizontally ? horizontalMover : verticalMover;

if ( isLocked || ( isFirst && isLast && ! rootClientId ) ) {
return null;
Expand All @@ -72,7 +72,7 @@ const BlockMover = ( {
forwardButtonProp,
backwardButtonProp
) => {
if ( isRTL && horizontalDirection ) {
if ( isRTL && isStackedHorizontally ) {
// for RTL and horizontal direction switch prop between forward and backward button
if ( isBackwardButton ) {
return forwardButtonProp; // set forwardButtonProp for backward button
Expand All @@ -89,9 +89,10 @@ const BlockMover = ( {
const direction = isBackwardButton ? -1 : 1;
const toIndex = fromIndex + direction; // position after move

const { backwardButtonTitle, forwardButtonTitle } = horizontalDirection
? horizontalMover
: verticalMover;
const {
backwardButtonTitle,
forwardButtonTitle,
} = isStackedHorizontally ? horizontalMover : verticalMover;

const buttonTitle = switchButtonPropIfRTL(
isBackwardButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function ButtonBlockAppender( {
rootClientId,
getStylesFromColorScheme,
showSeparator,
isFloating = false,
onAddBlock,
} ) {
const appenderStyle = {
Expand All @@ -31,7 +32,9 @@ function ButtonBlockAppender( {
};
const addBlockButtonStyle = getStylesFromColorScheme(
styles.addBlockButton,
styles.addBlockButtonDark
isFloating
? styles.floatingAddBlockButtonDark
: styles.addBlockButtonDark
);

return (
Expand All @@ -45,7 +48,12 @@ function ButtonBlockAppender( {
disabled={ disabled }
fixedRatio={ false }
>
<View style={ appenderStyle }>
<View
style={ [
appenderStyle,
isFloating && styles.floatingAppender,
] }
>
<Icon
icon={ plusCircleFilled }
style={ addBlockButtonStyle }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
border-radius: 4px;
}

.floatingAppender {
flex: none;
background-color: transparent;
border-width: 0;
}

.appenderLight {
background-color: $white;
border: $border-width solid $light-gray-500;
Expand All @@ -30,3 +36,8 @@
color: $background-dark-secondary;
background-color: $gray-40;
}

.floatingAddBlockButtonDark {
color: $black;
background-color: $gray-40;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import withClientId from './with-client-id';
export const ButtonBlockAppender = ( {
clientId,
showSeparator,
isFloating,
onAddBlock,
} ) => {
return (
<BaseButtonBlockAppender
rootClientId={ clientId }
showSeparator={ showSeparator }
isFloating={ isFloating }
onAddBlock={ onAddBlock }
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import { compose } from '@wordpress/compose';
*/
import ButtonBlockAppender from './button-block-appender';
import DefaultBlockAppender from './default-block-appender';

/**
* Internal dependencies
*/
import BlockList from '../block-list';
import { withBlockEditContext } from '../block-edit/context';

Expand Down Expand Up @@ -112,7 +108,9 @@ class InnerBlocks extends Component {
const {
clientId,
renderAppender,
renderFooterAppender,
__experimentalMoverDirection,
parentWidth,
horizontal,
scrollEnabled,
contentResizeMode,
Expand All @@ -121,6 +119,7 @@ class InnerBlocks extends Component {
onDeleteBlock,
marginVertical,
marginHorizontal,
horizontalAlignment,
} = this.props;
const { templateInProcess } = this.state;

Expand All @@ -132,10 +131,13 @@ class InnerBlocks extends Component {
marginHorizontal={ marginHorizontal }
rootClientId={ clientId }
renderAppender={ renderAppender }
renderFooterAppender={ renderFooterAppender }
withFooter={ false }
__experimentalMoverDirection={
__experimentalMoverDirection
}
parentWidth={ parentWidth }
horizontalAlignment={ horizontalAlignment }
horizontal={ horizontal }
scrollEnabled={ scrollEnabled }
contentResizeMode={ contentResizeMode }
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/hooks/index.native.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Internal dependencies
*/
export { AlignmentHookSettingsProvider } from './align';

import './custom-class-name';
import './generated-class-name';
import './style';
Expand Down
Loading