Skip to content

Commit

Permalink
chore: make formsheet work in Example app (#2528)
Browse files Browse the repository at this point in the history
## Description

Fixed #2521

## Changes

Separated the formsheet and card components and applied correct styles
for formsheet.

## Test code and steps to reproduce

Just use the `StackPresentation` screen in example app.

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
  • Loading branch information
kkafar authored Nov 20, 2024
1 parent 5fa039e commit 1362858
Showing 1 changed file with 33 additions and 8 deletions.
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

0 comments on commit 1362858

Please sign in to comment.