diff options
author | Michael Staub <michael.staub@brightmachines.com> | 2023-02-23 16:34:25 -0800 |
---|---|---|
committer | Michael Staub <michael.staub@brightmachines.com> | 2023-02-23 16:34:25 -0800 |
commit | 693cbb9f18eeec48ea6ed3eb03ff3a96ca6ec7dc (patch) | |
tree | 192494fe0751aa279209f447587c311efcd33668 /src/view/com/modals/crop-image/CropImage.web.tsx | |
parent | 23f07d8def1f4384022c7fecd0d7eac0ba8b2efc (diff) | |
parent | bbd0b03a46b1087ecca17219441d060c2be69de2 (diff) | |
download | voidsky-693cbb9f18eeec48ea6ed3eb03ff3a96ca6ec7dc.tar.zst |
Merge branch 'rnw' of github.com:bluesky-social/social-app into rnw
Diffstat (limited to 'src/view/com/modals/crop-image/CropImage.web.tsx')
-rw-r--r-- | src/view/com/modals/crop-image/CropImage.web.tsx | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/view/com/modals/crop-image/CropImage.web.tsx b/src/view/com/modals/crop-image/CropImage.web.tsx index e43f37397..c774b94e1 100644 --- a/src/view/com/modals/crop-image/CropImage.web.tsx +++ b/src/view/com/modals/crop-image/CropImage.web.tsx @@ -38,6 +38,7 @@ export function Component({ const pal = usePalette('default') const [as, setAs] = React.useState<AspectRatio>(AspectRatio.Square) const [scale, setScale] = React.useState<number>(1) + const editorRef = React.useRef<ImageEditor>(null) const doSetAs = (v: AspectRatio) => () => setAs(v) @@ -46,8 +47,20 @@ export function Component({ store.shell.closeModal() } const onPressDone = () => { - console.log('TODO') - onSelect(undefined) // TODO + const canvas = editorRef.current?.getImageScaledToCanvas() + if (canvas) { + const dataUri = canvas.toDataURL('image/jpeg') + onSelect({ + mediaType: 'photo', + path: dataUri, + mime: 'image/jpeg', + size: Math.round((dataUri.length * 3) / 4), // very rough estimate + width: DIMS[as].width, + height: DIMS[as].height, + }) + } else { + onSelect(undefined) + } store.shell.closeModal() } @@ -61,13 +74,15 @@ export function Component({ } return ( <View> - <View style={[styles.cropper, cropperStyle]}> + <View style={[styles.cropper, pal.borderDark, cropperStyle]}> <ImageEditor + ref={editorRef} style={styles.imageEditor} image={uri} width={DIMS[as].width} height={DIMS[as].height} scale={scale} + border={0} /> </View> <View style={styles.ctrls}> @@ -126,6 +141,9 @@ const styles = StyleSheet.create({ cropper: { marginLeft: 'auto', marginRight: 'auto', + borderWidth: 1, + borderRadius: 4, + overflow: 'hidden', }, cropperSquare: { width: 400, |