3b8b562268
* fix comments * add zeego package * get basic native dropdown working * add separator and icon components * refined native dropdown component * add android build properties to app.json * move `PostDropdownBtn` to its own component * fix selectors issue * move `PostDropdownBtn` to its own component * fix hitslop * fix post dropdown hitslop * fix android dropdown icons * move `UserAvatar.tsx` to native dropdown * use native dropdown in `ProfileHeader.tsx` * use native dropdown in `PostThreadItem.tsx` * use native dropdown in `UserBanner.tsx` * use native dropdown in `CustomFeed.tsx` * replace `testId` with `testID` (which is what is used everywhere) * move `Settings.tsx` to use native dropdown * create jest mocks for zeego * create jest mock for `zeego/dropdown-menu` * web styles for native dropdown * remove example native dropdown * adjust web styles * fix propagation * fix pressable in `Settings.tsx` * animate dropdown on web * add keyboard nav and hover styles * add hitslop to constants * add comments to NativeDropdown component * temporarily removed android icons * add testID to PostDropdownBtn * add testID back to all NativeDropdown button implementations * add postDropdownBtn testID * add testID to dropdown items * remove testID from dropdown menu item * refactor home-screen tests for native dropdown * refactor profile-screen tests for native dropdown * refactor thread-muting tests for native dropdown * refactor thread-screen tests for native dropdown * fix dropdown color for post dropdown button * remove icons from android dropdown menu * fix `create-account.test.ts` * fix `invite-codes.test.ts`
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import React, {useCallback} from 'react'
|
|
import {TouchableOpacity, StyleSheet} from 'react-native'
|
|
import {
|
|
FontAwesomeIcon,
|
|
FontAwesomeIconStyle,
|
|
} from '@fortawesome/react-native-fontawesome'
|
|
import {usePalette} from 'lib/hooks/usePalette'
|
|
import {useAnalytics} from 'lib/analytics/analytics'
|
|
import {useStores} from 'state/index'
|
|
import {isDesktopWeb} from 'platform/detection'
|
|
import {openCamera} from 'lib/media/picker'
|
|
import {useCameraPermission} from 'lib/hooks/usePermissions'
|
|
import {HITSLOP_10, POST_IMG_MAX} from 'lib/constants'
|
|
import {GalleryModel} from 'state/models/media/gallery'
|
|
|
|
type Props = {
|
|
gallery: GalleryModel
|
|
}
|
|
|
|
export function OpenCameraBtn({gallery}: Props) {
|
|
const pal = usePalette('default')
|
|
const {track} = useAnalytics()
|
|
const store = useStores()
|
|
const {requestCameraAccessIfNeeded} = useCameraPermission()
|
|
|
|
const onPressTakePicture = useCallback(async () => {
|
|
track('Composer:CameraOpened')
|
|
try {
|
|
if (!(await requestCameraAccessIfNeeded())) {
|
|
return
|
|
}
|
|
|
|
const img = await openCamera(store, {
|
|
width: POST_IMG_MAX.width,
|
|
height: POST_IMG_MAX.height,
|
|
freeStyleCropEnabled: true,
|
|
})
|
|
|
|
gallery.add(img)
|
|
} catch (err: any) {
|
|
// ignore
|
|
store.log.warn('Error using camera', err)
|
|
}
|
|
}, [gallery, track, store, requestCameraAccessIfNeeded])
|
|
|
|
if (isDesktopWeb) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<TouchableOpacity
|
|
testID="openCameraButton"
|
|
onPress={onPressTakePicture}
|
|
style={styles.button}
|
|
hitSlop={HITSLOP_10}
|
|
accessibilityRole="button"
|
|
accessibilityLabel="Camera"
|
|
accessibilityHint="Opens camera on device">
|
|
<FontAwesomeIcon
|
|
icon="camera"
|
|
style={pal.link as FontAwesomeIconStyle}
|
|
size={24}
|
|
/>
|
|
</TouchableOpacity>
|
|
)
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
button: {
|
|
paddingHorizontal: 15,
|
|
},
|
|
})
|