import { createBlankStackNavigator } from "react-native-screen-transitions/blank-stack";
import Transition from "react-native-screen-transitions";
import { View, Text, Image, TouchableOpacity } from "react-native";
import { interpolate } from "react-native-reanimated";
const Stack = createBlankStackNavigator();
// Home screen with image
function HomeScreen({ navigation }) {
const imageUri = "https://picsum.photos/200";
return (
<View style={{ flex: 1, padding: 20, justifyContent: "center" }}>
<TouchableOpacity
onPress={() => navigation.navigate("DetailIG", { imageUri })}
>
<Transition.Pressable
sharedBoundTag="ig-image"
style={{ width: 100, height: 100 }}
>
<Image
source={{ uri: imageUri }}
style={{ width: 100, height: 100, borderRadius: 8 }}
/>
</Transition.Pressable>
</TouchableOpacity>
</View>
);
}
// Detail screen with masked reveal
function DetailIGScreen({ route }: any) {
const { imageUri } = route.params;
return (
<View style={{ flex: 1 }}>
<Transition.MaskedView
maskElement={
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Transition.View
sharedBoundTag="ig-image"
style={{ width: 200, height: 200 }}
>
<Image
source={{ uri: imageUri }}
style={{ width: 200, height: 200, borderRadius: 16 }}
/>
</Transition.View>
</View>
}
>
<View style={{ flex: 1, backgroundColor: "#f5f5f5" }}>
<View style={{ flex: 1, paddingTop: 20, paddingHorizontal: 20 }}>
<Text style={{ fontSize: 20, fontWeight: "bold" }}>
Image Details
</Text>
<Text style={{ marginTop: 10, color: "#666" }}>
This image was revealed using a masked animation.
</Text>
</View>
</View>
</Transition.MaskedView>
</View>
);
}
export default function App() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen
name="DetailIG"
component={DetailIGScreen}
options={{
screenStyleInterpolator: ({ progress, bounds }) => {
"worklet";
const imageTransform = bounds({
id: "ig-image",
method: "transform",
});
return {
contentStyle: {
backgroundColor: interpolate(
progress,
[0, 1, 2],
["transparent", "#fff", "#fff"]
),
},
"ig-image": imageTransform,
};
},
gestureEnabled: true,
gestureDirection: "vertical",
}}
/>
</Stack.Navigator>
);
}