Skip to content
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
30 changes: 26 additions & 4 deletions apps/expo/src/app/camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { NativeStackNavigationProp } from "@react-navigation/native-stack";
import type * as React from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import {
BackHandler,
InteractionManager,
Pressable,
StyleSheet,
Expand Down Expand Up @@ -213,6 +214,14 @@ export default function CameraPage(): React.ReactElement {
onFlipCameraPressed();
}, [onFlipCameraPressed]);

const clearSelectedRecipient = useCallback(() => {
navigation.setParams({ defaultRecipientId: undefined });
navigation.navigate("Main", { screen: "Friends" });
}, [navigation]);
const clearSelectedRecipientInPlace = useCallback(() => {
navigation.setParams({ defaultRecipientId: undefined });
}, [navigation]);

// On focus, revalidate the session in case cookie exists but session expired
useFocusEffect(
useCallback(() => {
Expand Down Expand Up @@ -261,6 +270,22 @@ export default function CameraPage(): React.ReactElement {
void requestPermissions();
}, [isCameraInitialized, isActive, requestPermissions]);

useFocusEffect(
useCallback(() => {
if (!defaultRecipientId) return;

const backHandler = BackHandler.addEventListener(
"hardwareBackPress",
() => {
clearSelectedRecipient();
return true;
},
);

return () => backHandler.remove();
}, [clearSelectedRecipient, defaultRecipientId]),
);

const videoHdr = format?.supportsVideoHdr && enableHdr;
const photoHdr = format?.supportsPhotoHdr && enableHdr && !videoHdr;

Expand Down Expand Up @@ -364,10 +389,7 @@ export default function CameraPage(): React.ReactElement {
Sending to {selectedFriend.name}
</Text>
<Pressable
onPress={() => {
// Clear the pre-selection by resetting navigation params
navigation.setParams({ defaultRecipientId: undefined });
}}
onPress={clearSelectedRecipientInPlace}
style={styles.clearButton}
>
<Ionicons name="close-outline" size={24} color="white" />
Expand Down