diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js --- a/native/chat/chat-input-bar.react.js +++ b/native/chat/chat-input-bar.react.js @@ -90,7 +90,7 @@ import { NavContext } from '../navigation/navigation-context.js'; import { type NavigationRoute, - CameraModalRouteName, + ChatCameraModalRouteName, ImagePasteModalRouteName, } from '../navigation/route-names.js'; import { useSelector } from '../redux/redux-utils.js'; @@ -1066,8 +1066,8 @@ const openCamera = React.useCallback(() => { keyboardState?.dismissKeyboard(); - navigation.navigate<'CameraModal'>({ - name: CameraModalRouteName, + navigation.navigate<'ChatCameraModal'>({ + name: ChatCameraModalRouteName, params: { presentedFrom: route.key, thread: threadInfo, diff --git a/native/media/camera-modal.react.js b/native/media/camera-modal.react.js --- a/native/media/camera-modal.react.js +++ b/native/media/camera-modal.react.js @@ -1,6 +1,11 @@ // @flow import Icon from '@expo/vector-icons/Ionicons.js'; +import { + useNavigation, + type NavigationProp, + type ParamListBase, +} from '@react-navigation/native'; import invariant from 'invariant'; import * as React from 'react'; import { @@ -32,18 +37,14 @@ import { useIsAppForegrounded } from 'lib/shared/lifecycle-utils.js'; import type { PhotoCapture } from 'lib/types/media-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; -import type { ThreadInfo } from 'lib/types/thread-types.js'; import SendMediaButton from './send-media-button.react.js'; import ContentLoading from '../components/content-loading.react.js'; import ConnectedStatusBar from '../connected-status-bar.react.js'; -import { type InputState, InputStateContext } from '../input/input-state.js'; -import type { AppNavigationProp } from '../navigation/app-navigator.react.js'; import { OverlayContext, type OverlayContextType, } from '../navigation/overlay-context.js'; -import type { NavigationRoute } from '../navigation/route-names.js'; import { updateDeviceCameraInfoActionType } from '../redux/action-types.js'; import { type DimensionsInfo } from '../redux/dimensions-updater.react.js'; import { useSelector } from '../redux/redux-utils.js'; @@ -221,19 +222,13 @@ ]); } -export type CameraModalParams = { - +presentedFrom: string, - +thread: ThreadInfo, -}; - type TouchableOpacityInstance = React.AbstractComponent< React.ElementConfig, NativeMethods, >; type BaseProps = { - +navigation: AppNavigationProp<'CameraModal'>, - +route: NavigationRoute<'CameraModal'>, + handlePhotoCapture: (capture: PhotoCapture) => void, }; type Props = { ...BaseProps, @@ -244,10 +239,9 @@ +foreground: boolean, // Redux dispatch functions +dispatch: Dispatch, - // withInputState - +inputState: ?InputState, // withOverlayContext +overlayContext: ?OverlayContextType, + +navigation: NavigationProp, }; type State = { +zoom: number, @@ -857,7 +851,7 @@ }; close = () => { - this.props.navigation.goBackOnce(); + this.props.navigation.goBack(); }; takePhoto = async () => { @@ -927,9 +921,7 @@ this.close(); - const { inputState } = this.props; - invariant(inputState, 'inputState should be set'); - inputState.sendMultimediaMessage([capture], this.props.route.params.thread); + this.props.handlePhotoCapture(capture); }; clearPendingImage = () => { @@ -1186,8 +1178,8 @@ const deviceOrientation = useSelector(state => state.deviceOrientation); const foreground = useIsAppForegrounded(); const overlayContext = React.useContext(OverlayContext); - const inputState = React.useContext(InputStateContext); const dispatch = useDispatch(); + const navigation = useNavigation(); return ( ); }); diff --git a/native/media/chat-camera-modal.react.js b/native/media/chat-camera-modal.react.js new file mode 100644 --- /dev/null +++ b/native/media/chat-camera-modal.react.js @@ -0,0 +1,40 @@ +// @flow + +import invariant from 'invariant'; +import * as React from 'react'; + +import type { PhotoCapture } from 'lib/types/media-types.js'; +import type { ThreadInfo } from 'lib/types/thread-types.js'; + +import CameraModal from './camera-modal.react.js'; +import { InputStateContext } from '../input/input-state.js'; +import type { AppNavigationProp } from '../navigation/app-navigator.react.js'; +import type { NavigationRoute } from '../navigation/route-names.js'; + +export type ChatCameraModalParams = { + +presentedFrom: string, + +thread: ThreadInfo, +}; + +type Props = { + +navigation: AppNavigationProp<'ChatCameraModal'>, + +route: NavigationRoute<'ChatCameraModal'>, +}; + +function ChatCameraModal(props: Props): React.Node { + const { thread } = props.route.params; + + const inputState = React.useContext(InputStateContext); + + const sendPhoto = React.useCallback( + (capture: PhotoCapture) => { + invariant(inputState, 'inputState should be set'); + inputState.sendMultimediaMessage([capture], thread); + }, + [inputState, thread], + ); + + return ; +} + +export default ChatCameraModal; diff --git a/native/navigation/app-navigator.react.js b/native/navigation/app-navigator.react.js --- a/native/navigation/app-navigator.react.js +++ b/native/navigation/app-navigator.react.js @@ -21,7 +21,7 @@ ThreadSettingsMemberTooltipModalRouteName, RelationshipListItemTooltipModalRouteName, RobotextMessageTooltipModalRouteName, - CameraModalRouteName, + ChatCameraModalRouteName, VideoPlaybackModalRouteName, CommunityDrawerNavigatorRouteName, type ScreenParamList, @@ -32,7 +32,7 @@ import ThreadSettingsMemberTooltipModal from '../chat/settings/thread-settings-member-tooltip-modal.react.js'; import TextMessageTooltipModal from '../chat/text-message-tooltip-modal.react.js'; import KeyboardStateContainer from '../keyboard/keyboard-state-container.react.js'; -import CameraModal from '../media/camera-modal.react.js'; +import ChatCameraModal from '../media/chat-camera-modal.react.js'; import ImageModal from '../media/image-modal.react.js'; import VideoPlaybackModal from '../media/video-playback-modal.react.js'; import RelationshipListItemTooltipModal from '../profile/relationship-list-item-tooltip-modal.react.js'; @@ -131,7 +131,10 @@ name={RobotextMessageTooltipModalRouteName} component={RobotextMessageTooltipModal} /> - +