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

chore: make formsheet work in Example app #2528

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
41 changes: 33 additions & 8 deletions apps/src/screens/StackPresentation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ScrollView, StyleSheet, View, ImageBackground } from 'react-native';
import { ParamListBase } from '@react-navigation/native';
import { ParamListBase, RouteProp } from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
Expand All @@ -15,7 +15,7 @@ type StackParamList = {
ContainedModal: undefined;
ContainedTransparentModal: undefined;
FullScreenModal: undefined;
FormSheet: undefined;
FormSheet: { usesFormSheetPresentation?: boolean };
};

interface MainScreenProps {
Expand Down Expand Up @@ -71,21 +71,43 @@ const MainScreen = ({ navigation }: MainScreenProps): React.JSX.Element => {
);
};

interface FormScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
interface PushScreenProps {
navigation: NativeStackNavigationProp<StackParamList, 'Push'>;
}

const FormScreen = ({ navigation }: FormScreenProps): React.JSX.Element => (
const PushScreen = ({ navigation }: PushScreenProps) => (
<View style={styles.container}>
<FormScreenContent navigation={navigation} />
</View>
)

interface FormScreenProps {
navigation: NativeStackNavigationProp<StackParamList, 'FormSheet'>;
route: RouteProp<StackParamList, 'FormSheet'>;
}

const FormScreenContent = ({ navigation }: { navigation: NativeStackNavigationProp<StackParamList, 'Push' | 'FormSheet'> }) => (
<>
<Form />
<Button
testID="stack-presentation-form-screen-go-back-button"
title="Go back"
onPress={() => navigation.goBack()}
/>
</View>
</>
);


const FormScreen = ({ navigation, route }: FormScreenProps): React.JSX.Element => {
const isFormSheet = route.params?.usesFormSheetPresentation ?? false;

return (
<View style={!isFormSheet ? styles.container : null}>
<FormScreenContent navigation={navigation} />
</View>
);
}

interface ModalScreenProps {
navigation: NativeStackNavigationProp<ParamListBase>;
}
Expand Down Expand Up @@ -135,7 +157,7 @@ const App = (): React.JSX.Element => (
/>
<Stack.Screen
name="Push"
component={FormScreen}
component={PushScreen}
options={{ presentation: 'card' }}
/>
<Stack.Screen
Expand Down Expand Up @@ -177,7 +199,10 @@ const App = (): React.JSX.Element => (
<Stack.Screen
name="FormSheet"
component={FormScreen}
options={{ presentation: 'formSheet' }}
options={{ presentation: 'formSheet', sheetAllowedDetents: [0.5, 0.85] }}
initialParams={{
usesFormSheetPresentation: true
}}
/>
</Stack.Navigator>
);
Expand Down
Loading