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

[Mobile] Link picker via fetch #23922

Merged
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
14802b9
Implement link cell component for RN link picker experiment
mkevins May 22, 2020
8ec1a99
Use link cell in link modal UI
mkevins May 22, 2020
866d98a
Add link cell component
mkevins Jun 25, 2020
ed47f53
Add link suggestion item cell component
mkevins Jun 25, 2020
c621a55
Implement link picker results component via fetch function
mkevins Jun 25, 2020
1270065
Add link picker component
mkevins Jun 25, 2020
b02c759
Use link picker as subsheet in format library link modal
mkevins Jun 25, 2020
a74a408
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch
mkevins Jun 25, 2020
57fd2c6
Support search API endpoint
mkevins Jun 25, 2020
c8adbb8
Use ListHeaderComponent HACK for nested flatlist in scrollview
mkevins Jun 26, 2020
f44b30e
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch
mkevins Jul 6, 2020
59943fc
Revert "Use ListHeaderComponent HACK for nested flatlist in scrollview"
mkevins Jul 6, 2020
4b96728
use optimised FlatList inside bottom-sheet
dratwas Jul 10, 2020
b3558d1
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
mkevins Jul 14, 2020
4ce9237
Merge remote-tracking branch 'origin/rnmobile/bottom-sheet-flat-list'…
mkevins Jul 14, 2020
73026da
Implement basic pagination
mkevins Jul 14, 2020
0f78196
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
mkevins Jul 20, 2020
adee81a
fix android scroll on separator item
dratwas Jul 20, 2020
7c535aa
Merge branch 'rnmobile/bottom-sheet-flat-list' into rnmobile/feature/…
mkevins Jul 23, 2020
d64f8bf
Fix prettier issues
mkevins Jul 23, 2020
4f57f11
Debounce fetch on query changes
mkevins Jul 24, 2020
23078e5
Add gridicons as one-offs
mkevins Jul 24, 2020
8be7518
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
mkevins Jul 24, 2020
9e7a756
Use default instead of named import of styles in link suggestion item
mkevins Jul 27, 2020
eb345e9
Use hook instead of hoc in suggestion item
mkevins Jul 27, 2020
94dba57
fix bottom spacing in inserter and justifyContent
dratwas Jul 27, 2020
dea6d8f
add crollableContentStyle and use it
dratwas Jul 27, 2020
ef21b83
remove unused style
dratwas Jul 27, 2020
77e3f90
render spacing view only if needed
dratwas Jul 27, 2020
7d363bb
Use array literal for style instead of compose
mkevins Jul 27, 2020
d28755e
Add refresh gridicon
mkevins Jul 27, 2020
6446be4
Implement animated loading spinner
mkevins Jul 27, 2020
2a15031
Add loading icon to link picker results
mkevins Jul 27, 2020
ee09fd5
Merge branch 'rnmobile/bottom-sheet-flat-list' into rnmobile/feature/…
mkevins Jul 27, 2020
f0e32dd
Add temporary padding for testing apk
mkevins Jul 27, 2020
c46f59f
Update packages/components/src/mobile/bottom-sheet/index.native.js
dratwas Jul 28, 2020
2b6ed2b
fix syntax error after applying suggestion
dratwas Jul 28, 2020
b292cea
fix: set correct height of container
dratwas Jul 28, 2020
96f246f
Align link cell and link picker labels
mkevins Jul 29, 2020
5a439b4
Add chevron to link cell
mkevins Jul 29, 2020
59bd9b6
Left align query input and remove icon
mkevins Jul 29, 2020
95ffe9e
Use native spinner with some padding
mkevins Jul 29, 2020
1360519
Add apply button to link picker fullsheet
mkevins Jul 29, 2020
17d5c7e
Refactor picker spinner to use hasAllSuggestions state
mkevins Jul 29, 2020
99ca76e
Merge branch 'rnmobile/bottom-sheet-flat-list' into rnmobile/feature/…
mkevins Jul 29, 2020
c31d626
Use apply instead of check icon in ios navigation header
mkevins Jul 29, 2020
152edf7
Use safearea view for fullsheet link picker
mkevins Jul 29, 2020
fa7b3e7
Make protocol detection case insensitive
mkevins Jul 30, 2020
b0fe6df
DRY up gridicons code a bit
mkevins Jul 30, 2020
d6e62a1
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
mkevins Jul 30, 2020
cf909b9
Only render cell label if it is present
mkevins Jul 31, 2020
8482780
Adjust styles for picker input cell
mkevins Jul 31, 2020
bc495da
Fix css lint
mkevins Jul 31, 2020
6c4b642
Add scheme-specific suggestion summaries
mkevins Jul 31, 2020
d06e560
Use "Close" for iOS back button in fullsheet
mkevins Aug 3, 2020
2859bd0
Make link suggestion summary text smaller
mkevins Aug 3, 2020
b95238a
Use px unit in link suggestion styles
mkevins Aug 3, 2020
9220783
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
mkevins Aug 3, 2020
b039b7f
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
dratwas Aug 18, 2020
64a12d2
[WIP]Refactor to use new navigation
dratwas Aug 18, 2020
978a141
change modalUI to function
dratwas Aug 19, 2020
cb61996
first version of working full height modal with keyboard
dratwas Aug 20, 2020
58ff3a5
[WIP] generic way of handling fullscreen bottom-sheet screens
dratwas Aug 21, 2020
63e44a8
add fullHeight prop to navigation-screen
dratwas Aug 25, 2020
3f41b60
Add setHeight to useCallback dependencies
dratwas Aug 25, 2020
86842c0
Merge branch 'rnmobile/feat/full-height-bottom-sheet-screen' into rnm…
dratwas Aug 25, 2020
2443fb0
Fix issue with empty records in link picker list
dratwas Aug 25, 2020
58b8a23
fix some performance issues
dratwas Aug 25, 2020
8cf4c0d
remove useCallbacks since it is slower and fix the focus loop
dratwas Aug 26, 2020
4adec31
fix padding bottom
dratwas Aug 26, 2020
9016e1e
Fix for bottom insets
dratwas Aug 26, 2020
5437f0f
move styles to scss
dratwas Aug 26, 2020
f9681f6
add missing spacing on the top
dratwas Aug 26, 2020
d6166e6
fix issue with wrong title when removing the old one
dratwas Aug 26, 2020
de1298c
Refactor: move screens to separate file
dratwas Aug 26, 2020
a9af080
Apply suggestions from design review
dratwas Aug 27, 2020
afffc32
remove top handler from full screen bottom sheet android
dratwas Aug 28, 2020
2f272e5
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
dratwas Aug 28, 2020
e32e3e6
fix import of styles
dratwas Aug 28, 2020
424c408
fix rest of imports
dratwas Aug 28, 2020
0d4aa93
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
dratwas Aug 31, 2020
3565b0c
Add page param to docs
dratwas Aug 31, 2020
fec19db
set type of suggestions to post
dratwas Sep 1, 2020
67fba45
add cancel-circle-filled icon and use it in link picker
dratwas Sep 1, 2020
062f8ae
filter empty records
dratwas Sep 1, 2020
f2c15a3
(Andorid): Hide keyboard before back, change icon color, remove top c…
dratwas Sep 2, 2020
98684f1
hide keyboard first on Android
dratwas Sep 2, 2020
13b1df7
fix icon colors in cell.native
dratwas Sep 3, 2020
f8b0275
Android fixes for animation
dratwas Sep 4, 2020
ce05e08
change the icon color
dratwas Sep 4, 2020
54192c6
remove old tests
dratwas Sep 7, 2020
16c4e38
remove unused file and some cleanup
dratwas Sep 7, 2020
1380410
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
dratwas Sep 7, 2020
5d1691d
iOS close to cancel / Android arrow left icon to cancel icon
dratwas Sep 10, 2020
57689df
Fix initial selection
dratwas Sep 10, 2020
4a12d0b
change color of clear icon in link picker
dratwas Sep 11, 2020
84fa7fd
Back comment about supported endpoints
lukewalczak Sep 16, 2020
bfe859f
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
lukewalczak Sep 16, 2020
4679f08
Update changelog
lukewalczak Sep 18, 2020
91c83dd
Merge branch 'master' into rnmobile/feature/link-picker-via-fetch-wit…
lukewalczak Sep 18, 2020
a346bba
Add missing colors for link picker
lukewalczak Sep 18, 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
1 change: 1 addition & 0 deletions packages/components/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export { default as ReadableContentView } from './mobile/readable-content-view';
export { default as CycleSelectControl } from './mobile/cycle-select-control';
export { default as Gradient } from './mobile/gradient';
export { default as ColorSettings } from './mobile/color-settings';
export { LinkPicker } from './mobile/link-picker';
export { default as LinkSettings } from './mobile/link-settings';
export { default as Image, IMAGE_DEFAULT_FOCAL_POINT } from './mobile/image';
export { default as ImageEditingButton } from './mobile/image/image-editing-button';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useState,
useContext,
useMemo,
useCallback,
Children,
useRef,
} from '@wordpress/element';
Expand Down Expand Up @@ -77,18 +78,33 @@ function BottomSheetNavigationContainer( { children, animate, main, theme } ) {
},
};

