Repository navigation
Fix full-screen bottom sheet animations #34425
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
Changes from all commits
1847875
4854d73
9d43b06
5304fd5
42a997d
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ const BottomSheetNavigationScreen = ( { | |
| fullScreen, | ||
| isScrollable, | ||
| isNested, | ||
| name, | ||
| } ) => { | ||
| const navigation = useNavigation(); | ||
| const heightRef = useRef( { maxHeight: 0 } ); | ||
|
|
@@ -79,11 +80,19 @@ const BottomSheetNavigationScreen = ( { | |
| }; | ||
| return useMemo( () => { | ||
| return isScrollable || isNested ? ( | ||
| <View onLayout={ onLayout }>{ children }</View> | ||
| <View | ||
| onLayout={ onLayout } | ||
| testID={ `navigation-screen-${ name }` } | ||
|
Member
Author
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. As this is an element with no user-facing identifier, a |
||
| > | ||
| { children } | ||
| </View> | ||
| ) : ( | ||
| <ScrollView { ...listProps }> | ||
| <TouchableHighlight accessible={ false }> | ||
| <View onLayout={ onLayout }> | ||
| <View | ||
| onLayout={ onLayout } | ||
| testID={ `navigation-screen-${ name }` } | ||
| > | ||
| { children } | ||
| { ! isNested && ( | ||
| <View | ||
|
|
||
| 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'; | ||
| /** | ||
|
|
@@ -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
Member
Author
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. 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; | ||
|
|
||
| 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 ); | ||
| } ); | ||
| } ); |
Uh oh!
There was an error while loading. Please reload this page.
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.
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.