import Transition from "react-native-screen-transitions";
import { createBlankStackNavigator } from "react-native-screen-transitions/blank-stack";
import { View, Text, Image, TouchableOpacity } from "react-native";
import Animated, { interpolate } from "react-native-reanimated";
const Stack = createBlankStackNavigator();
// Home screen with tap target
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, padding: 20, justifyContent: "center" }}>
<TouchableOpacity
onPress={() => navigation.navigate("ImageDetail")}
style={{ alignSelf: "center" }}
>
<Transition.Pressable
sharedBoundTag="photo"
style={{ width: 100, height: 100, marginBottom: 10 }}
>
<Image
source={{ uri: "https://picsum.photos/100" }}
style={{ width: 100, height: 100, borderRadius: 8 }}
/>
</Transition.Pressable>
</TouchableOpacity>
<Text style={{ textAlign: "center" }}>Tap image to expand</Text>
</View>
);
}
// Detail screen with full image
function ImageDetailScreen() {
return (
<View style={{ flex: 1, backgroundColor: "#000" }}>
<Transition.View
sharedBoundTag="photo"
style={{ width: "100%", height: "50%", alignSelf: "center" }}
>
<Image
source={{ uri: "https://picsum.photos/500" }}
style={{ width: "100%", height: "100%" }}
/>
</Transition.View>
</View>
);
}
export default function App() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen
name="ImageDetail"
component={ImageDetailScreen}
options={{
screenStyleInterpolator: ({ progress, bounds }) => {
"worklet";
const photoTransform = bounds({
id: "photo",
method: "transform",
});
return {
contentStyle: {
backgroundColor: interpolate(
progress,
[0, 1, 2],
["transparent", "#000", "#000"]
),
},
"photo": photoTransform,
};
},
gestureEnabled: true,
gestureDirection: "vertical",
}}
/>
</Stack.Navigator>
);
}