const setHeight = ( height, layout ) => {
if ( currentHeight !== height && height > 1 ) {
if ( animate && layout && currentHeight === 1 ) {
setCurrentHeight( height );
} else if ( animate ) {
const setHeight = useCallback(
( height, layout ) => {
// The screen is fullHeight or changing from fullScreen to the default mode
if (
( typeof currentHeight === 'string' &&
typeof height !== 'string' ) ||
typeof height === 'string'
) {
performLayoutAnimation( ANIMATION_DURATION );
setCurrentHeight( height );
} else {
setCurrentHeight( height );

return;
}
}
};

if ( currentHeight !== height && height > 1 ) {
if ( animate && layout && currentHeight === 1 ) {
setCurrentHeight( height );
} else if ( animate ) {
performLayoutAnimation( ANIMATION_DURATION );
setCurrentHeight( height );
} else {
setCurrentHeight( height );
}
}
},
[ currentHeight ]
);

const screens = useMemo( () => {
return Children.map( children, ( child ) => {
Expand All @@ -105,9 +121,16 @@ function BottomSheetNavigationContainer( { children, animate, main, theme } ) {

return useMemo( () => {
return (
<View style={ { height: currentHeight } }>
<View
style={ {
height: currentHeight,
} }
>
<BottomSheetNavigationProvider
value={ { setHeight, currentHeight } }
value={ {
setHeight,
currentHeight,
} }
>
{ main ? (
<NavigationContainer theme={ _theme }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* External dependencies
*/
import {
useFocusEffect,
useIsFocused,
useNavigation,
useFocusEffect,
} from '@react-navigation/native';
import { View } from 'react-native';
import { debounce } from 'lodash';
Expand All @@ -21,18 +21,21 @@ import { useRef, useCallback, useContext, useMemo } from '@wordpress/element';
*/
import { BottomSheetNavigationContext } from './bottom-sheet-navigation-context';

const BottomSheetNavigationScreen = ( { children } ) => {
const BottomSheetNavigationScreen = ( { children, fullScreen } ) => {
const navigation = useNavigation();
const heightRef = useRef( { maxHeight: 0 } );
const isFocused = useIsFocused();
const {
onHandleHardwareButtonPress,
shouldEnableBottomSheetMaxHeight,
setIsFullScreen,
} = useContext( BottomSheetContext );

const { setHeight } = useContext( BottomSheetNavigationContext );

const setHeightDebounce = useCallback( debounce( setHeight, 10 ), [] );
const setHeightDebounce = useCallback( debounce( setHeight, 10 ), [
setHeight,
] );

useFocusEffect(
useCallback( () => {
Expand All @@ -45,17 +48,25 @@ const BottomSheetNavigationScreen = ( { children } ) => {
onHandleHardwareButtonPress( null );
return false;
} );
if ( heightRef.current.maxHeight !== 0 ) {
if ( fullScreen ) {
setHeight( '100%' );
setIsFullScreen( true );
} else if ( heightRef.current.maxHeight !== 0 ) {
setIsFullScreen( false );
setHeight( heightRef.current.maxHeight );
}
return () => {};
}, [] )
}, [ setHeight ] )
);
const onLayout = ( { nativeEvent } ) => {
if ( fullScreen ) {
return;
}
const { height } = nativeEvent.layout;

if ( heightRef.current.maxHeight !== height && isFocused ) {
heightRef.current.maxHeight = height;
setHeightDebounce( height, true );
setHeightDebounce( height );
}
};

Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/mobile/bottom-sheet/cell.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class BottomSheetCell extends Component {
);
}

componentDidUpdate() {
if ( this.state.isEditingValue ) {
componentDidUpdate( prevProps, prevState ) {
if ( ! prevState.isEditingValue && this.state.isEditingValue ) {
this._valueTextInput.focus();
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class BottomSheetCell extends Component {
<Icon
icon={ icon }
size={ 24 }
color={ iconStyle.color }
fill={ iconStyle.color }
isPressed={ false }
/>
<View
Expand Down
56 changes: 50 additions & 6 deletions packages/components/src/mobile/bottom-sheet/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import PickerCell from './picker-cell';
import SwitchCell from './switch-cell';
import RangeCell from './range-cell';
import ColorCell from './color-cell';
import LinkCell from './link-cell';
import LinkSuggestionItemCell from './link-suggestion-item-cell';
import RadioCell from './radio-cell';
import NavigationScreen from './bottom-sheet-navigation/navigation-screen';
import NavigationContainer from './bottom-sheet-navigation/navigation-container';
Expand All @@ -50,6 +52,8 @@ class BottomSheet extends Component {
this
);

this.setIsFullScreen = this.setIsFullScreen.bind( this );

this.onDimensionsChange = this.onDimensionsChange.bind( this );
this.onCloseBottomSheet = this.onCloseBottomSheet.bind( this );
this.onHandleClosingBottomSheet = this.onHandleClosingBottomSheet.bind(
Expand All @@ -64,6 +68,7 @@ class BottomSheet extends Component {

this.state = {
safeAreaBottomInset: 0,
safeAreaTopInset: 0,
bounces: false,
maxHeight: 0,
keyboardHeight: 0,
Expand All @@ -72,6 +77,7 @@ class BottomSheet extends Component {
handleClosingBottomSheet: null,
handleHardwareButtonPress: null,
isMaxHeightSet: true,
isFullScreen: this.props.isFullScreen || false,
};

SafeArea.getSafeAreaInsetsForRootView().then(
Expand Down Expand Up @@ -136,13 +142,19 @@ class BottomSheet extends Component {
}

onSafeAreaInsetsUpdate( result ) {
const { safeAreaBottomInset } = this.state;
const { safeAreaBottomInset, safeAreaTopInset } = this.state;
if ( this.safeAreaEventSubscription === null ) {
return;
}
const { safeAreaInsets } = result;
if ( safeAreaBottomInset !== safeAreaInsets.bottom ) {
this.setState( { safeAreaBottomInset: safeAreaInsets.bottom } );
if (
safeAreaBottomInset !== safeAreaInsets.bottom ||
safeAreaTopInset !== safeAreaInsets.top
) {
this.setState( {
safeAreaBottomInset: safeAreaInsets.bottom,
safeAreaTopInset: safeAreaInsets.top,
} );
}
}

Expand Down Expand Up @@ -231,6 +243,16 @@ class BottomSheet extends Component {
this.onShouldSetBottomSheetMaxHeight( true );
}

setIsFullScreen( isFullScreen ) {
if ( isFullScreen !== this.state.isFullScreen ) {
if ( isFullScreen ) {
this.setState( { isFullScreen, isMaxHeightSet: false } );
} else {
this.setState( { isFullScreen, isMaxHeightSet: true } );
}
}
}

onHardwareButtonPress() {
const { onClose } = this.props;
const { handleHardwareButtonPress } = this.state;
Expand All @@ -245,7 +267,6 @@ class BottomSheet extends Component {
getContentStyle() {
const { safeAreaBottomInset } = this.state;
return {
flexGrow: 1,
paddingBottom:
( safeAreaBottomInset || 0 ) +
styles.scrollableContent.paddingBottom,
Expand All @@ -272,9 +293,11 @@ class BottomSheet extends Component {
maxHeight,
bounces,
safeAreaBottomInset,
safeAreaTopInset,
isScrolling,
scrollEnabled,
isMaxHeightSet,
isFullScreen,
} = this.state;

const panResponder = PanResponder.create( {
Expand Down Expand Up @@ -303,6 +326,12 @@ class BottomSheet extends Component {
styles.bottomSheetHeaderTitleDark
);

let listStyle = {};
if ( isFullScreen ) {
listStyle = { flexGrow: 1 };
} else if ( isMaxHeightSet ) {
listStyle = { maxHeight };
}
const listProps = {
disableScrollViewPanResponder: true,
bounces,
Expand All @@ -316,8 +345,10 @@ class BottomSheet extends Component {
contentStyle,
isChildrenScrollable && this.getContentStyle(),
contentStyle,
isFullScreen && { flexGrow: 1 },
],
style: isMaxHeightSet ? { maxHeight } : {},
style: listStyle,
safeAreaBottomInset,
scrollEnabled,
automaticallyAdjustContentInsets: false,
};
Expand Down Expand Up @@ -373,11 +404,21 @@ class BottomSheet extends Component {
style={ {
...backgroundStyle,
borderColor: 'rgba(0, 0, 0, 0.1)',
marginTop:
Platform.OS === 'ios' && isFullScreen
? safeAreaTopInset
: 0,
flex: isFullScreen ? 1 : undefined,
...( Platform.OS === 'android' && isFullScreen
? styles.backgroundFullScreen
: {} ),
...style,
} }
keyboardVerticalOffset={ -safeAreaBottomInset }
>
<View style={ styles.dragIndicator } />
{ ! ( Platform.OS === 'android' && isFullScreen ) && (
<View style={ styles.dragIndicator } />
) }
{ ! hideHeader && getHeader() }
<WrapperView
{ ...( isChildrenScrollable
Expand All @@ -396,6 +437,7 @@ class BottomSheet extends Component {
onHandleHardwareButtonPress: this
.onHandleHardwareButtonPress,
listProps,
setIsFullScreen: this.setIsFullScreen,
} }
>
<TouchableHighlight accessible={ false }>
Expand Down Expand Up @@ -429,6 +471,8 @@ ThemedBottomSheet.PickerCell = PickerCell;
ThemedBottomSheet.SwitchCell = SwitchCell;
ThemedBottomSheet.RangeCell = RangeCell;
ThemedBottomSheet.ColorCell = ColorCell;
ThemedBottomSheet.LinkCell = LinkCell;
ThemedBottomSheet.LinkSuggestionItemCell = LinkSuggestionItemCell;
ThemedBottomSheet.RadioCell = RadioCell;
ThemedBottomSheet.NavigationScreen = NavigationScreen;
ThemedBottomSheet.NavigationContainer = NavigationContainer;
Expand Down
28 changes: 28 additions & 0 deletions packages/components/src/mobile/bottom-sheet/link-cell.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { link, Icon, chevronRight } from '@wordpress/icons';

/**
* Internal dependencies
*/
import Cell from './cell';
import styles from './styles.scss';

const { placeholderColor } = styles;

export default function LinkCell( { value, onPress } ) {
return (
<Cell
icon={ link }
label={ __( 'Link to' ) }
// since this is not actually editable, we treat value as a placeholder
value={ value || __( 'Search or type URL' ) }
valueStyle={ !! value ? undefined : placeholderColor }
onPress={ onPress }
>
<Icon icon={ chevronRight }></Icon>
</Cell>
);
}
Loading