Changeset View
Changeset View
Standalone View
Standalone View
native/media/camera-modal.react.js
Show All 28 Lines | |||||
import { useDispatch } from 'react-redux'; | import { useDispatch } from 'react-redux'; | ||||
import { pathFromURI, filenameFromPathOrURI } from 'lib/media/file-utils.js'; | import { pathFromURI, filenameFromPathOrURI } from 'lib/media/file-utils.js'; | ||||
import { useIsAppForegrounded } from 'lib/shared/lifecycle-utils.js'; | import { useIsAppForegrounded } from 'lib/shared/lifecycle-utils.js'; | ||||
import type { PhotoCapture } from 'lib/types/media-types.js'; | import type { PhotoCapture } from 'lib/types/media-types.js'; | ||||
import type { Dispatch } from 'lib/types/redux-types.js'; | import type { Dispatch } from 'lib/types/redux-types.js'; | ||||
import SendMediaButton from './send-media-button.react.js'; | import SendMediaButton from './send-media-button.react.js'; | ||||
import type { RegistrationNavigationProp } from '../account/registration/registration-navigator.react.js'; | |||||
import ContentLoading from '../components/content-loading.react.js'; | import ContentLoading from '../components/content-loading.react.js'; | ||||
import ConnectedStatusBar from '../connected-status-bar.react.js'; | import ConnectedStatusBar from '../connected-status-bar.react.js'; | ||||
import type { AppNavigationProp } from '../navigation/app-navigator.react.js'; | import type { AppNavigationProp } from '../navigation/app-navigator.react.js'; | ||||
import { | import { | ||||
OverlayContext, | OverlayContext, | ||||
type OverlayContextType, | type OverlayContextType, | ||||
} from '../navigation/overlay-context.js'; | } from '../navigation/overlay-context.js'; | ||||
import type { OverlayParamList } from '../navigation/route-names.js'; | |||||
import { updateDeviceCameraInfoActionType } from '../redux/action-types.js'; | import { updateDeviceCameraInfoActionType } from '../redux/action-types.js'; | ||||
import { type DimensionsInfo } from '../redux/dimensions-updater.react.js'; | import { type DimensionsInfo } from '../redux/dimensions-updater.react.js'; | ||||
import { useSelector } from '../redux/redux-utils.js'; | import { useSelector } from '../redux/redux-utils.js'; | ||||
import { colors } from '../themes/colors.js'; | import { colors } from '../themes/colors.js'; | ||||
import { type DeviceCameraInfo } from '../types/camera.js'; | import { type DeviceCameraInfo } from '../types/camera.js'; | ||||
import type { NativeMethods } from '../types/react-native.js'; | import type { NativeMethods } from '../types/react-native.js'; | ||||
import { | import { | ||||
AnimatedView, | AnimatedView, | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | |||||
type TouchableOpacityInstance = React.AbstractComponent< | type TouchableOpacityInstance = React.AbstractComponent< | ||||
React.ElementConfig<typeof TouchableOpacity>, | React.ElementConfig<typeof TouchableOpacity>, | ||||
NativeMethods, | NativeMethods, | ||||
>; | >; | ||||
type BaseProps = { | type BaseProps = { | ||||
+handlePhotoCapture: (capture: PhotoCapture) => mixed, | +handlePhotoCapture: (capture: PhotoCapture) => mixed, | ||||
+navigation: $Values< | +navigation: | ||||
$ObjMapi<OverlayParamList, <K>(K) => AppNavigationProp<K>>, | | AppNavigationProp<'ChatCameraModal'> | ||||
>, | | AppNavigationProp<'UserAvatarCameraModal'> | ||||
| AppNavigationProp<'ThreadAvatarCameraModal'> | |||||
| RegistrationNavigationProp<'RegistrationUserAvatarCameraModal'>, | |||||
}; | }; | ||||
type Props = { | type Props = { | ||||
...BaseProps, | ...BaseProps, | ||||
// Redux state | // Redux state | ||||
+dimensions: DimensionsInfo, | +dimensions: DimensionsInfo, | ||||
+deviceCameraInfo: DeviceCameraInfo, | +deviceCameraInfo: DeviceCameraInfo, | ||||
+deviceOrientation: Orientations, | +deviceOrientation: Orientations, | ||||
+foreground: boolean, | +foreground: boolean, | ||||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | return and( | ||||
lessThan(y, flashButtonY), | lessThan(y, flashButtonY), | ||||
greaterThan(y, add(flashButtonY, flashButtonHeight)), | greaterThan(y, add(flashButtonY, flashButtonHeight)), | ||||
), | ), | ||||
); | ); | ||||
} | } | ||||
static isActive(props) { | static isActive(props) { | ||||
const { overlayContext } = props; | const { overlayContext } = props; | ||||
invariant(overlayContext, 'CameraModal should have OverlayContext'); | if (!overlayContext) { | ||||
return true; | |||||
} | |||||
return !overlayContext.isDismissing; | return !overlayContext.isDismissing; | ||||
} | } | ||||
componentDidMount() { | componentDidMount() { | ||||
if (CameraModal.isActive(this.props)) { | if (CameraModal.isActive(this.props)) { | ||||
Orientation.unlockAllOrientations(); | Orientation.unlockAllOrientations(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static async cleanUpPendingPhotoCapture(pendingPhotoCapture: PhotoCapture) { | ||||
} | } | ||||
try { | try { | ||||
await filesystem.unlink(path); | await filesystem.unlink(path); | ||||
} catch (e) {} | } catch (e) {} | ||||
} | } | ||||
get containerStyle() { | get containerStyle() { | ||||
const { overlayContext } = this.props; | const { overlayContext } = this.props; | ||||
invariant(overlayContext, 'CameraModal should have OverlayContext'); | if (!overlayContext) { | ||||
return styles.container; | |||||
} | |||||
return { | return { | ||||
...styles.container, | ...styles.container, | ||||
opacity: overlayContext.position, | opacity: overlayContext.position, | ||||
}; | }; | ||||
} | } | ||||
get focusIndicatorStyle() { | get focusIndicatorStyle() { | ||||
return { | return { | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | flashButton.measure((x, y, width, height, pageX, pageY) => { | ||||
this.flashButtonX.setValue(pageX); | this.flashButtonX.setValue(pageX); | ||||
this.flashButtonY.setValue(pageY); | this.flashButtonY.setValue(pageY); | ||||
this.flashButtonWidth.setValue(width); | this.flashButtonWidth.setValue(width); | ||||
this.flashButtonHeight.setValue(height); | this.flashButtonHeight.setValue(height); | ||||
}); | }); | ||||
}; | }; | ||||
close = () => { | close = () => { | ||||
this.props.navigation.goBackOnce(); | const { overlayContext, navigation } = this.props; | ||||
if (overlayContext && navigation.goBackOnce) { | |||||
navigation.goBackOnce(); | |||||
} else { | |||||
navigation.goBack(); | |||||
} | |||||
}; | }; | ||||
takePhoto = async () => { | takePhoto = async () => { | ||||
const { camera } = this; | const { camera } = this; | ||||
invariant(camera, 'camera ref should be set'); | invariant(camera, 'camera ref should be set'); | ||||
this.setState({ stagingMode: true }); | this.setState({ stagingMode: true }); | ||||
// We avoid flipping this.state.useFrontCamera if we discover we don't | // We avoid flipping this.state.useFrontCamera if we discover we don't | ||||
▲ Show 20 Lines • Show All 334 Lines • Show Last 20 Lines |