-
-
Notifications
You must be signed in to change notification settings - Fork 607
fix(Android, FormSheet): Fix dynamic height change for fitToContents #3484
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
Open
t0maboro
wants to merge
19
commits into
main
Choose a base branch
from
@t0maboro/fit-to-contents-dynamic-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+346
−6
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d3bdef1
Add example
t0maboro 2893205
Use absolute positioning
t0maboro cc3bf1c
Cleanup after testing
t0maboro a544161
Add animation
t0maboro ed939d2
Update example
t0maboro 2ea04ec
Change default duration
t0maboro 9e0dfab
Fix typo
t0maboro 5a049bd
Remove duration
t0maboro 8752c17
Add prop that allows overriding default animation
t0maboro 76728c2
Add description
t0maboro 882af0b
Do not use animated component by default
t0maboro 096cde4
Add Todo
t0maboro 5db2608
Restore default app
t0maboro 279daab
Allow quick shrink+expand combo to be handled properly
t0maboro 4fe8810
Fix pressables
t0maboro cd6fa67
Replace translation with direct call
t0maboro 3c89d69
Fix snapping back on Fabric
t0maboro bc2e458
Refactor animation logic
t0maboro f4475fa
Refactor
t0maboro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,175 @@ | ||
| import React, { useRef, useState } from 'react'; | ||
| import { | ||
| Button, | ||
| View, | ||
| Text, | ||
| StyleSheet, | ||
| TextInput, | ||
| Animated, | ||
| } from 'react-native'; | ||
| import { NavigationContainer } from '@react-navigation/native'; | ||
| import { | ||
| createNativeStackNavigator, | ||
| NativeStackScreenProps, | ||
| } from '@react-navigation/native-stack'; | ||
| import Colors from '../shared/styling/Colors'; | ||
| import PressableWithFeedback from '../shared/PressableWithFeedback'; | ||
|
|
||
| const USE_ANIMATED_COMPONENT = false; | ||
|
|
||
| type StackParamList = { | ||
| Home: undefined; | ||
| FormSheet: undefined; | ||
| }; | ||
|
|
||
| const Stack = createNativeStackNavigator<StackParamList>(); | ||
|
|
||
| const HomeScreen = ({ navigation }: NativeStackScreenProps<StackParamList>) => ( | ||
| <View style={styles.screen}> | ||
| <Text style={styles.title}>Home Screen</Text> | ||
| <Button | ||
| title="Open Form Sheet" | ||
| onPress={() => navigation.navigate('FormSheet')} | ||
| /> | ||
| </View> | ||
| ); | ||
|
|
||
| const FormSheetScreen = ({ | ||
| navigation, | ||
| }: NativeStackScreenProps<StackParamList>) => { | ||
| const [showTopView, setShowTopView] = useState(false); | ||
| const [showBottomView, setShowBottomView] = useState(false); | ||
| const [rectangleHeight, setRectangleHeight] = useState(200); | ||
| const animatedRectangleHeight = useRef(new Animated.Value(200)).current; | ||
| const currentAnimatedRectangleHeight = useRef(200); | ||
|
|
||
| const toggleTopView = () => setShowTopView(prev => !prev); | ||
| const toggleBottomView = () => setShowBottomView(prev => !prev); | ||
| const toggleRectangleHeight = () => | ||
| setRectangleHeight(prev => (prev === 200 ? 400 : 200)); | ||
|
|
||
| const toggleAnimatedRectangleHeight = () => { | ||
| const newHeight = | ||
| currentAnimatedRectangleHeight.current === 200 ? 400 : 200; | ||
| Animated.timing(animatedRectangleHeight, { | ||
| toValue: newHeight, | ||
| duration: 300, | ||
| useNativeDriver: false, | ||
| }).start(() => { | ||
| currentAnimatedRectangleHeight.current = newHeight; | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <View style={styles.formSheetContainer}> | ||
| {showTopView && ( | ||
| <View style={styles.rectangle}> | ||
| <TextInput style={styles.input} /> | ||
| <PressableWithFeedback> | ||
| <Text style={styles.text}>Top View</Text> | ||
| </PressableWithFeedback> | ||
| </View> | ||
| )} | ||
| <Text style={styles.formSheetTitle}>Form Sheet Content</Text> | ||
| {USE_ANIMATED_COMPONENT ? ( | ||
| <Animated.View | ||
| style={[styles.rectangle, { height: animatedRectangleHeight }]} | ||
| /> | ||
| ) : ( | ||
| <View style={[styles.rectangle, { height: rectangleHeight }]} /> | ||
| )} | ||
|
|
||
| <Button | ||
| title={showTopView ? 'Hide Top View' : 'Show Top View'} | ||
| onPress={toggleTopView} | ||
| /> | ||
| {USE_ANIMATED_COMPONENT ? ( | ||
| <Button | ||
| title={`Toggle Animated Rectangle Height (Current: ${currentAnimatedRectangleHeight.current}px)`} | ||
| onPress={toggleAnimatedRectangleHeight} | ||
| /> | ||
| ) : ( | ||
| <Button | ||
| title={`Toggle Height (Current: ${rectangleHeight}px)`} | ||
| onPress={toggleRectangleHeight} | ||
| /> | ||
| )} | ||
| <Button | ||
| title={showBottomView ? 'Hide Bottom View' : 'Show Bottom View'} | ||
| onPress={toggleBottomView} | ||
| /> | ||
| <Button title="Dismiss" onPress={() => navigation.goBack()} /> | ||
| {showBottomView && ( | ||
| <View style={styles.rectangle}> | ||
| <PressableWithFeedback> | ||
| <Text style={styles.text}>Bottom View</Text> | ||
| </PressableWithFeedback> | ||
| </View> | ||
| )} | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <NavigationContainer> | ||
| <Stack.Navigator> | ||
| <Stack.Screen name="Home" component={HomeScreen} /> | ||
| <Stack.Screen | ||
| name="FormSheet" | ||
| component={FormSheetScreen} | ||
| options={{ | ||
| presentation: 'formSheet', | ||
| sheetAllowedDetents: 'fitToContents', | ||
| contentStyle: { | ||
| backgroundColor: Colors.YellowLight40, | ||
| }, | ||
| // TODO(@t0maboro) - add `sheetContentDefaultResizeAnimationEnabled` prop here when possible | ||
| }} | ||
| /> | ||
| </Stack.Navigator> | ||
| </NavigationContainer> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| screen: { | ||
| flex: 1, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| padding: 20, | ||
| }, | ||
| title: { | ||
| fontSize: 24, | ||
| marginBottom: 20, | ||
| }, | ||
| formSheetContainer: { | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| padding: 20, | ||
| gap: 20, | ||
| }, | ||
| formSheetTitle: { | ||
| fontSize: 20, | ||
| fontWeight: 'bold', | ||
| marginBottom: 10, | ||
| }, | ||
| text: { | ||
| fontSize: 16, | ||
| marginBottom: 8, | ||
| color: Colors.White, | ||
| }, | ||
| rectangle: { | ||
| width: '100%', | ||
| backgroundColor: Colors.NavyLight80, | ||
| height: 200, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }, | ||
| input: { | ||
| width: 100, | ||
| height: 20, | ||
| borderColor: Colors.BlueDark100, | ||
| borderWidth: 1, | ||
| }, | ||
| }); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.