diff --git a/apps/mobile/app/common/filesystem/compress.js b/apps/mobile/app/common/filesystem/compress.js index 7c6dc9477..5e3a0ba2a 100644 --- a/apps/mobile/app/common/filesystem/compress.js +++ b/apps/mobile/app/common/filesystem/compress.js @@ -48,3 +48,22 @@ export async function compressToBase64(path, type) { RNFetchBlob.fs.unlink(response.uri.replace("file://", "")).catch(console.log); return base64; } + +export async function compressToFile(path, type) { + const response = await ImageResizer.createResizedImage( + path, + 1080, + 9999, + type, + 85, + 0, + undefined, + true, + { + mode: "contain", + onlyScaleDown: true + } + ); + RNFetchBlob.fs.unlink(path.replace("file://", "")).catch(console.log); + return response.uri; +} diff --git a/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx b/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx new file mode 100644 index 000000000..281e6c352 --- /dev/null +++ b/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx @@ -0,0 +1,173 @@ +/* +This file is part of the Notesnook project (https://notesnook.com/) + +Copyright (C) 2023 Streetwriters (Private) Limited + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +import React, { useState } from "react"; +import { Image, TouchableOpacity, View } from "react-native"; +import { ImagePickerResponse } from "react-native-image-picker"; +import { useThemeColors } from "../../../../../../packages/theme/dist"; +import { presentSheet } from "../../../services/event-manager"; +import { SIZE } from "../../../utils/size"; +import { Button } from "../../ui/button"; +import { IconButton } from "../../ui/icon-button"; +import { Notice } from "../../ui/notice"; +import Paragraph from "../../ui/typography/paragraph"; + +export default function AttachImage({ + response, + onAttach, + close +}: { + response: ImagePickerResponse; + onAttach: ({ compress }: { compress: boolean }) => void; + close: ((ctx?: string | undefined) => void) | undefined; +}) { + const { colors } = useThemeColors(); + const [compress, setCompress] = useState(true); + const image = response.assets?.[0]; + const width = image?.width || 0; + const height = image?.height || 0; + const ratio = width / height; + + return ( + + {image ? ( + + + + ) : null} + + { + setCompress(!compress); + }} + > + { + setCompress(!compress); + }} + /> + + + Compress image (recommended) + + + + {!compress ? ( + + ) : ( + + )} + +