-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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] FloatingToolbar #17399
[RNMobile] FloatingToolbar #17399
Changes from all commits
635108e
643c1b2
a78f204
3db95b7
7aa44a2
f9fa455
7b12673
14d482b
89664eb
fc8c3da
264b178
654e162
111059c
89ed4d7
900233d
2deb517
6106f27
67c5cca
648a1b9
9659a73
e99d365
69da85e
ae6d2ce
1c9b133
8752302
e3a4f1a
df025a6
d8b0d83
59f0d5f
f3085c1
636bf83
95acf23
47cd600
6449038
d0ba0fe
c70edc5
300a8a5
a9d7489
2695248
d2a07ec
e911f5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View, TouchableWithoutFeedback } from 'react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './block-mobile-floating-toolbar.scss'; | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
|
||
const { Fill, Slot } = createSlotFill( 'FloatingToolbar' ); | ||
|
||
function FloatingToolbar( { children } ) { | ||
return ( | ||
<Fill> | ||
{ ( { innerFloatingToolbar } ) => { | ||
return ( | ||
<TouchableWithoutFeedback> | ||
<View | ||
// Issue: `FloatingToolbar` placed above the first item in group is not touchable on Android. | ||
// Temporary solution: Use `innerFloatingToolbar` to place `FloatingToolbar` over the first item in group. | ||
// TODO: `{ top: innerFloatingToolbar ? 0 : -44 }` along with `innerFloatingToolbar` should be removed once issue is fixed. | ||
style={ [ styles.floatingToolbarFill, { top: innerFloatingToolbar ? 0 : -44 } ] } | ||
>{ children } | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
} } | ||
|
||
</Fill> | ||
); | ||
} | ||
|
||
FloatingToolbar.Slot = Slot; | ||
|
||
export default FloatingToolbar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.floatingToolbarFill { | ||
background-color: $dark-gray-500; | ||
margin: auto; | ||
min-width: 100; | ||
max-height: $floating-toolbar-height; | ||
border-radius: 22px; | ||
flex-direction: row; | ||
z-index: 100; | ||
top: -$floating-toolbar-height; | ||
height: $floating-toolbar-height; | ||
position: absolute; | ||
align-items: center; | ||
justify-content: center; | ||
align-self: center; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import { KeyboardAwareFlatList, ReadableContentView } from '@wordpress/component | |
import styles from './style.scss'; | ||
import BlockListBlock from './block'; | ||
import BlockListAppender from '../block-list-appender'; | ||
import FloatingToolbar from './block-mobile-floating-toolbar'; | ||
|
||
const innerToolbarHeight = 44; | ||
|
||
|
@@ -69,13 +70,15 @@ export class BlockList extends Component { | |
} | ||
|
||
render() { | ||
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender } = this.props; | ||
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender, isFirstBlock, selectedBlockParentId } = this.props; | ||
|
||
const showFloatingToolbar = isFirstBlock && selectedBlockParentId !== ''; | ||
return ( | ||
<View | ||
style={ { flex: 1 } } | ||
onAccessibilityEscape={ clearSelectedBlock } | ||
> | ||
{ showFloatingToolbar && <FloatingToolbar.Slot fillProps={ { innerFloatingToolbar: showFloatingToolbar } } /> } | ||
<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" | ||
|
@@ -93,6 +96,9 @@ export class BlockList extends Component { | |
ListHeaderComponent={ header } | ||
ListEmptyComponent={ this.renderDefaultBlockAppender } | ||
ListFooterComponent={ withFooter && this.renderBlockListFooter } | ||
getItemLayout={ ( data, index ) => { | ||
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. Do we still need this considering the current temporary fix? If we don't let's remove it to avoid having unexpected side effects 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. Yes, it's still needed to get working properly |
||
return { length: 0, offset: 0, index }; | ||
} } | ||
/> | ||
|
||
{ renderAppender && blockClientIds.length > 0 && | ||
|
@@ -166,6 +172,7 @@ export default compose( [ | |
getBlockInsertionPoint, | ||
isBlockInsertionPointVisible, | ||
getSelectedBlock, | ||
getBlockRootClientId, | ||
} = select( 'core/block-editor' ); | ||
|
||
const selectedBlockClientId = getSelectedBlockClientId(); | ||
|
@@ -182,7 +189,12 @@ export default compose( [ | |
); | ||
}; | ||
|
||
const selectedBlockIndex = getBlockIndex( selectedBlockClientId ); | ||
const selectedBlockIndex = getBlockIndex( selectedBlockClientId, rootClientId ); | ||
|
||
const isFirstBlock = selectedBlockIndex === 0; | ||
|
||
const selectedBlockParentId = getBlockRootClientId( selectedBlockClientId ); | ||
|
||
const shouldShowBlockAtIndex = ( index ) => { | ||
const shouldHideBlockAtIndex = ( | ||
! isSelectedGroup && blockInsertionPointIsVisible && | ||
|
@@ -201,6 +213,8 @@ export default compose( [ | |
shouldShowBlockAtIndex, | ||
shouldShowInsertionPoint, | ||
selectedBlockClientId, | ||
isFirstBlock, | ||
selectedBlockParentId, | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => { | ||
|
@@ -218,4 +232,3 @@ export default compose( [ | |
} ), | ||
withPreferredColorScheme, | ||
] )( BlockList ); | ||
|
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.
Do we still need to change this file? considering we are rendering the first one inside the bounds. I know this is a temp fix but still I'd want to change minimum code to avoid any side effects until we find a better solution.
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.
If we want to simplify it to the minimum we don't need to use slot/fill, however, I've decided to keep this for the next investigations.