-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Android): prevent sheet footer from flickering on sheet sliding (#…
…2505) ## Description Previous implementation of `sheetTopWhileDragging` relied on linear interpolation. Due to numeric errors in floating point division sometimes the footer was +- 1 pixel up/down from the accurate position, resulting in 1px flickering / "dancing". This PR changes the way sheet top is computed to making use of the parent screen `top` property, whenever possible. ## Changes - **Add test dedicated to formsheet** - **"Stabilize" footer** ## Test code and steps to reproduce Added dedicated test `TestFormSheet`. ## Checklist - [ ] Included code example that can be used to test this change - [ ] Updated TS types - [ ] Updated documentation: <!-- For adding new props to native-stack --> - [ ] https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx - [ ] Ensured that CI passes
- Loading branch information
Showing
4 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import React from 'react'; | ||
import { enableFreeze } from 'react-native-screens'; | ||
import Example from './Example'; | ||
// import * as Test from './src/tests'; | ||
// import Example from './Example'; | ||
import * as Test from './src/tests'; | ||
|
||
enableFreeze(true); | ||
|
||
export default function App() { | ||
return <Example />; | ||
// return <Test.Test42 />; | ||
// return <Example />; | ||
return <Test.TestFormSheet />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { NavigationContainer, RouteProp } from "@react-navigation/native"; | ||
import { NativeStackNavigationProp, createNativeStackNavigator } from "@react-navigation/native-stack"; | ||
import React, { useLayoutEffect } from "react"; | ||
import { Button, Text, TextInput, View } from "react-native"; | ||
|
||
type RouteParamList = { | ||
Home: undefined; | ||
FormSheet: undefined; | ||
} | ||
|
||
type RouteProps<RouteName extends keyof RouteParamList> = { | ||
navigation: NativeStackNavigationProp<RouteParamList, RouteName>; | ||
route: RouteProp<RouteParamList, RouteName>; | ||
} | ||
|
||
const Stack = createNativeStackNavigator<RouteParamList>(); | ||
|
||
function Home({ navigation }: RouteProps<'Home'>) { | ||
return ( | ||
<View style={{ flex: 1, backgroundColor: 'lightsalmon' }}> | ||
<Button title="Open FormSheet" onPress={() => navigation.navigate('FormSheet')} /> | ||
</View> | ||
); | ||
} | ||
|
||
function FormSheet({ navigation }: RouteProps<'FormSheet'>) { | ||
return ( | ||
<View style={{ backgroundColor: 'lightgreen' }}> | ||
<View style={{ paddingTop: 20 }}> | ||
<Button title="Go back" onPress={() => navigation.goBack()} /> | ||
</View> | ||
<View style={{ alignItems: 'center' }}> | ||
<TextInput style={{ marginVertical: 12, paddingVertical: 8, backgroundColor: 'lavender', borderRadius: 24, width: '80%' }} placeholder="Trigger keyboard..."></TextInput> | ||
</View> | ||
</View> | ||
) | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator> | ||
<Stack.Screen name="Home" component={Home} /> | ||
<Stack.Screen name="FormSheet" component={FormSheet} options={{ | ||
presentation: 'formSheet', | ||
sheetAllowedDetents: [0.5, 1.0], | ||
sheetCornerRadius: 8, | ||
sheetLargestUndimmedDetentIndex: 'last', | ||
contentStyle: { | ||
backgroundColor: 'lightblue', | ||
}, | ||
unstable_sheetFooter: () => { | ||
return ( | ||
<View style={{ height: 64, backgroundColor: 'red' }}> | ||
<Text>Footer</Text> | ||
<Button title="Just click me" onPress={() => console.log('Footer button clicked')} /> | ||
</View> | ||
); | ||
} | ||
}}/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters