Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -94,9 +94,7 @@ function BottomSheetNavigationContainer( { children, animate, main, theme } ) {
}

if ( height > 1 ) {
if ( currentHeight === 1 ) {
setCurrentHeight( height );
} else if ( animate ) {
if ( animate ) {

@dcalhoun dcalhoun Aug 31, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My interpretation of the original intent of this code is to avoid animating setting the height during the initial layout. However, it was erroneously applied when navigating away from full-screen bottom sheets. Removing it resolves this issue.

From my testing, the non-animation setting was used when a block settings is first opened, but I am unable to perceive a difference with or without its presence.

performLayoutAnimation( ANIMATION_DURATION );
setCurrentHeight( height );
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const BottomSheetNavigationScreen = ( {
fullScreen,
isScrollable,
isNested,
name,
} ) => {
const navigation = useNavigation();
const heightRef = useRef( { maxHeight: 0 } );
Expand Down Expand Up @@ -79,11 +80,19 @@ const BottomSheetNavigationScreen = ( {
};
return useMemo( () => {
return isScrollable || isNested ? (
<View onLayout={ onLayout }>{ children }</View>
<View
onLayout={ onLayout }
testID={ `navigation-screen-${ name }` }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is an element with no user-facing identifier, a testID was required to query the element.

>
{ children }
</View>
) : (
<ScrollView { ...listProps }>
<TouchableHighlight accessible={ false }>
<View onLayout={ onLayout }>
<View
onLayout={ onLayout }
testID={ `navigation-screen-${ name }` }
>
{ children }
{ ! isNested && (
<View
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* External dependencies
*/
import { act } from 'react-test-renderer';
import { Text } from 'react-native';
import { render, fireEvent, waitFor } from 'test/helpers';

/**
* Internal dependencies
*/
import NavigationContainer from '../navigation-container';
import NavigationScreen from '../navigation-screen';
import { performLayoutAnimation } from '../../../layout-animation';

jest.mock( '../../../layout-animation', () => ( {
performLayoutAnimation: jest.fn(),
} ) );

const TestComponent = () => <Text>Test Component</Text>;

jest.useFakeTimers();

it( 'animates from full-screen to non-full-screen', async () => {
const screen = render(
<NavigationContainer main animate>
<NavigationScreen name="test-screen-1">
<TestComponent />
</NavigationScreen>
</NavigationContainer>
);

// Await navigation screen to allow async state updates to complete
const navigationScreen = await waitFor( () =>
screen.getByTestId( 'navigation-screen-test-screen-1' )
);

// Trigger full-screen layout
act( () => {
fireEvent( navigationScreen, 'layout', {
nativeEvent: {
layout: {
/**
* onLayout would never provide a string height, but this is the most
* straightforward approach to recreating the desired testing context.
* The alternative would be `navigation.navigate` from a full-screen
* screen to a non-full-screen screen.
*/
height: '100%',
},
},
} );
jest.runAllTimers();
} );

// Trigger non-full-screen layout
act( () => {
fireEvent( navigationScreen, 'layout', {
nativeEvent: {
layout: {
height: 123,
},
},
} );
jest.runAllTimers();
} );

expect( performLayoutAnimation ).toHaveBeenCalledTimes( 2 );
} );
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { Platform, Keyboard } from 'react-native';
import { Keyboard } from 'react-native';
import { useNavigation, useRoute } from '@react-navigation/native';
import { delay } from 'lodash';
/**
Expand All @@ -20,31 +20,20 @@ const LinkPickerScreen = () => {
const navigation = useNavigation();
const route = useRoute();
const onLinkPicked = ( { url, title } ) => {
if ( Platform.OS === 'android' ) {
Keyboard.dismiss();
delay( () => {
navigation.navigate( linkSettingsScreens.settings, {
inputValue: url,
text: title,
} );
}, 100 );
return;
}
Comment on lines -23 to -32

@dcalhoun dcalhoun Aug 31, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My presumption is that this conditional logic was placed to improve animations on Android at some point. It would appear similar logic is now beneficial for iOS as well.

navigation.navigate( linkSettingsScreens.settings, {
inputValue: url,
text: title,
} );
Keyboard.dismiss();
delay( () => {
navigation.navigate( linkSettingsScreens.settings, {
inputValue: url,
text: title,
} );
}, 100 );
};

const onCancel = () => {
if ( Platform.OS === 'android' ) {
Keyboard.dismiss();
delay( () => {
navigation.goBack();
}, 100 );
return;
}
navigation.goBack();
Keyboard.dismiss();
delay( () => {
navigation.goBack();
}, 100 );
};

const { inputValue } = route.params;
Expand Down
144 changes: 144 additions & 0 deletions packages/format-library/src/link/test/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* External dependencies
*/
import { Keyboard, Platform } from 'react-native';
import { render, fireEvent, waitFor } from 'test/helpers';

/**
* WordPress dependencies
*/
import { Slot, SlotFillProvider } from '@wordpress/components';

/**
* Internal dependencies
*/
import { link } from '../index';

const { edit: LinkEdit } = link;

// Simplified tree to render link format component
const LinkEditSlot = ( props ) => (
<SlotFillProvider>
<Slot name="RichText.ToolbarControls.link" />
<LinkEdit { ...props } />
</SlotFillProvider>
);

beforeAll( () => {
jest.useFakeTimers();
jest.spyOn( Keyboard, 'dismiss' );
Keyboard.dismiss.mockImplementation();
} );

afterAll( () => {
Keyboard.dismiss.mockRestore();
} );

describe( 'Android', () => {
it( 'ensures smooth back animation', async () => {
const screen = render(
<LinkEditSlot
activeAttributes={ {} }
onChange={ () => {} }
value={ {
text: '',
formats: [],
replacements: [],
} }
/>
);
fireEvent.press( screen.getByA11yLabel( 'Link' ) );
fireEvent.press(
screen.getByA11yLabel( 'Link to, Search or type URL' )
);
// Await back button to allow async state updates to complete
const backButton = await waitFor( () =>
screen.getByA11yLabel( 'Go back' )
);
Keyboard.dismiss.mockClear();
fireEvent.press( backButton );

expect( Keyboard.dismiss ).toHaveBeenCalledTimes( 1 );
} );

it( 'ensures smooth apply animation', async () => {
const { getByA11yLabel } = render(
<LinkEditSlot
activeAttributes={ {} }
onChange={ () => {} }
value={ {
text: '',
formats: [],
replacements: [],
} }
/>
);
fireEvent.press( getByA11yLabel( 'Link' ) );
fireEvent.press( getByA11yLabel( 'Link to, Search or type URL' ) );
// Await back button to allow async state updates to complete
const backButton = await waitFor( () => getByA11yLabel( 'Apply' ) );
Keyboard.dismiss.mockClear();
fireEvent.press( backButton );

expect( Keyboard.dismiss ).toHaveBeenCalledTimes( 1 );
} );
} );

describe( 'iOS', () => {
const originalPlatform = Platform.OS;
beforeAll( () => {
Platform.OS = 'ios';
} );

afterAll( () => {
Platform.OS = originalPlatform;
} );

it( 'ensures smooth back animation', async () => {
const screen = render(
<LinkEditSlot
activeAttributes={ {} }
onChange={ () => {} }
value={ {
text: '',
formats: [],
replacements: [],
} }
/>
);
fireEvent.press( screen.getByA11yLabel( 'Link' ) );
fireEvent.press(
screen.getByA11yLabel( 'Link to, Search or type URL' )
);
// Await back button to allow async state updates to complete
const backButton = await waitFor( () =>
screen.getByA11yLabel( 'Go back' )
);
Keyboard.dismiss.mockClear();
fireEvent.press( backButton );

expect( Keyboard.dismiss ).toHaveBeenCalledTimes( 1 );
} );

it( 'ensures smooth apply animation', async () => {
const { getByA11yLabel } = render(
<LinkEditSlot
activeAttributes={ {} }
onChange={ () => {} }
value={ {
text: '',
formats: [],
replacements: [],
} }
/>
);
fireEvent.press( getByA11yLabel( 'Link' ) );
fireEvent.press( getByA11yLabel( 'Link to, Search or type URL' ) );
// Await back button to allow async state updates to complete
const backButton = await waitFor( () => getByA11yLabel( 'Apply' ) );
Keyboard.dismiss.mockClear();
fireEvent.press( backButton );

expect( Keyboard.dismiss ).toHaveBeenCalledTimes( 1 );
} );
} );
2 changes: 2 additions & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For each user feature we should also add a importance categorization label to i

## Unreleased
- [**] Enable embed preview for a list of providers (for now only YouTube and Twitter) [#34446]
- [*] Fix animation stutter when closing full-screen bottom sheets. [#34425]

## 1.60.1
- [*] RNmobile: Fix the cancel button on Block Variation Picker / Columns Block. [#34249]
- [*] Column block: Fix Android close button alignment. [#34332]
Expand Down