import { createBlankStackNavigator } from "react-native-screen-transitions/blank-stack";
import Transition from "react-native-screen-transitions";
import { View, Text, ScrollView, TouchableOpacity } from "react-native";
import Animated, { interpolate } from "react-native-reanimated";
const Stack = createBlankStackNavigator();
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, justifyContent: "center" }}>
<TouchableOpacity onPress={() => navigation.navigate("Sheet")}>
<Text>Open Sheet</Text>
</TouchableOpacity>
</View>
);
}
function SheetScreen() {
return (
<Transition.ScrollView
style={{ flex: 1, backgroundColor: "#fff" }}
scrollEnabled={true}
>
<View style={{ padding: 20 }}>
<Text style={{ fontSize: 20, fontWeight: "bold", marginBottom: 10 }}>
Options
</Text>
<Text>Swipe to adjust the sheet height</Text>
</View>
</Transition.ScrollView>
);
}
export default function App() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen
name="Sheet"
component={SheetScreen}
options={{
snapPoints: [0.5, 0.75, 1],
initialSnapIndex: 0,
screenStyleInterpolator: ({ progress }) => {
"worklet";
return {
contentStyle: {
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
transform: [
{
translateY: interpolate(progress, [0, 1, 2], [600, 0, 600]),
},
],
},
backdropStyle: {
opacity: interpolate(progress, [0, 1, 2], [0, 0.3, 0]),
},
};
},
transitionSpec: {
open: {
timing: "spring",
config: { stiffness: 800, damping: 100 },
},
close: {
timing: "spring",
config: { stiffness: 800, damping: 100 },
},
expand: {
timing: "spring",
config: { stiffness: 600, damping: 80 },
},
collapse: {
timing: "spring",
config: { stiffness: 600, damping: 80 },
},
},
gestureEnabled: true,
gestureDirection: "vertical",
backdropBehavior: "collapse",
}}
/>
</Stack.Navigator>
);
}