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] Full screen block inserter menu for Android #34129

Merged
merged 15 commits into from
Aug 25, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import styles from './style.scss';

const MIN_COL_NUM = 3;

export default function BlockTypesList( { name, items, onSelect, listProps } ) {
export default function BlockTypesList( {
name,
items,
onSelect,
listProps,
initialNumToRender = 3,
} ) {
const [ numberOfColumns, setNumberOfColumns ] = useState( MIN_COL_NUM );
const [ itemWidth, setItemWidth ] = useState();
const [ maxWidth, setMaxWidth ] = useState();
Expand Down Expand Up @@ -81,7 +87,7 @@ export default function BlockTypesList( { name, items, onSelect, listProps } ) {
keyboardShouldPersistTaps="always"
numColumns={ numberOfColumns }
data={ items }
initialNumToRender={ 3 }
initialNumToRender={ initialNumToRender }
ItemSeparatorComponent={ () => (
<TouchableWithoutFeedback accessible={ false }>
<View
Expand Down
14 changes: 11 additions & 3 deletions packages/block-editor/src/components/inserter/menu.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ function InserterMenu( {
const [ filterValue, setFilterValue ] = useState( '' );
const [ showTabs, setShowTabs ] = useState( true );
// eslint-disable-next-line no-undef
const [ showSearchForm, setShowSearchForm ] = useState( __DEV__ );
const [ showSearchForm, setShowSearchForm ] = useState( true );
const [ tabIndex, setTabIndex ] = useState( 0 );

const isIOS = Platform.OS === 'ios';

const {
showInsertionPoint,
hideInsertionPoint,
Expand Down Expand Up @@ -200,17 +202,23 @@ function InserterMenu( {
}
hasNavigation
setMinHeightToMaxHeight={ showSearchForm }
contentStyle={ styles.list }
contentStyle={ styles[ 'inserter-menu__list' ] }
isFullScreen={ ! isIOS && showSearchForm }
allowDragIndicator={ true }
>
<BottomSheetConsumer>
{ ( { listProps } ) => (
<TouchableHighlight accessible={ false }>
<TouchableHighlight
accessible={ false }
style={ styles[ 'inserter-menu__list-wrapper' ] }
>
{ ! showTabs || filterValue ? (
<InserterSearchResults
rootClientId={ rootClientId }
filterValue={ filterValue }
onSelect={ onSelectItem }
listProps={ listProps }
isFullScreen={ ! isIOS && showSearchForm }
/>
) : (
<InserterTabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,34 @@ import InserterNoResults from './no-results';
import { store as blockEditorStore } from '../../store';
import useBlockTypeImpressions from './hooks/use-block-type-impressions';

const NON_BLOCK_CATEGORIES = [ 'reusable' ];
const ALLOWED_EMBED_VARIATIONS = [ 'core/embed' ];

function InserterSearchResults( {
filterValue,
onSelect,
listProps,
rootClientId,
isFullScreen,
} ) {
const { blockTypes } = useSelect(
( select ) => {
const allItems = select( blockEditorStore ).getInserterItems(
rootClientId
);
const filteredItems = searchItems( allItems, filterValue );

const blockItems = allItems.filter(
( { id, category } ) =>
! NON_BLOCK_CATEGORIES.includes( category ) &&
// We don't want to show all possible embed variations
// as different blocks in the inserter. We'll only show a
// few popular ones.
( category !== 'embed' ||
( category === 'embed' &&
ALLOWED_EMBED_VARIATIONS.includes( id ) ) )
);

const filteredItems = searchItems( blockItems, filterValue );

return { blockTypes: filteredItems };
},
Expand All @@ -46,6 +62,7 @@ function InserterSearchResults( {
return (
<BlockTypesList
name="Blocks"
initialNumToRender={ isFullScreen ? 10 : 3 }
{ ...{ items, onSelect: handleSelect, listProps } }
/>
);
Expand Down
13 changes: 8 additions & 5 deletions packages/block-editor/src/components/inserter/style.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
color: $blue-30;
}

.list {
.inserter-menu__list-wrapper {
flex: 1;
}

.inserter-menu__list {
padding-bottom: 20;
padding-top: 8;
}
Expand Down Expand Up @@ -51,13 +55,12 @@

.inserter-tabs__wrapper {
overflow: hidden;
flex: 1;
}

.inserter-tabs__container {
height: 100%;
width: 100%;
}

.inserter-tabs__item {
position: absolute;
flex: 1;
flex-direction: row;
}
8 changes: 1 addition & 7 deletions packages/block-editor/src/components/inserter/tabs.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ function InserterTabs( {
>
<Animated.View style={ containerStyle }>
{ tabs.map( ( { component: TabComponent }, index ) => (
<View
key={ `tab-${ index }` }
style={ [
styles[ 'inserter-tabs__item' ],
{ left: index * wrapperWidth },
] }
>
<View key={ `tab-${ index }` }>
<TabComponent
rootClientId={ rootClientId }
onSelect={ onSelect }
Expand Down
12 changes: 11 additions & 1 deletion packages/components/src/mobile/bottom-sheet/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,16 @@ class BottomSheet extends Component {
</>
);

const showDragIndicator = () => {
// if iOS or not fullscreen show the drag indicator
if ( Platform.OS === 'ios' || ! this.state.isFullScreen ) {
return true;
}

// Otherwise check the allowDragIndicator
return this.props.allowDragIndicator;
};

return (
<Modal
isVisible={ isVisible }
Expand Down Expand Up @@ -536,7 +546,7 @@ class BottomSheet extends Component {
style={ styles.header }
onLayout={ this.onHeaderLayout }
>
{ ! ( Platform.OS === 'android' && isFullScreen ) && (
{ showDragIndicator() && (
<View style={ styles.dragIndicator } />
) }
{ ! hideHeader && getHeader() }
Expand Down
17 changes: 12 additions & 5 deletions packages/components/src/search-control/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TouchableOpacity,
Platform,
useColorScheme,
Keyboard,
} from 'react-native';

/**
Expand Down Expand Up @@ -116,12 +117,18 @@ function SearchControl( {
setCurrentStyles( futureStyles );
}, [ isActive, isDark ] );

useEffect(
() => () => {
useEffect( () => {
const keyboardHideSubscription = Keyboard.addListener(
'keyboardDidHide',
() => {
onCancel();
}
);
return () => {
clearTimeout( onCancelTimer.current );
},
[]
);
keyboardHideSubscription.remove();
};
}, [] );

const {
'search-control__container': containerStyle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
.search-control__container {
height: 40px;
}

.search-control__container--active {
border-bottom-color: $light-gray-500;
border-bottom-width: 1px;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
border-radius: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.search-control__container {
height: 40px;
}
.search-control__container--active {
margin-right: 0;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/search-control/style.native.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.search-control__container {
height: 46px;
height: 48px;
margin: 0 16px $grid-unit-10;
flex-direction: row;
justify-content: space-between;
}

.search-control__inner-container {
Expand Down